Class: Kustomize::Transform::PurgeInternalAnnotationsTransform

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

Constant Summary collapse

ANNOTS_LENS =
Lens['metadata', 'annotations']
INTERNAL_ANNOT_PATTERN =
/^kustomizer\.covalenthq\.com\//

Instance Method Summary collapse

Methods inherited from Kustomize::Transform

create, #inspect, #rewrite_all

Instance Method Details

#rewrite(rc) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kustomize/transform/purge_internal_annotations_transform.rb', line 15

def rewrite(rc)
  ANNOTS_LENS.update_in(rc) do |orig_annots|
    next(:keep) unless orig_annots and orig_annots.length.nonzero?

    new_annots =
      orig_annots.reject{ |k, v| INTERNAL_ANNOT_PATTERN.match?(k) }

    if new_annots.length == orig_annots.length
      :keep
    elsif new_annots.empty?
      :pop
    else
      [:set, new_annots]
    end
  end
end