Module: Mortar::ClientHelper
- Included in:
- DescribeCommand, FireCommand, ListCommand, YankCommand
- Defined in:
- lib/mortar/mixins/client_helper.rb
Instance Method Summary collapse
Instance Method Details
#build_kubeconfig_from_env ⇒ K8s::Config
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mortar/mixins/client_helper.rb', line 23 def build_kubeconfig_from_env token = ENV['KUBE_TOKEN'] token = Base64.strict_decode64(token) K8s::Config.new( clusters: [ { name: 'kubernetes', cluster: { server: ENV['KUBE_SERVER'], certificate_authority_data: ENV['KUBE_CA'] } } ], users: [ { name: 'mortar', user: { token: token } } ], contexts: [ { name: 'mortar', context: { cluster: 'kubernetes', user: 'mortar' } } ], preferences: {}, current_context: 'mortar' ) rescue ArgumentError signal_usage_error "KUBE_TOKEN env doesn't seem to be base64 encoded!" end |
#client ⇒ K8s::Client
6 7 8 |
# File 'lib/mortar/mixins/client_helper.rb', line 6 def client @client ||= create_client end |
#create_client ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/mortar/mixins/client_helper.rb', line 10 def create_client if ENV['KUBE_TOKEN'] && ENV['KUBE_CA'] && ENV['KUBE_SERVER'] K8s::Client.new(K8s::Transport.config(build_kubeconfig_from_env)) elsif ENV['KUBECONFIG'] K8s::Client.config(K8s::Config.load_file(ENV['KUBECONFIG'])) elsif File.exist?(File.join(Dir.home, '.kube', 'config')) K8s::Client.config(K8s::Config.load_file(File.join(Dir.home, '.kube', 'config'))) else K8s::Client.in_cluster_config end end |