Class: Kube::Cluster::Middleware::Annotations
- Inherits:
-
Kube::Cluster::Middleware
- Object
- Kube::Cluster::Middleware
- Kube::Cluster::Middleware::Annotations
- Defined in:
- lib/kube/cluster/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
Instance Method Summary collapse
- #call(manifest) ⇒ Object
-
#initialize(**annotations) ⇒ Annotations
constructor
A new instance of Annotations.
Constructor Details
#initialize(**annotations) ⇒ Annotations
Returns a new instance of Annotations.
17 18 19 |
# File 'lib/kube/cluster/middleware/annotations.rb', line 17 def initialize(**annotations) @annotations = annotations.transform_keys(&:to_sym).transform_values(&:to_s) end |
Instance Method Details
#call(manifest) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/kube/cluster/middleware/annotations.rb', line 21 def call(manifest) manifest.resources.map! do |resource| h = resource.to_h h[:metadata] ||= {} h[:metadata][:annotations] = @annotations.merge(h[:metadata][:annotations] || {}) resource.rebuild(h) end end |