summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMayra Cabrera <mcabrera@gitlab.com>2018-06-19 16:07:28 -0500
committerMayra Cabrera <mcabrera@gitlab.com>2018-06-19 16:18:19 -0500
commit5e47ae45e8c4367b52569bbdec722f9509b22b2d (patch)
treeac6ae82c79f7516a2eec0d973b924dc70fdec8e2
parent0397b8134fc56fc04a4f5b508bd44e51d460c6dc (diff)
downloadgitlab-ce-48126-fix-prometheus-installation.tar.gz
Specify chart version when deploying apps to clusters48126-fix-prometheus-installation
When deploying apps to GKE cluster we use the stable chart, and that expose us to breaking changes like when enforcing a chart version. Closes #48126
-rw-r--r--app/models/clusters/applications/ingress.rb4
-rw-r--r--app/models/clusters/applications/jupyter.rb4
-rw-r--r--app/models/clusters/applications/prometheus.rb8
-rw-r--r--app/models/clusters/applications/runner.rb4
-rw-r--r--app/models/clusters/concerns/application_core.rb4
-rw-r--r--app/models/clusters/concerns/application_data.rb7
-rw-r--r--changelogs/unreleased/48126-fix-prometheus-installation.yml5
-rw-r--r--lib/gitlab/kubernetes/helm/chart.rb14
-rw-r--r--lib/gitlab/kubernetes/helm/install_command.rb12
-rw-r--r--spec/lib/gitlab/kubernetes/helm/api_spec.rb2
-rw-r--r--spec/lib/gitlab/kubernetes/helm/install_command_spec.rb53
-rw-r--r--spec/models/clusters/applications/ingress_spec.rb9
-rw-r--r--spec/models/clusters/applications/jupyter_spec.rb11
-rw-r--r--spec/models/clusters/applications/prometheus_spec.rb11
-rw-r--r--spec/models/clusters/applications/runner_spec.rb13
15 files changed, 135 insertions, 26 deletions
diff --git a/app/models/clusters/applications/ingress.rb b/app/models/clusters/applications/ingress.rb
index 27fc3b85465..91b17fa5de0 100644
--- a/app/models/clusters/applications/ingress.rb
+++ b/app/models/clusters/applications/ingress.rb
@@ -26,14 +26,14 @@ module Clusters
end
end
- def chart
+ def chart_name
'stable/nginx-ingress'
end
def install_command
Gitlab::Kubernetes::Helm::InstallCommand.new(
name,
- chart: chart,
+ chart: chart_data,
values: values
)
end
diff --git a/app/models/clusters/applications/jupyter.rb b/app/models/clusters/applications/jupyter.rb
index 975d434e1a4..2206d2a1f42 100644
--- a/app/models/clusters/applications/jupyter.rb
+++ b/app/models/clusters/applications/jupyter.rb
@@ -21,7 +21,7 @@ module Clusters
end
end
- def chart
+ def chart_name
"#{name}/jupyterhub"
end
@@ -36,7 +36,7 @@ module Clusters
def install_command
Gitlab::Kubernetes::Helm::InstallCommand.new(
name,
- chart: chart,
+ chart: chart_data,
values: values,
repository: repository
)
diff --git a/app/models/clusters/applications/prometheus.rb b/app/models/clusters/applications/prometheus.rb
index c702c4ee807..95f571ca3d0 100644
--- a/app/models/clusters/applications/prometheus.rb
+++ b/app/models/clusters/applications/prometheus.rb
@@ -21,7 +21,7 @@ module Clusters
end
end
- def chart
+ def chart_name
'stable/prometheus'
end
@@ -33,10 +33,14 @@ module Clusters
80
end
+ def chart_version
+ '6.7.3'
+ end
+
def install_command
Gitlab::Kubernetes::Helm::InstallCommand.new(
name,
- chart: chart,
+ chart: { name: chart_name, version: chart_version },
values: values
)
end
diff --git a/app/models/clusters/applications/runner.rb b/app/models/clusters/applications/runner.rb
index e6f795f3e0b..e2b86e92764 100644
--- a/app/models/clusters/applications/runner.rb
+++ b/app/models/clusters/applications/runner.rb
@@ -14,7 +14,7 @@ module Clusters
default_value_for :version, VERSION
- def chart
+ def chart_name
"#{name}/gitlab-runner"
end
@@ -29,7 +29,7 @@ module Clusters
def install_command
Gitlab::Kubernetes::Helm::InstallCommand.new(
name,
- chart: chart,
+ chart: chart_data,
values: values,
repository: repository
)
diff --git a/app/models/clusters/concerns/application_core.rb b/app/models/clusters/concerns/application_core.rb
index 623b836c0ed..e55f733105e 100644
--- a/app/models/clusters/concerns/application_core.rb
+++ b/app/models/clusters/concerns/application_core.rb
@@ -28,6 +28,10 @@ module Clusters
# Override if you need extra data synchronized
# from K8s after installation
end
+
+ def chart_version
+ nil
+ end
end
end
end
diff --git a/app/models/clusters/concerns/application_data.rb b/app/models/clusters/concerns/application_data.rb
index 96ac757e99e..a4c104bfdca 100644
--- a/app/models/clusters/concerns/application_data.rb
+++ b/app/models/clusters/concerns/application_data.rb
@@ -17,6 +17,13 @@ module Clusters
def chart_values_file
"#{Rails.root}/vendor/#{name}/values.yaml"
end
+
+ def chart_data
+ {
+ name: chart_name,
+ version: chart_version
+ }
+ end
end
end
end
diff --git a/changelogs/unreleased/48126-fix-prometheus-installation.yml b/changelogs/unreleased/48126-fix-prometheus-installation.yml
new file mode 100644
index 00000000000..e6ab9c46fbf
--- /dev/null
+++ b/changelogs/unreleased/48126-fix-prometheus-installation.yml
@@ -0,0 +1,5 @@
+---
+title: Specify chart version when installing applications on Clusters
+merge_request: 20010
+author:
+type: fixed
diff --git a/lib/gitlab/kubernetes/helm/chart.rb b/lib/gitlab/kubernetes/helm/chart.rb
new file mode 100644
index 00000000000..37ead5782cf
--- /dev/null
+++ b/lib/gitlab/kubernetes/helm/chart.rb
@@ -0,0 +1,14 @@
+module Gitlab
+ module Kubernetes
+ module Helm
+ class Chart
+ attr_reader :name, :version
+
+ def initialize(name, version)
+ @name = name
+ @version = version
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/kubernetes/helm/install_command.rb b/lib/gitlab/kubernetes/helm/install_command.rb
index 30af3e97b4a..98e4faf8ef2 100644
--- a/lib/gitlab/kubernetes/helm/install_command.rb
+++ b/lib/gitlab/kubernetes/helm/install_command.rb
@@ -6,7 +6,7 @@ module Gitlab
def initialize(name, chart:, values:, repository: nil)
@name = name
- @chart = chart
+ @chart = Gitlab::Kubernetes::Helm::Chart.new(chart[:name], chart[:version])
@values = values
@repository = repository
end
@@ -39,9 +39,17 @@ module Gitlab
def script_command
<<~HEREDOC
- helm install #{chart} --name #{name} --namespace #{Gitlab::Kubernetes::Helm::NAMESPACE} -f /data/helm/#{name}/config/values.yaml >/dev/null
+ helm install #{chart.name} #{dynamic_chart_flags} --namespace #{Gitlab::Kubernetes::Helm::NAMESPACE} -f /data/helm/#{name}/config/values.yaml >/dev/null
HEREDOC
end
+
+ def dynamic_chart_flags
+ if chart.version
+ "--name #{name} --version #{chart.version}"
+ else
+ "--name #{name}"
+ end
+ end
end
end
end
diff --git a/spec/lib/gitlab/kubernetes/helm/api_spec.rb b/spec/lib/gitlab/kubernetes/helm/api_spec.rb
index 740466ea5cb..c8460b0bd03 100644
--- a/spec/lib/gitlab/kubernetes/helm/api_spec.rb
+++ b/spec/lib/gitlab/kubernetes/helm/api_spec.rb
@@ -10,7 +10,7 @@ describe Gitlab::Kubernetes::Helm::Api do
let(:command) do
Gitlab::Kubernetes::Helm::InstallCommand.new(
application.name,
- chart: application.chart,
+ chart: { name: application.chart_name, version: application.chart_version },
values: application.values
)
end
diff --git a/spec/lib/gitlab/kubernetes/helm/install_command_spec.rb b/spec/lib/gitlab/kubernetes/helm/install_command_spec.rb
index 547f3f1752c..3b32d550d5b 100644
--- a/spec/lib/gitlab/kubernetes/helm/install_command_spec.rb
+++ b/spec/lib/gitlab/kubernetes/helm/install_command_spec.rb
@@ -7,29 +7,47 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do
let(:install_command) do
described_class.new(
application.name,
- chart: application.chart,
+ chart: { name: application.chart_name, version: application.chart_version },
values: application.values
)
end
subject { install_command }
- it_behaves_like 'helm commands' do
- let(:commands) do
- <<~EOS
+ context 'for ingress' do
+ let(:application) { create(:clusters_applications_ingress) }
+
+ it_behaves_like 'helm commands' do
+ let(:commands) do
+ <<~EOS
+ helm init --client-only >/dev/null
+ helm install #{application.chart_name} --name #{application.name} --namespace #{namespace} -f /data/helm/#{application.name}/config/values.yaml >/dev/null
+ EOS
+ end
+ end
+ end
+
+ context 'for prometheus' do
+ let(:application) { create(:clusters_applications_prometheus) }
+
+ it_behaves_like 'helm commands' do
+ let(:commands) do
+ <<~EOS
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
- EOS
+ helm install #{application.chart_name} --name #{application.name} --version #{application.chart_version} --namespace #{namespace} -f /data/helm/#{application.name}/config/values.yaml >/dev/null
+ EOS
+ end
end
end
- context 'with an application with a repository' do
+ context 'for runner' 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,
+ chart: { name: application.chart_name, version: application.chart_version },
values: application.values,
repository: application.repository
)
@@ -38,9 +56,22 @@ describe Gitlab::Kubernetes::Helm::InstallCommand do
it_behaves_like 'helm commands' do
let(:commands) do
<<~EOS
- helm init --client-only >/dev/null
- 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
+ helm init --client-only >/dev/null
+ helm repo add #{application.name} #{application.repository}
+ helm install #{application.chart_name} --name #{application.name} --namespace #{namespace} -f /data/helm/#{application.name}/config/values.yaml >/dev/null
+ EOS
+ end
+ end
+ end
+
+ context 'for jupyter' do
+ let(:application) { create(:clusters_applications_jupyter) }
+
+ it_behaves_like 'helm commands' do
+ let(:commands) do
+ <<~EOS
+ helm init --client-only >/dev/null
+ helm install #{application.chart_name} --name #{application.name} --namespace #{namespace} -f /data/helm/#{application.name}/config/values.yaml >/dev/null
EOS
end
end
diff --git a/spec/models/clusters/applications/ingress_spec.rb b/spec/models/clusters/applications/ingress_spec.rb
index a47a07d908d..abae6bf4171 100644
--- a/spec/models/clusters/applications/ingress_spec.rb
+++ b/spec/models/clusters/applications/ingress_spec.rb
@@ -72,7 +72,8 @@ describe Clusters::Applications::Ingress do
it 'should be initialized with ingress arguments' do
expect(subject.name).to eq('ingress')
- expect(subject.chart).to eq('stable/nginx-ingress')
+ expect(subject.chart.name).to eq('stable/nginx-ingress')
+ expect(subject.chart.version).to be_nil
expect(subject.values).to eq(ingress.values)
end
end
@@ -87,4 +88,10 @@ describe Clusters::Applications::Ingress do
is_expected.to include('podAnnotations')
end
end
+
+ describe '#chart_version' do
+ subject { ingress.chart_version }
+
+ it { is_expected.to be_nil }
+ end
end
diff --git a/spec/models/clusters/applications/jupyter_spec.rb b/spec/models/clusters/applications/jupyter_spec.rb
index ca48a1d8072..713030f4c10 100644
--- a/spec/models/clusters/applications/jupyter_spec.rb
+++ b/spec/models/clusters/applications/jupyter_spec.rb
@@ -35,7 +35,8 @@ describe Clusters::Applications::Jupyter do
it 'should be initialized with 4 arguments' do
expect(subject.name).to eq('jupyter')
- expect(subject.chart).to eq('jupyter/jupyterhub')
+ expect(subject.chart.name).to eq('jupyter/jupyterhub')
+ expect(subject.chart.version).to be_nil
expect(subject.repository).to eq('https://jupyterhub.github.io/helm-chart/')
expect(subject.values).to eq(jupyter.values)
end
@@ -56,4 +57,12 @@ describe Clusters::Applications::Jupyter do
is_expected.to include("callbackUrl: #{jupyter.callback_url}")
end
end
+
+ describe '#chart_version' do
+ let(:jupyter) { create(:clusters_applications_jupyter) }
+
+ subject { jupyter.chart_version }
+
+ it { is_expected.to be_nil }
+ end
end
diff --git a/spec/models/clusters/applications/prometheus_spec.rb b/spec/models/clusters/applications/prometheus_spec.rb
index d2302583ac8..459c0f734c8 100644
--- a/spec/models/clusters/applications/prometheus_spec.rb
+++ b/spec/models/clusters/applications/prometheus_spec.rb
@@ -108,7 +108,8 @@ describe Clusters::Applications::Prometheus do
it 'should be initialized with 3 arguments' do
expect(subject.name).to eq('prometheus')
- expect(subject.chart).to eq('stable/prometheus')
+ expect(subject.chart.name).to eq('stable/prometheus')
+ expect(subject.chart.version).to eq('6.7.3')
expect(subject.values).to eq(prometheus.values)
end
end
@@ -126,4 +127,12 @@ describe Clusters::Applications::Prometheus do
is_expected.to include('serverFiles')
end
end
+
+ describe '#chart_version' do
+ let(:prometheus) { create(:clusters_applications_prometheus) }
+
+ subject { prometheus.chart_version }
+
+ it { is_expected.to eq('6.7.3') }
+ end
end
diff --git a/spec/models/clusters/applications/runner_spec.rb b/spec/models/clusters/applications/runner_spec.rb
index 3ef59457c5f..204ab5cd03a 100644
--- a/spec/models/clusters/applications/runner_spec.rb
+++ b/spec/models/clusters/applications/runner_spec.rb
@@ -30,7 +30,8 @@ describe Clusters::Applications::Runner do
it 'should be initialized with 4 arguments' do
expect(subject.name).to eq('runner')
- expect(subject.chart).to eq('runner/gitlab-runner')
+ expect(subject.chart.name).to eq('runner/gitlab-runner')
+ expect(subject.chart.version).to be_nil
expect(subject.repository).to eq('https://charts.gitlab.io')
expect(subject.values).to eq(gitlab_runner.values)
end
@@ -103,4 +104,14 @@ describe Clusters::Applications::Runner do
end
end
end
+
+ describe '#chart_version' do
+ let(:project) { create(:project) }
+ let(:cluster) { create(:cluster, projects: [project]) }
+ let(:gitlab_runner) { create(:clusters_applications_runner, cluster: cluster) }
+
+ subject { gitlab_runner.chart_version }
+
+ it { is_expected.to be_nil }
+ end
end