Class: Kerbi::State::ConfigMapBackend
- Inherits:
-
BaseBackend
- Object
- BaseBackend
- Kerbi::State::ConfigMapBackend
- Includes:
- Mixins::CmBackendTesting
- Defined in:
- lib/state/config_map_backend.rb
Overview
Treats a Kubernetes configmap in a namespace as a persistent store for state entries. Reads and writes to the configmap.
Instance Attribute Summary collapse
-
#auth_bundle ⇒ Hash
readonly
Credentials generated by Utils::K8sAuth to use for auth.
-
#namespace ⇒ String
readonly
Kubernetes namespace where configmap lives.
Attributes inherited from BaseBackend
Instance Method Summary collapse
-
#apply_resource(resource_desc, mode: 'create') ⇒ Object
Creates the configmap given an exact dict representation of its contents.
-
#create_namespace ⇒ Object
Creates the required namespace resource for this configmap in the cluster.
-
#create_resource ⇒ Object
Creates the configmap with 0 entries.
-
#initialize(auth_bundle, release_name, namespace) ⇒ ConfigMapBackend
constructor
A new instance of ConfigMapBackend.
-
#provision_missing_resources(**opts) ⇒ Object
Checks for the namespace and configmap, creating along the way if missing.
- #resource_name ⇒ Object
- #resource_signature ⇒ Object
-
#template_resource(entries) ⇒ Hash
Outputs the dict representation of the configmap, templated with the given entries.
Methods included from Mixins::CmBackendTesting
#data_readable?, #echo_init, #namespace_exists?, #puts_outcome, #read_write_ready?, #resource_exists?, #test_connection, #test_list_namespaces, #test_target_ns_exists
Methods inherited from BaseBackend
#delete, #delete_entry, #entries, #entry_set, #prime, #save, #working?
Constructor Details
#initialize(auth_bundle, release_name, namespace) ⇒ ConfigMapBackend
Returns a new instance of ConfigMapBackend.
23 24 25 26 27 |
# File 'lib/state/config_map_backend.rb', line 23 def initialize(auth_bundle, release_name, namespace) @auth_bundle = auth_bundle.freeze @release_name = release_name.freeze @namespace = (namespace || @release_name).freeze end |
Instance Attribute Details
#auth_bundle ⇒ Hash (readonly)
Credentials generated by Utils::K8sAuth to use for auth
14 15 16 |
# File 'lib/state/config_map_backend.rb', line 14 def auth_bundle @auth_bundle end |
#namespace ⇒ String (readonly)
Kubernetes namespace where configmap lives
19 20 21 |
# File 'lib/state/config_map_backend.rb', line 19 def namespace @namespace end |
Instance Method Details
#apply_resource(resource_desc, mode: 'create') ⇒ Object
Creates the configmap given an exact dict representation of its contents. This method doesn’t actually get used outside of rspec, but it’s super useful there so keeping for time being.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/state/config_map_backend.rb', line 52 def apply_resource(resource_desc, mode: 'create') if mode == 'create' #noinspection RubyResolve client("v1").create_config_map(resource_desc) elsif mode == 'update' #noinspection RubyResolve client("v1").update_config_map(resource_desc) else raise "What kind of sick mode is #{mode}?" end end |
#create_namespace ⇒ Object
Creates the required namespace resource for this configmap in the cluster.
81 82 83 84 85 86 |
# File 'lib/state/config_map_backend.rb', line 81 def create_namespace values = { namespace: namespace } dict = Kerbi::State::NamespaceMixer.new(values).run.first #noinspection RubyResolve client("v1").create_namespace(dict) end |
#create_resource ⇒ Object
Creates the configmap with 0 entries.
43 44 45 |
# File 'lib/state/config_map_backend.rb', line 43 def create_resource apply_resource(template_resource([])) end |
#provision_missing_resources(**opts) ⇒ Object
Checks for the namespace and configmap, creating along the way if missing. Does not raise if already exists.
33 34 35 36 37 38 39 |
# File 'lib/state/config_map_backend.rb', line 33 def provision_missing_resources(**opts) create_namespace unless (ns_existed = namespace_exists?) echo_init("namespaces/#{namespace}", ns_existed, opts) create_resource unless (cm_existed = resource_exists?) echo_init("configmaps/#{namespace}/#{cm_name}", cm_existed, opts) end |
#resource_name ⇒ Object
88 89 90 |
# File 'lib/state/config_map_backend.rb', line 88 def resource_name cm_name end |
#resource_signature ⇒ Object
92 93 94 |
# File 'lib/state/config_map_backend.rb', line 92 def resource_signature "configmaps/#{namespace}/#{resource_name}" end |
#template_resource(entries) ⇒ Hash
Outputs the dict representation of the configmap, templated with the given entries.
69 70 71 72 73 74 75 76 |
# File 'lib/state/config_map_backend.rb', line 69 def template_resource(entries) values = { consts::ENTRIES_ATTR => entries.map(&:to_h), namespace: namespace, cm_name: cm_name } Kerbi::State::ConfigMapMixer.new(values).run.first end |