Class: Pangea::Magma::Stack
Overview
Stack — the high-level “give me a typed orchestrator for these workspaces with these edges” helper. Bundles Distribution + Chain + Orchestrator declaration into one call so per-workspace ‘.magma.rb` files don’t repeat the same wiring template across the fleet.
Authors:
STACK = Pangea::Magma::Stack.build(
name: :k3s_stack,
tiers: {
permissions: [K3S_PERMISSIONS_WORKSPACE],
cluster: [K3S_CLUSTER_WORKSPACE],
},
edges: [
{ from: :k3s_permissions, output: :instance_profile_name,
to: :k3s_cluster, input: :instance_profile_name },
{ from: :k3s_permissions, output: :node_role_name,
to: :k3s_cluster, input: :node_role_name },
],
optimization: Pangea::Magma::Optimization.parallel_by_tier,
attestation: { enabled: true, chain: 'tameshi' },
)
STACK.chain # → Pangea::Magma::Chain
STACK.orchestrator # → Pangea::Magma::Orchestrator
STACK.deploy! # convenience for STACK.orchestrator.deploy!
Per theory/PANGEA-MAGMA-ORCHESTRATION.md §III.6.
Instance Attribute Summary collapse
-
#attestation ⇒ Object
readonly
Returns the value of attribute attestation.
-
#chain ⇒ Object
readonly
Returns the value of attribute chain.
-
#distribution ⇒ Object
readonly
Returns the value of attribute distribution.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#optimization ⇒ Object
readonly
Returns the value of attribute optimization.
-
#orchestrator ⇒ Object
readonly
Returns the value of attribute orchestrator.
Class Method Summary collapse
Instance Method Summary collapse
- #deploy!(only: nil) ⇒ Object
-
#initialize(name:, chain:, orchestrator:, distribution:, optimization:, attestation:) ⇒ Stack
constructor
A new instance of Stack.
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(name:, chain:, orchestrator:, distribution:, optimization:, attestation:) ⇒ Stack
Returns a new instance of Stack.
130 131 132 133 134 135 136 137 138 |
# File 'lib/pangea/magma/stack.rb', line 130 def initialize(name:, chain:, orchestrator:, distribution:, optimization:, attestation:) @name = name @chain = chain @orchestrator = orchestrator @distribution = distribution @optimization = optimization @attestation = attestation end |
Instance Attribute Details
#attestation ⇒ Object (readonly)
Returns the value of attribute attestation.
41 42 43 |
# File 'lib/pangea/magma/stack.rb', line 41 def attestation @attestation end |
#chain ⇒ Object (readonly)
Returns the value of attribute chain.
41 42 43 |
# File 'lib/pangea/magma/stack.rb', line 41 def chain @chain end |
#distribution ⇒ Object (readonly)
Returns the value of attribute distribution.
41 42 43 |
# File 'lib/pangea/magma/stack.rb', line 41 def distribution @distribution end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
41 42 43 |
# File 'lib/pangea/magma/stack.rb', line 41 def name @name end |
#optimization ⇒ Object (readonly)
Returns the value of attribute optimization.
41 42 43 |
# File 'lib/pangea/magma/stack.rb', line 41 def optimization @optimization end |
#orchestrator ⇒ Object (readonly)
Returns the value of attribute orchestrator.
41 42 43 |
# File 'lib/pangea/magma/stack.rb', line 41 def orchestrator @orchestrator end |
Class Method Details
.build(name:, tiers:, edges: [], optimization: nil, attestation: {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/pangea/magma/stack.rb', line 44 def build(name:, tiers:, edges: [], optimization: nil, attestation: {}) opt = case optimization when Pangea::Magma::Optimization then optimization when Hash then Pangea::Magma::Optimization.declare(**optimization) when nil then nil else raise ArgumentError, "optimization must be Optimization|Hash|nil, got #{optimization.class}" end flat_workspaces = tiers.values.flatten by_name = flat_workspaces.to_h { |w| [w.name, w] } # Auto-derive tier edges only when no explicit edges given. tier_edges = edges.empty? ? auto_tier_edges(tiers) : edges chain = Pangea::Magma::Chain.build(optimization: opt) do |c| flat_workspaces.each { |w| c.workspace w } tier_edges.each do |e| from = by_name.fetch(e.fetch(:from).to_sym) { raise ArgumentError, "edge.from references unknown workspace: #{e[:from]}" } to = by_name.fetch(e.fetch(:to).to_sym) { raise ArgumentError, "edge.to references unknown workspace: #{e[:to]}" } c.edge from: from, output: e.fetch(:output), to: to, input: e.fetch(:input) end end distribution = Pangea::Magma::Distribution.declare( strategy: :tier_separation, tiers: tiers, edges: tiers_to_distribution_edges(tiers), placement: tiers.transform_values { {} }, ) orchestrator = Pangea::Magma::Orchestrator.new( distribution: distribution, optimization: opt, attestation: attestation, ) new(name: name.to_sym, chain: chain, orchestrator: orchestrator, distribution: distribution, optimization: opt, attestation: attestation) end |
Instance Method Details
#deploy!(only: nil) ⇒ Object
140 141 142 |
# File 'lib/pangea/magma/stack.rb', line 140 def deploy!(only: nil) @orchestrator.deploy!(only: only) end |
#to_h ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/pangea/magma/stack.rb', line 144 def to_h { name: @name.to_s, chain: @chain.to_h, distribution: @distribution.to_h, optimization: @optimization&.to_h, attestation: @attestation, } end |
#to_json(*args) ⇒ Object
154 155 156 |
# File 'lib/pangea/magma/stack.rb', line 154 def to_json(*args) to_h.to_json(*args) end |