Sha256: 7c87862a8eed4b83dd32eb3d3bb01c425ad441471beecdd99dd47107a85c3bd0

Contents?: true

Size: 580 Bytes

Versions: 11

Compression:

Stored size: 580 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:
    orig_tags = tag.split(".")

    # Unique with order preservation:
    uniqs = orig_tags + ["annotated"] + matches.reject { |x| orig_tags.include? x }
    return uniqs.join(".")
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
fluent-plugin-append-kubernetes-annotations-to-tag-0.4.0.pre.1 lib/kubernetes_annotations_tag_appender.rb
fluent-plugin-append-kubernetes-annotations-to-tag-0.3.0 lib/kubernetes_annotations_tag_appender.rb
fluent-plugin-append-kubernetes-annotations-to-tag-0.3.0.pre.1 lib/kubernetes_annotations_tag_appender.rb
fluent-plugin-append-kubernetes-annotations-to-tag-0.2.0 lib/kubernetes_annotations_tag_appender.rb
fluent-plugin-append-kubernetes-annotations-to-tag-0.1.0.pre.12 lib/kubernetes_annotations_tag_appender.rb
fluent-plugin-append-kubernetes-annotations-to-tag-0.1.0.pre.11 lib/kubernetes_annotations_tag_appender.rb
fluent-plugin-append-kubernetes-annotations-to-tag-0.1.0.pre.10 lib/kubernetes_annotations_tag_appender.rb
fluent-plugin-append-kubernetes-annotations-to-tag-0.1.0.pre.9 lib/kubernetes_annotations_tag_appender.rb
fluent-plugin-append-kubernetes-annotations-to-tag-0.1.0.pre.8 lib/kubernetes_annotations_tag_appender.rb
fluent-plugin-append-kubernetes-annotations-to-tag-0.1.0.pre.7 lib/kubernetes_annotations_tag_appender.rb
fluent-plugin-append-kubernetes-annotations-to-tag-0.1.0.pre.6 lib/kubernetes_annotations_tag_appender.rb