Module: Dapp::Kube::Dapp::Command::Lint

Included in:
Dapp
Defined in:
lib/dapp/kube/dapp/command/lint.rb

Instance Method Summary collapse

Instance Method Details

#kube_chart_nameObject



6
7
8
9
10
11
12
13
14
15
# File 'lib/dapp/kube/dapp/command/lint.rb', line 6

def kube_chart_name
  chart_yaml_path = kube_chart_path.join("Chart.yaml")
  chart_spec = yaml_load_file(chart_yaml_path)

  if chart_spec["name"].nil? || chart_spec["name"].empty?
    raise ::Dapp::Error::Command, code: :no_helm_chart_spec_name, data: { name: chart_spec["name"], path: chart_yaml_path, raw_spec: chart_yaml_path.read.strip }
  end

  chart_spec["name"]
end

#kube_lintObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/dapp/kube/dapp/command/lint.rb', line 30

def kube_lint
  kube_check_helm_chart!

  repo = option_repo

  docker_tag = option_tags.first

  with_kube_tmp_lint_chart_dir do
    kube_copy_chart
    kube_generate_helm_chart_tpl
    kube_helm_decode_secrets

    all_values = {}
    [kube_chart_path('values.yaml').expand_path, *kube_values_paths, *kube_tmp_chart_secret_values_paths].each do |values_path|
      all_values = all_values.in_depth_merge(yaml_load_file(values_path))
    end

    options[:helm_set_options].each do |opt_spec|
      name, _, value = opt_spec.partition("=")
      keys = name.split(".")

      values = all_values
      keys.each_with_index do |key, ind|
        if ind == keys.size - 1
          values[key] = YAML.load(value)
        else
          values[key] ||= {}
          values = values[key]
        end
      end
    end

    service_values = Helm::Values.service_values_hash(self, repo, kube_namespace, docker_tag, fake: true)
    all_values = all_values.in_depth_merge service_values

    kube_chart_path_for_helm.join("values.yaml").write YAML.dump(all_values)

    shellout! "helm lint --strict #{kube_chart_path_for_helm}"
  end
end

#with_kube_tmp_lint_chart_dir(&blk) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dapp/kube/dapp/command/lint.rb', line 17

def with_kube_tmp_lint_chart_dir(&blk)
  old_kube_tmp_helm_chart_dir = @kube_tmp_helm_chart_dir
  unless ENV['DAPP_HELM_CHART_DIR']
    @kube_tmp_helm_chart_dir = File.join(Dir.mktmpdir('dapp-helm-lint-', tmp_base_dir), kube_chart_name)
  end

  begin
    with_kube_tmp_chart_dir(&blk)
  ensure
    @kube_tmp_helm_chart_dir = old_kube_tmp_helm_chart_dir
  end
end