Class: KubeDeployTools::ConfigMap
- Defined in:
- lib/kube_deploy_tools/make_configmap.rb
Instance Method Summary collapse
- #base ⇒ Object
-
#initialize(name, from_file, namespace = 'default', labels = nil) ⇒ ConfigMap
constructor
A new instance of ConfigMap.
- #target_hash ⇒ Object
Constructor Details
#initialize(name, from_file, namespace = 'default', labels = nil) ⇒ ConfigMap
Returns a new instance of ConfigMap.
7 8 9 10 11 12 |
# File 'lib/kube_deploy_tools/make_configmap.rb', line 7 def initialize(name, from_file, namespace = 'default', labels = nil) @name = name @namespace = namespace @labels = labels @from_file = from_file end |
Instance Method Details
#base ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/kube_deploy_tools/make_configmap.rb', line 14 def base { 'apiVersion' => 'v1', 'kind' => 'ConfigMap', 'metadata' => {}, 'data' => {} } end |
#target_hash ⇒ Object
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 |
# File 'lib/kube_deploy_tools/make_configmap.rb', line 23 def target_hash res = base res['metadata']['name'] = @name res['metadata']['namespace'] = @namespace res['metadata']['labels'] = @labels if @labels @from_file.each do |from_file| if from_file.include? '=' # e.g. --from-file=config.yml=/path/to/configs/production.yml configmap_key, filepath = from_file.split("=", 2) res['data'][configmap_key] = File.read(filepath) elsif File.file?(from_file) # e.g. --from-file=/path/to/configs/production.yml configmap_key = File.basename(from_file) filepath = from_file res['data'][configmap_key] = File.read(filepath) elsif File.directory?(from_file) # e.g. --from-file=/path/to/configs/ Dir[File.join(from_file, '*')].each do |filepath| # NOTE(jmodes): Multiple levels of directories are not supported. next if File.directory?(filepath) configmap_key = File.basename(filepath) res['data'][configmap_key] = File.read(filepath) end end end res end |