Class: Kube::Cluster::Middleware::Namespace

Inherits:
Kube::Cluster::Middleware show all
Defined in:
lib/kube/cluster/middleware/namespace.rb

Overview

Sets metadata.namespace on all namespace-scoped resources. Cluster-scoped kinds (Namespace, ClusterRole, etc.) are skipped.

stack do
  use Middleware::Namespace, "production"
end

Constant Summary

Constants inherited from Kube::Cluster::Middleware

DEFAULT_FILTER

Instance Method Summary collapse

Methods inherited from Kube::Cluster::Middleware

build, #filter

Constructor Details

#initialize(namespace, filter: DEFAULT_FILTER) ⇒ Namespace

Returns a new instance of Namespace.



17
18
19
20
# File 'lib/kube/cluster/middleware/namespace.rb', line 17

def initialize(namespace, filter: DEFAULT_FILTER)
  super(filter: filter)
  @namespace = namespace
end

Instance Method Details

#call(manifest) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/kube/cluster/middleware/namespace.rb', line 22

def call(manifest)
  manifest.resources.map! do |resource|
    filter(resource) do
      next resource if resource.cluster_scoped?
      h = resource.to_h
      h[:metadata] ||= {}
      h[:metadata][:namespace] = @namespace
      resource.rebuild(h)
    end
  end
end