class TrainPlugins::TrainKubernetes::Connection

Attributes

client[RW]

Public Class Methods

new(options) click to toggle source
Calls superclass method
# File lib/train-kubernetes/connection.rb, line 10
def initialize(options)
  super(options)

  parse_kubeconfig
  connect
end

Public Instance Methods

connect() click to toggle source
# File lib/train-kubernetes/connection.rb, line 19
def connect
  @client.apis(prefetch_resources: true)
rescue Excon::Error::Socket => e
  logger.error e.message
  exit
end
parse_kubeconfig() click to toggle source
# File lib/train-kubernetes/connection.rb, line 34
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_identifier() click to toggle source
# File lib/train-kubernetes/connection.rb, line 30
def unique_identifier
  @client.transport.server.gsub(%r{(http|https)\:\/\/}, '') || 'default'
end
uri() click to toggle source
# File lib/train-kubernetes/connection.rb, line 26
def uri
  "kubernetes://#{unique_identifier}"
end