class KeyValue::Kubernetes::Configmap::Client

Public Class Methods

new(kubernetes_client = nil) click to toggle source
# File lib/keyvalue/kubernetes/configmap.rb, line 13
def initialize(kubernetes_client = nil)
  @k8s_client = kubernetes_client || create_client
end

Public Instance Methods

read_key(key_name) click to toggle source
# File lib/keyvalue/kubernetes/configmap.rb, line 17
def read_key(key_name)
  configmap = @k8s_client.get_config_map(key_name, 'default')
  JSON.parse(configmap.data.value)
rescue Kubeclient::ResourceNotFoundError
  raise KeyNotFoundError, "Key '#{key_name}' not found"
end
update_key(key_name, value) click to toggle source
# File lib/keyvalue/kubernetes/configmap.rb, line 24
def update_key(key_name, value)
  @k8s_client.patch_config_map(
    key_name,
    { data: { value: value.to_json } },
    'default'
  )
rescue Kubeclient::ResourceNotFoundError
  raise KeyNotFoundError, "Key '#{key_name}' not found"
end