Class: GlooIngressAdapter::ResourceObserver

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo_ingress_adapter/resource_observer.rb

Overview

Watcher for ingress resources

Defined Under Namespace

Classes: ObserverThread

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind:, client:, logger:, field_selector: nil) ⇒ ResourceObserver

Returns a new instance of ResourceObserver.



28
29
30
31
32
33
34
35
# File 'lib/gloo_ingress_adapter/resource_observer.rb', line 28

def initialize(kind:, client:, logger:, field_selector: nil)
  @kind = kind
  @client = client
  @logger = logger
  @field_selector = field_selector
  @watcher = nil
  @lock = Mutex.new
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



26
27
28
# File 'lib/gloo_ingress_adapter/resource_observer.rb', line 26

def kind
  @kind
end

Instance Method Details

#start(queue:) ⇒ Object



37
38
39
# File 'lib/gloo_ingress_adapter/resource_observer.rb', line 37

def start(queue:)
  ObserverThread.new(observer: self, queue:)
end

#stopObject



59
60
61
# File 'lib/gloo_ingress_adapter/resource_observer.rb', line 59

def stop
  watcher&.finish
end

#watch(queue:) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gloo_ingress_adapter/resource_observer.rb', line 41

def watch(queue:)
  logger.info("Watching #{kind}#{field_selector && " with #{field_selector.to_json}"}")

  retriable do
    self.watcher = client.watch_entities(kind, field_selector:, as: :ros)

    watcher.each do |event|
      logger.info("Received event: #{event.object.kind} #{event.object..name} #{event.type.downcase}")
      queue << event
    end
  end
rescue StandardError => e
  logger.error("Error observing #{kind} resources: #{e.full_message}")
  raise(e)
ensure
  self.watcher = nil
end