Class: Kubeclient::Config
- Inherits:
-
Object
- Object
- Kubeclient::Config
- Defined in:
- lib/kubeclient/config.rb
Overview
Kubernetes client configuration class
Defined Under Namespace
Classes: Context
Class Method Summary collapse
-
.read(filename) ⇒ Object
Builds Config instance by parsing given file, with lookups relative to file’s directory.
Instance Method Summary collapse
- #context(context_name = nil) ⇒ Object
- #contexts ⇒ Object
-
#initialize(data, kcfg_path) ⇒ Config
constructor
data (Hash) - Parsed kubeconfig data.
Constructor Details
#initialize(data, kcfg_path) ⇒ Config
data (Hash) - Parsed kubeconfig data. kcfg_path (string) - Base directory for resolving relative references to external files.
If set to nil, all external lookups & commands are disabled (even for absolute paths).
See also the more convenient Config.read
25 26 27 28 29 |
# File 'lib/kubeclient/config.rb', line 25 def initialize(data, kcfg_path) @kcfg = data @kcfg_path = kcfg_path raise 'Unknown kubeconfig version' if @kcfg['apiVersion'] != 'v1' end |
Class Method Details
Instance Method Details
#context(context_name = nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/kubeclient/config.rb', line 41 def context(context_name = nil) cluster, user, namespace = fetch_context(context_name || @kcfg['current-context']) ca_cert_data = fetch_cluster_ca_data(cluster) client_cert_data = fetch_user_cert_data(user) client_key_data = fetch_user_key_data(user) = (user) = {} if !ca_cert_data.nil? cert_store = OpenSSL::X509::Store.new cert_store.add_cert(OpenSSL::X509::Certificate.new(ca_cert_data)) [:verify_ssl] = OpenSSL::SSL::VERIFY_PEER [:cert_store] = cert_store else [:verify_ssl] = OpenSSL::SSL::VERIFY_NONE end unless client_cert_data.nil? [:client_cert] = OpenSSL::X509::Certificate.new(client_cert_data) end unless client_key_data.nil? [:client_key] = OpenSSL::PKey.read(client_key_data) end Context.new(cluster['server'], @kcfg['apiVersion'], , , namespace) end |
#contexts ⇒ Object
37 38 39 |
# File 'lib/kubeclient/config.rb', line 37 def contexts @kcfg['contexts'].map { |x| x['name'] } end |