install_command_spec.rb 2.7 KB
Newer Older
1 2 3
require 'rails_helper'

describe Gitlab::Kubernetes::Helm::InstallCommand do
4 5 6 7 8 9 10 11 12 13
  let(:application) { create(:clusters_applications_prometheus) }
  let(:namespace) { Gitlab::Kubernetes::Helm::NAMESPACE }

  let(:install_command) do
    described_class.new(
      application.name,
      chart: application.chart,
      values: application.values
    )
  end
14

15 16 17 18 19 20 21 22 23 24
  describe '#generate_script' do
    let(:command) do
      <<~MSG
      set -eo pipefail
      apk add -U ca-certificates openssl >/dev/null
      wget -q -O - https://kubernetes-helm.storage.googleapis.com/helm-v2.7.0-linux-amd64.tar.gz | tar zxC /tmp >/dev/null
      mv /tmp/linux-amd64/helm /usr/bin/
      helm init --client-only >/dev/null
      helm install #{application.chart} --name #{application.name} --namespace #{namespace} -f /data/helm/#{application.name}/config/values.yaml >/dev/null
      MSG
25 26
    end

27
    subject { install_command.generate_script }
28

29 30
    it 'should return appropriate command' do
      is_expected.to eq(command)
31 32
    end

33 34 35 36 37 38 39 40 41 42
    context 'with an application with a repository' do
      let(:ci_runner) { create(:ci_runner) }
      let(:application) { create(:clusters_applications_runner, runner: ci_runner) }
      let(:install_command) do
        described_class.new(
          application.name,
          chart: application.chart,
          values: application.values,
          repository: application.repository
        )
43 44 45 46 47 48 49 50 51
      end

      let(:command) do
        <<~MSG
        set -eo pipefail
        apk add -U ca-certificates openssl >/dev/null
        wget -q -O - https://kubernetes-helm.storage.googleapis.com/helm-v2.7.0-linux-amd64.tar.gz | tar zxC /tmp >/dev/null
        mv /tmp/linux-amd64/helm /usr/bin/
        helm init --client-only >/dev/null
52 53
        helm repo add #{application.name} #{application.repository}
        helm install #{application.chart} --name #{application.name} --namespace #{namespace} -f /data/helm/#{application.name}/config/values.yaml >/dev/null
54 55 56 57 58 59 60
        MSG
      end

      it 'should return appropriate command' do
        is_expected.to eq(command)
      end
    end
61
  end
62

63 64
  describe '#config_map?' do
    subject { install_command.config_map? }
65

66 67
    it { is_expected.to be_truthy }
  end
68

69 70 71 72 73 74 75
  describe '#config_map_resource' do
    let(:metadata) do
      {
        name: "values-content-configuration-#{application.name}",
        namespace: namespace,
        labels: { name: "values-content-configuration-#{application.name}" }
      }
76
    end
77

78
    let(:resource) { ::Kubeclient::Resource.new(metadata: metadata, data: { values: application.values }) }
79

80
    subject { install_command.config_map_resource }
81

82 83
    it 'returns a KubeClient resource with config map content for the application' do
      is_expected.to eq(resource)
84
    end
85 86
  end
end