Class: Kustomize::Transform::CommonAnnotationsTransform

Inherits:
Kustomize::Transform show all
Includes:
Accessory
Defined in:
lib/kustomize/transform/common_annotations_transform.rb

Constant Summary collapse

BASE_LENS =
Lens["metadata", "annotations"]
LENS_PREFIXES =
[
  Lens["spec", "template"],
  Lens["spec", "jobTemplate", "spec", "template"]
]

Instance Method Summary collapse

Methods inherited from Kustomize::Transform

create, #inspect, #rewrite_all

Constructor Details

#initialize(new_annots) ⇒ CommonAnnotationsTransform

Returns a new instance of CommonAnnotationsTransform.



8
9
10
# File 'lib/kustomize/transform/common_annotations_transform.rb', line 8

def initialize(new_annots)
  @new_annots = new_annots
end

Instance Method Details

#rewrite(rc_doc) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kustomize/transform/common_annotations_transform.rb', line 19

def rewrite(rc_doc)
  rc_doc = BASE_LENS.update_in(rc_doc) do |annots|
    [:set, (annots || {}).merge(@new_annots)]
  end

  LENS_PREFIXES.inject(rc_doc) do |doc, prefix|
    prefix.update_in(rc_doc) do |node|
      next(:keep) unless node.kind_of?(Hash)

      new_node = BASE_LENS.update_in(node) do |annots|
        [:set, (annots || {}).merge(@new_annots)]
      end

      [:set, new_node]
    end
  end
end