Class: Pangea::Magma::Distribution

Inherits:
Object
  • Object
show all
Defined in:
lib/pangea/magma/distribution.rb

Overview

Strategy for distributing architecture pieces across workspaces. Per theory/PANGEA-MAGMA-ORCHESTRATION.md §III.4. The distribution doesn’t change WHAT is deployed — only WHERE it lives in state organization.

Authors:

dist = Pangea::Magma::Distribution.declare(
  strategy: :tier_separation,
  tiers: {
    network:  [vpc_ws, dns_ws, lb_ws],
    cluster:  [iam_ws, k3s_ws, kms_ws],
    workload: [fluxcd_ws, observability_ws],
  },
  edges: { network: :cluster, cluster: :workload },
  placement: {
    network:  { region: 'us-east-1' },
    cluster:  { region: 'us-east-1' },
    workload: { region: 'us-east-1' },
  },
)

chain = dist.to_chain

Operators migrate between Distribution strategies via Pangea::Magma::Migration (M0.2).

Constant Summary collapse

STRATEGIES =
%i[tier_separation single_workspace per_provider custom].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strategy:, tiers:, edges:, placement:) ⇒ Distribution

Returns a new instance of Distribution.



49
50
51
52
53
54
# File 'lib/pangea/magma/distribution.rb', line 49

def initialize(strategy:, tiers:, edges:, placement:)
  @strategy  = strategy
  @tiers     = tiers
  @edges     = edges
  @placement = placement
end

Instance Attribute Details

#edgesObject (readonly)

Returns the value of attribute edges.



47
48
49
# File 'lib/pangea/magma/distribution.rb', line 47

def edges
  @edges
end

#placementObject (readonly)

Returns the value of attribute placement.



47
48
49
# File 'lib/pangea/magma/distribution.rb', line 47

def placement
  @placement
end

#strategyObject (readonly)

Returns the value of attribute strategy.



47
48
49
# File 'lib/pangea/magma/distribution.rb', line 47

def strategy
  @strategy
end

#tiersObject (readonly)

Returns the value of attribute tiers.



47
48
49
# File 'lib/pangea/magma/distribution.rb', line 47

def tiers
  @tiers
end

Class Method Details

.declare(strategy:, tiers: {}, edges: {}, placement: {}) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/pangea/magma/distribution.rb', line 38

def declare(strategy:, tiers: {}, edges: {}, placement: {})
  unless STRATEGIES.include?(strategy)
    raise ArgumentError,
          "unknown strategy #{strategy.inspect}; expected one of #{STRATEGIES.inspect}"
  end
  new(strategy: strategy, tiers: tiers, edges: edges, placement: placement)
end

Instance Method Details

#to_chainObject

Convert the distribution to a Pangea::Magma::Chain. For :tier_separation: build a chain with tier-level edges; each workspace in a tier links to every workspace in the depending tier via the canonical outputs.

For M0.1 this is a structural conversion — full typed-output wiring per tier requires the workspaces to declare their I/O slots, which is the M0.1 Workspace.declare path.



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/pangea/magma/distribution.rb', line 64

def to_chain
  case @strategy
  when :tier_separation
    tier_separation_chain
  when :single_workspace
    single_workspace_chain
  when :per_provider, :custom
    raise NotImplementedError,
          "Distribution.to_chain(strategy=#{@strategy}) — M0.3"
  end
end

#to_hObject



76
77
78
79
80
81
82
83
# File 'lib/pangea/magma/distribution.rb', line 76

def to_h
  {
    strategy:  @strategy.to_s,
    tiers:     @tiers.transform_values { |ws_list| ws_list.map { |w| w.name.to_s } },
    edges:     @edges.transform_keys(&:to_s).transform_values(&:to_s),
    placement: @placement.transform_keys(&:to_s),
  }
end

#to_json(*args) ⇒ Object



85
86
87
# File 'lib/pangea/magma/distribution.rb', line 85

def to_json(*args)
  to_h.to_json(*args)
end