class Kustomize::Transform::CommonLabelsTransform

Constants

LENSES_FOR_ALL
LENSES_FOR_KIND

Public Class Methods

new(new_labels) click to toggle source
# File lib/kustomize/transform/common_labels_transform.rb, line 8
def initialize(new_labels)
  @new_labels = new_labels
end

Public Instance Methods

rewrite(rc_doc) click to toggle source
# File lib/kustomize/transform/common_labels_transform.rb, line 26
def rewrite(rc_doc)
  rc_kind = rc_doc['kind']
  use_lenses = LENSES_FOR_ALL

  if lenses_for_doc_kind = LENSES_FOR_KIND[rc_kind]
    use_lenses += lenses_for_doc_kind
  end

  use_lenses.inject(rc_doc) do |doc, lens|
    lens.update_in(doc) do |annots|
      [:set, (annots || {}).merge(@new_labels)]
    end
  end
end