class Fluent::Plugin::KubernetesAnnotationFilter

Attributes

containing_annotations[R]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter-kubernetes-annotation.rb, line 11
def initialize
  super
end

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter-kubernetes-annotation.rb, line 22
def configure(conf)
  super

  @containing_annotations = @contains_sections.map(&:annotation)
end
filter(_, _, record) click to toggle source
# File lib/fluent/plugin/filter-kubernetes-annotation.rb, line 28
def filter(_, _, record)
  begin
    if(record.has_key?("kubernetes") && record["kubernetes"].has_key?("annotations"))
      unless annotations_contain_container_name?(record)
        return nil
      end
    elsif(!@pass_through_events_without_kubernetes_tags)
      return nil
    end

  rescue => e
    log.warn "failed to filter by kubernetes annotation", error: e
    log.warn_backtrace
  end

  return record
end

Private Instance Methods

annotations_contain_container_name?(record) click to toggle source
# File lib/fluent/plugin/filter-kubernetes-annotation.rb, line 48
def annotations_contain_container_name?(record)
  return false if containing_annotations.size == 0

  container_name = record['kubernetes']['container_name']

  containing_annotations.all? { |annotation|
    content = record["kubernetes"]["annotations"][annotation]

    if(content)
      JSON.parse(content)&.include?(container_name)
    end
  }
end