Sha256: 693f0cf716731b4475f12c7974d896248c45c57155984145b31c717131473a14

Contents?: true

Size: 1.42 KB

Versions: 10

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true
require 'kubeclient'
require 'kubernetes-deploy/kubeclient_builder/google_friendly_config'

module KubernetesDeploy
  module KubeclientBuilder
    class ContextMissingError < FatalDeploymentError
      def initialize(context_name)
        super("`#{context_name}` context must be configured in your KUBECONFIG (#{ENV['KUBECONFIG']}).")
      end
    end

    private

    def build_v1_kubeclient(context)
      _build_kubeclient(
        api_version: "v1",
        context: context
      )
    end

    def build_v1beta1_kubeclient(context)
      _build_kubeclient(
        api_version: "v1beta1",
        context: context,
        endpoint_path: "/apis/extensions/"
      )
    end

    def build_policy_v1beta1_kubeclient(context)
      _build_kubeclient(
        api_version: "v1beta1",
        context: context,
        endpoint_path: "/apis/policy/"
      )
    end

    def _build_kubeclient(api_version:, context:, endpoint_path: nil)
      config = GoogleFriendlyConfig.read(ENV.fetch("KUBECONFIG"))
      unless config.contexts.include?(context)
        raise ContextMissingError, context
      end
      kube_context = config.context(context)

      client = Kubeclient::Client.new(
        "#{kube_context.api_endpoint}#{endpoint_path}",
        api_version,
        ssl_options: kube_context.ssl_options,
        auth_options: kube_context.auth_options
      )
      client.discover
      client
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
kubernetes-deploy-0.12.12 lib/kubernetes-deploy/kubeclient_builder.rb
kubernetes-deploy-0.12.11 lib/kubernetes-deploy/kubeclient_builder.rb
kubernetes-deploy-0.12.10 lib/kubernetes-deploy/kubeclient_builder.rb
kubernetes-deploy-0.12.9 lib/kubernetes-deploy/kubeclient_builder.rb
kubernetes-deploy-0.12.8 lib/kubernetes-deploy/kubeclient_builder.rb
kubernetes-deploy-0.12.7 lib/kubernetes-deploy/kubeclient_builder.rb
kubernetes-deploy-0.12.6 lib/kubernetes-deploy/kubeclient_builder.rb
kubernetes-deploy-0.12.5 lib/kubernetes-deploy/kubeclient_builder.rb
kubernetes-deploy-0.12.4 lib/kubernetes-deploy/kubeclient_builder.rb
kubernetes-deploy-0.12.3 lib/kubernetes-deploy/kubeclient_builder.rb