Sha256: 3171cc38e59d1790e8837086b4bc17b2351e1f45322c26b721274fdb9b30a50b

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Resque
  module Kubernetes
    module Context
      # Kubeclient Context from `kubectl` config file.
      class Kubectl
        def applicable?
          File.exist?(kubeconfig)
        end

        def context
          config = Kubeclient::Config.read(kubeconfig)

          Resque::Kubernetes::ContextFactory::Context.new(
              config.context.api_endpoint,
              config.context.api_version,
              config.context.namespace,
              auth_options: auth_options(config),
              ssl_options:  config.context.ssl_options
          )
        end

        private

        def kubeconfig
          File.join(ENV["HOME"], ".kube", "config")
        end

        def auth_options(config)
          options = config.context.auth_options
          return options unless options.empty?
          google_application_default_credentials
        end

        def google_application_default_credentials
          return unless defined?(Google) && defined?(Google::Auth)
          {bearer_token: Kubeclient::GoogleApplicationDefaultCredentials.token}
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
resque-kubernetes-2.0.0 lib/resque/kubernetes/context/kubectl.rb
resque-kubernetes-1.3.0 lib/resque/kubernetes/context/kubectl.rb
resque-kubernetes-1.2.0 lib/resque/kubernetes/context/kubectl.rb
resque-kubernetes-1.1.0 lib/resque/kubernetes/context/kubectl.rb