class DTK::CrdClient

Constants

DEFAULT_API_VERSION

include Singleton

KubeclientVersions

Attributes

kubeclient[RW]

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

Public Class Methods

get_kubeclient(opts) click to toggle source
# 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 = {}) click to toggle source
# 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
new(apiVersion) click to toggle source

opts can have keys

kubernetes_client - already instantiated kubernetes client
# 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