Class: DTK::CrdClient

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/crd_client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ CrdClient

opts can have keys

kubernetes_client - already instantiated kubernetes client


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/crd_client.rb', line 21

def initialize(opts = {})
  if @kubeclient = opts[:kubernetes_client]
    return @kubeclient
  end

  ssl_options  = {}
  auth_options = { bearer_token_file: '/var/run/secrets/kubernetes.io/serviceaccount/token' }
  
  if File.exist?("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt")
    ssl_options[:ca_file] = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
  end

  socket_options = {
    socket_class: Celluloid::IO::TCPSocket,
    ssl_socket_class: Celluloid::IO::SSLSocket
  }

  @kubeclient = Kubeclient::Client.new(
    'https://kubernetes.default.svc/apis/',
    'dtk.io/v1alpha1',
    auth_options: auth_options,
    ssl_options:  ssl_options,
    socket_options: socket_options 
  )
  @kubeclient.discover unless @kubeclient.discovered
  @kubeclient
end

Instance Attribute Details

#kubeclientObject

Returns the value of attribute kubeclient.



9
10
11
# File 'lib/crd_client.rb', line 9

def kubeclient
  @kubeclient
end

Class Method Details

.get_kubeclient(opts) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/crd_client.rb', line 11

def self.get_kubeclient(opts)
  if @kubeclient = opts[:kubeclient]
    @kubeclient
  else
    ::DTK::CrdClient.instance.kubeclient
  end
end