Class: TrainPlugins::TrainKubernetes::Connection

Inherits:
Train::Plugins::Transport::BaseConnection
  • Object
show all
Includes:
Platform
Defined in:
lib/train-kubernetes/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Platform

#platform

Constructor Details

#initialize(options) ⇒ Connection

Returns a new instance of Connection.



10
11
12
13
14
15
16
# File 'lib/train-kubernetes/connection.rb', line 10

def initialize(options)
  super(options)
  @pod = options[:pod]
  @container = options[:container]
  parse_kubeconfig
  connect
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



18
19
20
# File 'lib/train-kubernetes/connection.rb', line 18

def client
  @client
end

Instance Method Details

#connectObject



20
21
22
23
24
25
# File 'lib/train-kubernetes/connection.rb', line 20

def connect
  @client.apis(prefetch_resources: true)
rescue Excon::Error::Socket => e
  logger.error e.message
  exit
end

#parse_kubeconfigObject



35
36
37
38
# File 'lib/train-kubernetes/connection.rb', line 35

def parse_kubeconfig
  kubeconfig_file = @options[:kubeconfig] if @options[:kubeconfig]
  @client = K8s::Client.config(K8s::Config.load_file(File.expand_path(kubeconfig_file)))
end

#unique_identifierObject



31
32
33
# File 'lib/train-kubernetes/connection.rb', line 31

def unique_identifier
  @client.transport.server.gsub(%r{(http|https)\:\/\/}, '') || 'default'
end

#uriObject



27
28
29
# File 'lib/train-kubernetes/connection.rb', line 27

def uri
  "kubernetes://#{unique_identifier}"
end