Class: Kubes::Config

Inherits:
Object
  • Object
show all
Includes:
DslEvaluator, Singleton
Defined in:
lib/kubes/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



7
8
9
# File 'lib/kubes/config.rb', line 7

def initialize
  @config = defaults
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/kubes/config.rb', line 6

def config
  @config
end

Instance Method Details

#configure {|@config| ... } ⇒ Object

Yields:



87
88
89
# File 'lib/kubes/config.rb', line 87

def configure
  yield(@config)
end

#defaultsObject



11
12
13
14
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
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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 = false # 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.layering = ActiveSupport::OrderedOptions.new
  config.layering.show = ENV['KUBES_LAYERING_SHOW'] || false

  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/tmp/state", Kubes.app, "#{Kubes.env}/data.json"].compact.join('/')

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

  config.merger = ActiveSupport::OrderedOptions.new
  config.merger.options = {overwrite_arrays: true}

  config
end

#kind_orderObject

Create resources in specific order so dependent resources are available



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/kubes/config.rb', line 64

def kind_order
  %w[
    Namespace
    StorageClass
    CustomResourceDefinition
    MutatingWebhookConfiguration
    ServiceAccount
    PodSecurityPolicy
    Role
    ClusterRole
    RoleBinding
    ClusterRoleBinding
    ConfigMap
    Secret
    Service
    LimitRange
    Deployment
    StatefulSet
    CronJob
    PodDisruptionBudget
  ]
end

#load_configsObject

Load configs example:

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



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/kubes/config.rb', line 98

def load_configs
  evaluate_file(".kubes/config.rb")
  evaluate_file(".kubes/config/env/#{Kubes.env}.rb")
  if Kubes.app
    # TODO: deprecate
    evaluate_file(".kubes/config/env/#{Kubes.app}.rb")
    evaluate_file(".kubes/config/env/#{Kubes.app}/#{Kubes.env}.rb")
    # newer
    evaluate_file(".kubes/config/app/#{Kubes.app}.rb")
    evaluate_file(".kubes/config/app/#{Kubes.app}/#{Kubes.env}.rb")
  end
  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_orderObject

Create shared resources first



56
57
58
59
60
61
# File 'lib/kubes/config.rb', line 56

def role_order
  %w[
    common
    shared
  ]
end