Sha256: 6e44e58f723b43d9191c46e25704209f2712cfbeeb92ce78b9ee2288e9c9d1d7

Contents?: true

Size: 987 Bytes

Versions: 1

Compression:

Stored size: 987 Bytes

Contents

# frozen_string_literal: true

module CronKubernetes
  module Context
    # Kubeclient Context from well-known locations within a Kubernetes cluster.
    class WellKnown
      TOKEN_FILE     = "/var/run/secrets/kubernetes.io/serviceaccount/token"
      CA_FILE        = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
      NAMESPACE_FILE = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"

      def applicable?
        File.exist?(TOKEN_FILE)
      end

      def context
        CronKubernetes::KubeclientContext::Context.new(
          "https://kubernetes.default.svc",
          "v1",
          namespace,
          auth_options: {bearer_token_file: TOKEN_FILE},
          ssl_options:
        )
      end

      private

      def namespace
        return nil unless File.exist?(NAMESPACE_FILE)

        File.read(NAMESPACE_FILE)
      end

      def ssl_options
        return {} unless File.exist?(CA_FILE)

        {ca_file: CA_FILE}
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cron-kubernetes-3.0.0 lib/cron_kubernetes/context/well_known.rb