Class: TrainPlugins::TrainKubernetes::Connection

Inherits:
Train::Plugins::Transport::BaseConnection
  • Object
show all
Includes:
Platform
Defined in:
lib/train-kubernetes-docs/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.



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

def initialize(options)
  super(options)
  @pod = options[:pod] || options[:path]&.gsub('/', '')
  @container = options[:container]
  @namespace = options[:namespace] || options[:host]
  parse_kubeconfig
  connect
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



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

def client
  @client
end

Instance Method Details

#connectObject



22
23
24
25
26
27
# File 'lib/train-kubernetes-docs/connection.rb', line 22

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

#parse_kubeconfigObject



37
38
39
40
# File 'lib/train-kubernetes-docs/connection.rb', line 37

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



33
34
35
# File 'lib/train-kubernetes-docs/connection.rb', line 33

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

#uriObject



29
30
31
# File 'lib/train-kubernetes-docs/connection.rb', line 29

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