Sha256: 090df44de77edd22d2c95b5db3967e05a158aa0188d826f917bd7f5c673abd73

Contents?: true

Size: 470 Bytes

Versions: 1

Compression:

Stored size: 470 Bytes

Contents

require 'json'

class KubernetesAnnotationsTagAppender
  attr_reader :annotations

  def initialize(annotations)
    @annotations = annotations
  end

  def append(tag, data, container_name)
    matches = annotations.select do | annotation |
      json = data[annotation] || "[]"
      JSON.parse(json)&.include? container_name
    end

    # Don't re-add tags if they're already present:
    uniqs = (tag.split(".") + matches).uniq
    return uniqs.join(".")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-append-kubernetes-annotations-to-tag-0.1.0.pre.5 lib/kubernetes_annotations_tag_appender.rb