Class: Kube::Cluster::Manifest::Middleware::Annotations

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

Overview

Merges annotations into metadata.annotations on every resource. Existing annotations are preserved; the supplied annotations act as defaults that can be overridden per-resource.

stack do
  use Middleware::Annotations,
    "prometheus.io/scrape": "true",
    "prometheus.io/port":   "9090"
end

Constant Summary

Constants inherited from Kube::Cluster::Manifest::Middleware

CLUSTER_SCOPED_KINDS, POD_BEARING_KINDS

Instance Method Summary collapse

Constructor Details

#initialize(**annotations) ⇒ Annotations

Returns a new instance of Annotations.



18
19
20
# File 'lib/kube/cluster/manifest/middleware/annotations.rb', line 18

def initialize(**annotations)
  @annotations = annotations.transform_keys(&:to_sym).transform_values(&:to_s)
end

Instance Method Details

#call(resource) ⇒ Object



22
23
24
25
26
27
# File 'lib/kube/cluster/manifest/middleware/annotations.rb', line 22

def call(resource)
  h = resource.to_h
  h[:metadata] ||= {}
  h[:metadata][:annotations] = @annotations.merge(h[:metadata][:annotations] || {})
  rebuild(resource, h)
end