class Kubes::Config

Attributes

config[R]

Public Class Methods

new() click to toggle source
# File lib/kubes/config.rb, line 7
def initialize
  @config = defaults
end

Public Instance Methods

configure() { |config| ... } click to toggle source
# File lib/kubes/config.rb, line 81
def configure
  yield(@config)
end
defaults() click to toggle source
# File lib/kubes/config.rb, line 11
def defaults
  config = ActiveSupport::OrderedOptions.new

  config.auto_prune = true

  config.builder = "docker" # IE: docker or gcloud

  # Auto-switching options
  config.kubectl = ActiveSupport::OrderedOptions.new
  config.kubectl.context = nil
  config.kubectl.context_keep = true # after switching context keep it

  # whether or not continue if the kubectl command fails
  config.kubectl.exit_on_fail = ActiveSupport::OrderedOptions.new
  config.kubectl.exit_on_fail.apply  = true # whether or not continue if the kubectl apply command fails
  config.kubectl.exit_on_fail.delete = false # whether or not continue if the kubectl delete command fails
  # Note: delete is a internal method to ActiveSupport::OrderedOptions so will have to access it with ['...']

  config.kubectl.order = ActiveSupport::OrderedOptions.new
  config.kubectl.order.roles = role_order
  config.kubectl.order.kinds = kind_order

  config.repo = nil # expected to be set by .kubes/config.rb
  config.repo_auto_auth = true

  config.logger = Logger.new($stderr)
  config.logger.level = ENV['KUBES_LOG_LEVEL'] || :info

  config.skip = []

  config.state = ActiveSupport::OrderedOptions.new
  config.state.path = "#{Kubes.root}/.kubes/state/#{Kubes.env}/data.json"

  config.suffix_hash = true # append suffix hash to ConfigMap and Secret

  config
end
kind_order() click to toggle source

Create resources in specific order so dependent resources are available

# File lib/kubes/config.rb, line 58
def kind_order
  %w[
    Namespace
    StorageClass
    CustomResourceDefinition
    MutatingWebhookConfiguration
    ServiceAccount
    PodSecurityPolicy
    Role
    ClusterRole
    RoleBinding
    ClusterRoleBinding
    ConfigMap
    Secret
    Service
    LimitRange
    Deployment
    StatefulSet
    CronJob
    PodDisruptionBudget
  ]
end
load_configs() click to toggle source

Load configs example:

.kubes/config.rb .kubes/config/env/dev.rb .kubes/config/plugins/google.rb .kubes/config/plugins/google/dev.rb

# File lib/kubes/config.rb, line 92
def load_configs
  evaluate_file(".kubes/config.rb")
  evaluate_file(".kubes/config/env/#{Kubes.env}.rb")
  Kubes::Plugin.plugins.each do |klass|
    # klass: IE: KubesAws, KubesGoogle
    name = klass.to_s.underscore.sub('kubes_','') # kubes_google => google
    evaluate_file(".kubes/config/plugins/#{name}.rb")
    evaluate_file(".kubes/config/plugins/#{name}/#{Kubes.env}.rb")
  end
end
role_order() click to toggle source

Create shared resources first

# File lib/kubes/config.rb, line 50
def role_order
  %w[
    common
    shared
  ]
end