Class: Kube::Cluster::Manifest
- Inherits:
-
Schema::Manifest
- Object
- Schema::Manifest
- Kube::Cluster::Manifest
- Defined in:
- lib/kube/cluster/manifest.rb,
lib/kube/cluster/manifest/stack.rb,
lib/kube/cluster/manifest/middleware.rb,
lib/kube/cluster/manifest/middleware/labels.rb,
lib/kube/cluster/manifest/middleware/namespace.rb,
lib/kube/cluster/manifest/middleware/annotations.rb,
lib/kube/cluster/manifest/middleware/resource_preset.rb,
lib/kube/cluster/manifest/middleware/security_context.rb,
lib/kube/cluster/manifest/middleware/pod_anti_affinity.rb,
lib/kube/cluster/manifest/middleware/hpa_for_deployment.rb,
lib/kube/cluster/manifest/middleware/ingress_for_service.rb,
lib/kube/cluster/manifest/middleware/service_for_deployment.rb
Overview
A Manifest subclass that runs resources through a middleware stack on enumeration. Manifests represent files — resources pass through middleware before rendering or saving.
class MyApp < Kube::Cluster::Manifest
stack do
use Middleware::Namespace, "production"
use Middleware::Labels, app: "web-app"
use Middleware::ResourcePreset
end
end
app = MyApp.new
app << Kube::Schema["Deployment"].new { ... }
app.to_yaml # resources have been transformed by the stack
Defined Under Namespace
Classes: Middleware, Stack
Class Method Summary collapse
-
.stack(&block) ⇒ Object
Declare a middleware stack at the class level.
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Enumerate resources after passing them through the middleware stack.
-
#to_a ⇒ Object
Override to_a so it returns middleware-processed resources.
-
#to_yaml ⇒ Object
Override to_yaml so it renders through the middleware stack.
Class Method Details
.stack(&block) ⇒ Object
Declare a middleware stack at the class level.
stack do
use Middleware::ResourcePreset
use Middleware::SecurityContext
end
41 42 43 |
# File 'lib/kube/cluster/manifest.rb', line 41 def self.stack(&block) @stack = Stack.new(&block) end |
Instance Method Details
#each(&block) ⇒ Object
Enumerate resources after passing them through the middleware stack. The entire manifest is passed to the stack so that generative middleware can introduce new resources that subsequent stages will see and process.
Every method that reads the manifest (to_yaml, to_a, map, select, etc.) goes through here.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/kube/cluster/manifest.rb', line 52 def each(&block) return enum_for(:each) unless block stack = self.class.instance_variable_get(:@stack) if stack stack.call(@resources).each(&block) else @resources.each(&block) end end |
#to_a ⇒ Object
Override to_a so it returns middleware-processed resources. The parent class returns @resources.dup directly.
71 72 73 |
# File 'lib/kube/cluster/manifest.rb', line 71 def to_a map(&:itself) end |
#to_yaml ⇒ Object
Override to_yaml so it renders through the middleware stack. The parent class accesses @resources directly, bypassing each.
65 66 67 |
# File 'lib/kube/cluster/manifest.rb', line 65 def to_yaml map { |r| r.to_yaml }.join("") end |