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

Inherits:
Kube::Cluster::Manifest::Middleware show all
Defined in:
lib/kube/cluster/manifest/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::Manifest::Middleware

CLUSTER_SCOPED_KINDS, POD_BEARING_KINDS

Instance Method Summary collapse

Constructor Details

#initialize(namespace) ⇒ Namespace

Returns a new instance of Namespace.



15
16
17
# File 'lib/kube/cluster/manifest/middleware/namespace.rb', line 15

def initialize(namespace)
  @namespace = namespace
end

Instance Method Details

#call(resource) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/kube/cluster/manifest/middleware/namespace.rb', line 19

def call(resource)
  return resource if cluster_scoped?(resource)

  h = resource.to_h
  h[:metadata] ||= {}
  h[:metadata][:namespace] = @namespace
  rebuild(resource, h)
end