Class: DTK::CrdClient

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

Constant Summary collapse

DEFAULT_API_VERSION =

include Singleton

'v1alpha1'
KubeclientVersions =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(apiVersion) ⇒ CrdClient

opts can have keys

kubernetes_client - already instantiated kubernetes client


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/crd_client.rb', line 40

def initialize(apiVersion)
  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/#{apiVersion}",
    auth_options: auth_options,
    ssl_options:  ssl_options,
    socket_options: socket_options 
  )
  @kubeclient.discover unless @kubeclient.discovered
  @kubeclient
end

Instance Attribute Details

#kubeclientObject

COMPONENT_DEF_CRD_VERSION = ENV ASSEMBLY_CRD_VERSION = ENV WORKFLOW_CRD_VERSION = ENV WORKFLOW_INSTANCE_CRD_VERSION = ENV



15
16
17
# File 'lib/crd_client.rb', line 15

def kubeclient
  @kubeclient
end

Class Method Details

.get_kubeclient(opts) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/crd_client.rb', line 17

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

.kubeclient_version(opts = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/crd_client.rb', line 25

def self.kubeclient_version(opts = {})
  version = opts[:apiVersion] || DEFAULT_API_VERSION

  if existing_version = KubeclientVersions[version]
    return existing_version
  else
    new_instance = new(version).kubeclient
    KubeclientVersions[version] = new_instance
    new_instance
  end
end