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, force: false) ⇒ Namespace

Returns a new instance of Namespace.



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

def initialize(namespace, filter: DEFAULT_FILTER, force: false)
  unless force
    raise "Middleware::Namespace is deprecated... use Middleware::SetNamespace"
  end

  super(filter: filter)
  @namespace = namespace
end

Instance Method Details

#call(manifest) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kube/cluster/middleware/namespace.rb', line 26

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