Module: KubeDeployTools::DeployConfigFileUtil

Included in:
DeployConfigFile, ImageRegistry::Driver::Aws
Defined in:
lib/kube_deploy_tools/deploy_config_file/util.rb

Instance Method Summary collapse

Instance Method Details

#check_and_err(condition, error) ⇒ Object



5
6
7
8
9
10
# File 'lib/kube_deploy_tools/deploy_config_file/util.rb', line 5

def check_and_err(condition, error)
  if ! condition
    Logger.error("Error in configuration #{@filename}")
    raise ArgumentError, error
  end
end

#check_and_warn(condition, warning) ⇒ Object



12
13
14
15
16
17
# File 'lib/kube_deploy_tools/deploy_config_file/util.rb', line 12

def check_and_warn(condition, warning)
  if ! condition
    Logger.warn("Warning in configuration #{@filename}")
    Logger.warn(warning)
  end
end

#load_library(lib) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/kube_deploy_tools/deploy_config_file/util.rb', line 19

def load_library(lib)
  # All paths must be valid accessible gcs paths for the current user.
  # To modify gcloud identity being used by this process, set
  # GOOGLE_APPLICATION_CREDENTIALS or sign in with `gcloud auth login`
  lib_config = nil
  if lib.start_with?('gs://')
    Tempfile.open(['gs-kdt-library', '.yaml']) do |t|
      out = Shellrunner.check_call('gsutil', 'cat', lib)
      t.write(out)
      t.flush
      lib_config = DeployConfigFile.new(t.path)
    end
  elsif File.exist?(lib)
    lib_config = DeployConfigFile.new(lib)
  else
    raise "Unsupported or non-existent library: #{lib}"
  end

  lib_config
end