Class: GlooIngressAdapter::ClientFactory
- Inherits:
-
Object
- Object
- GlooIngressAdapter::ClientFactory
- Defined in:
- lib/gloo_ingress_adapter/client_factory.rb
Overview
Factory for Kubernetes clients
Constant Summary collapse
- KUBERNETES_API_URL =
"https://kubernetes.default.svc"
Instance Method Summary collapse
- #create_client(version:, api: nil) ⇒ Object
-
#initialize(kubeconfig:, logger:) ⇒ ClientFactory
constructor
A new instance of ClientFactory.
Constructor Details
#initialize(kubeconfig:, logger:) ⇒ ClientFactory
Returns a new instance of ClientFactory.
10 11 12 13 |
# File 'lib/gloo_ingress_adapter/client_factory.rb', line 10 def initialize(kubeconfig:, logger:) @kubeconfig = kubeconfig.freeze @logger = logger end |
Instance Method Details
#create_client(version:, api: nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gloo_ingress_adapter/client_factory.rb', line 15 def create_client(version:, api: nil) suffix = api ? "/apis/#{api}" : "" = { timeouts: { open: 30, read: 30 }, } url = KUBERNETES_API_URL if @kubeconfig context = Kubeclient::Config.read(@kubeconfig).context url = context.api_endpoint [:auth_options] = context. [:ssl_options] = context. else [:auth_options] = { bearer_token_file: "/var/run/secrets/kubernetes.io/serviceaccount/token" } if File.exist?("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt") [:ssl_options] = { ca_file: "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" } end end Kubeclient::Client.new("#{url}#{suffix}", version, **) end |