Class: Rubernetes::Operator

Inherits:
Object
  • Object
show all
Defined in:
lib/rubernetes/operator.rb

Overview

Operator Class to run the core operator functions for your crd

Instance Method Summary collapse

Constructor Details

#initialize(crd_group, crd_version, crd_plural, options = {}) ⇒ Operator

Returns a new instance of Operator.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rubernetes/operator.rb', line 19

def initialize(crd_group, crd_version, crd_plural, options = {})
  # parameters
  @crd_group = crd_group
  @crd_version = crd_version
  @crd_plural = crd_plural

  # defaults
  @options = options
  @options[:sleepTimer] ||= 1
  @options[:namespace] ||= nil

  # persistence/cache layer
  @options[:persistence_location] ||= '/tmp/cache'
  Dir.mkdir(@options[:persistence_location]) unless File.exist?(@options[:persistence_location])
  @store = YAML::Store.new("#{@options[:persistence_location]}/#{@crd_group}_#{@crd_version}_#{@crd_plural}.yaml")

  # utilities
  @k8sclient = KubeClient.new(crd_group, crd_version)
  @logger = Logger.new(crd_group, crd_version, crd_plural, namespace: @options[:namespace])

  @logger.info('init the operator')
end

Instance Method Details

#runObject



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

def run
  @logger.info('start the operator')

  loop do
    begin
      watcher.each do |event|
        handle_event(event)
      end
      watcher.finish
    rescue StandardError => e
      @logger.error(e.inspect)
    end

    # do not overwhelm Kube API, relax between calls
    sleep(@options[:sleepTimer])
  end
end