From 2e8685792fa930aa92fd5f83c029367ef94ee39e Mon Sep 17 00:00:00 2001 From: Gerard Hickey Date: Fri, 8 Apr 2022 15:21:03 -0700 Subject: [PATCH 01/10] Updated Helm template code to report minor version Signed-off-by: Gerard Hickey --- spec/helm_template_helper.rb | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/spec/helm_template_helper.rb b/spec/helm_template_helper.rb index 859eb021a2..be7b783985 100644 --- a/spec/helm_template_helper.rb +++ b/spec/helm_template_helper.rb @@ -2,17 +2,30 @@ require 'yaml' require 'open3' class HelmTemplate - def self.helm_version - `helm version -c`.match('Ver(sion)?:"v(\d)\.')[2] + @@_helm_major_version = nil + @@_helm_minor_version = nil + + def self.helm_major_version + if @@_helm_major_version.nil? + parts = `helm version -c`.match('Ver(sion)?:"v(\d)\.(\d+)\.') + @@_helm_major_version = parts[2].to_i + @@_helm_minor_version = parts[3].to_i + end + + @@_helm_major_version + end + + def self.helm_minor_version + @@_helm_minor_version end def self.helm_template_call(release_name: 'test', path: '-', namespace: nil, extra_args: nil) namespace_arg = namespace.nil? ? '' : "--namespace #{namespace}" - case helm_version - when "2" then + case helm_major_version + when 2 then "helm template -n #{release_name} -f #{path} #{namespace_arg} #{extra_args} ." - when "3" then + when 3 then "helm template #{release_name} . -f #{path} #{namespace_arg} #{extra_args}" else # If we don't know the version of Helm, use `false` command -- GitLab From c82ebeeb7c238b6a07668e38b88aba8d980ff2d0 Mon Sep 17 00:00:00 2001 From: Gerard Hickey Date: Fri, 8 Apr 2022 15:24:22 -0700 Subject: [PATCH 02/10] Updated Gitaly tests for running Helm 3.2+ vers Helm 3.1.x did not render the full security context where as anything greater than Helm 3.2.0 does render the full security context. These changes allow the spec tests to operate under any Helm 3 version. Signed-off-by: Gerard Hickey --- spec/configuration/gitaly_spec.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/spec/configuration/gitaly_spec.rb b/spec/configuration/gitaly_spec.rb index e04d3c9538..b2acf81855 100644 --- a/spec/configuration/gitaly_spec.rb +++ b/spec/configuration/gitaly_spec.rb @@ -142,7 +142,26 @@ describe 'Gitaly configuration' do gitaly_set = t.resources_by_kind('StatefulSet').select { |key| key == gitaly_stateful_set } security_context = gitaly_set[gitaly_stateful_set]['spec']['template']['spec']['securityContext'] - expect(security_context).to eq(expectedContext) + # This if statement can be simplified when testing support is + # dropped for Helm 3.1.x + if HelmTemplate.helm_major_version == 3 && HelmTemplate.helm_minor_version > 1 + # Helm 3.2+ renders the full security context. So we check given + # the expected context from the table above and then check the + # additional attributes that are not specified in the table above. + fullContext = {"runAsUser"=>1000, "fsGroup"=>1000} + unless expectedContext.nil? + expectedContext.keys.each do |expected_key| + expect(security_context[expected_key]).to eq(expectedContext[expected_key]) + fullContext.delete(expected_key) + end + end + + fullContext.keys.each do |unexpected_key| + expect(security_context[unexpected_key]).to eq(fullContext[unexpected_key]) + end + else + expect(security_context).to eq(expectedContext) + end end end end -- GitLab From dd2e2a70eec8b817fdb1f6187b5fb3613ab37dcc Mon Sep 17 00:00:00 2001 From: Gerard Hickey Date: Fri, 8 Apr 2022 15:35:39 -0700 Subject: [PATCH 03/10] Rubocop fixes --- spec/configuration/gitaly_spec.rb | 14 ++++++-------- spec/helm_template_helper.rb | 14 +++++++------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/spec/configuration/gitaly_spec.rb b/spec/configuration/gitaly_spec.rb index b2acf81855..ebbd36edc6 100644 --- a/spec/configuration/gitaly_spec.rb +++ b/spec/configuration/gitaly_spec.rb @@ -148,16 +148,14 @@ describe 'Gitaly configuration' do # Helm 3.2+ renders the full security context. So we check given # the expected context from the table above and then check the # additional attributes that are not specified in the table above. - fullContext = {"runAsUser"=>1000, "fsGroup"=>1000} - unless expectedContext.nil? - expectedContext.keys.each do |expected_key| - expect(security_context[expected_key]).to eq(expectedContext[expected_key]) - fullContext.delete(expected_key) - end + full_context = { "runAsUser" => 1000, "fsGroup" => 1000 } + expectedContext&.each_key do |expected_key| + expect(security_context[expected_key]).to eq(expectedContext[expected_key]) + full_context.delete(expected_key) end - fullContext.keys.each do |unexpected_key| - expect(security_context[unexpected_key]).to eq(fullContext[unexpected_key]) + full_context.each_key do |unexpected_key| + expect(security_context[unexpected_key]).to eq(full_context[unexpected_key]) end else expect(security_context).to eq(expectedContext) diff --git a/spec/helm_template_helper.rb b/spec/helm_template_helper.rb index be7b783985..352b5e6363 100644 --- a/spec/helm_template_helper.rb +++ b/spec/helm_template_helper.rb @@ -2,21 +2,21 @@ require 'yaml' require 'open3' class HelmTemplate - @@_helm_major_version = nil - @@_helm_minor_version = nil + @_helm_major_version = nil + @_helm_minor_version = nil def self.helm_major_version - if @@_helm_major_version.nil? + if @_helm_major_version.nil? parts = `helm version -c`.match('Ver(sion)?:"v(\d)\.(\d+)\.') - @@_helm_major_version = parts[2].to_i - @@_helm_minor_version = parts[3].to_i + @_helm_major_version = parts[2].to_i + @_helm_minor_version = parts[3].to_i end - @@_helm_major_version + @_helm_major_version end def self.helm_minor_version - @@_helm_minor_version + @_helm_minor_version end def self.helm_template_call(release_name: 'test', path: '-', namespace: nil, extra_args: nil) -- GitLab From fdabb5a0d3f0f2299f2abbf6d0c7d062f22eb29a Mon Sep 17 00:00:00 2001 From: Gerard Hickey Date: Fri, 15 Apr 2022 12:26:29 -0700 Subject: [PATCH 04/10] Update CI testing to use Helm v3.3.1 The minumum supported Helm version is specified as v3.3.1 and this updates the CI pipeline to use Helm v3.3.1 for all the testing. Signed-off-by: Gerard Hickey Changelog: other --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3e6ecf1675..e53cfa8c0f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -29,7 +29,7 @@ image: registry.gitlab.com/gitlab-org/gitlab-build-images:gitlab-charts-build-ba variables: AUTO_DEPLOY_TAG_REGEX: '^[0-9]+\.[0-9]+\.[0-9]+\+[a-z0-9]{7,}$' KUBECTL_VERSION: "v1.16.15" - HELM_VERSION: "3.1.2" + HELM_VERSION: "3.3.1" STABLE_REPO_URL: "https://charts.helm.sh/stable" GOOGLE_APPLICATION_CREDENTIALS: ${CI_PROJECT_DIR}/.google_keyfile.json # AUTO_DEVOPS_DOMAIN is the application deployment domain and should be set as a variable at the group or project level. -- GitLab From 64badd84bc446508ecf2c3195fcdd09179c4716e Mon Sep 17 00:00:00 2001 From: Gerard Hickey Date: Mon, 18 Apr 2022 14:48:10 -0700 Subject: [PATCH 05/10] Raise exception when Helm version less than minimum supported --- spec/configuration/gitaly_spec.rb | 2 -- spec/helm_template_helper.rb | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/configuration/gitaly_spec.rb b/spec/configuration/gitaly_spec.rb index ebbd36edc6..2df84f47c6 100644 --- a/spec/configuration/gitaly_spec.rb +++ b/spec/configuration/gitaly_spec.rb @@ -157,8 +157,6 @@ describe 'Gitaly configuration' do full_context.each_key do |unexpected_key| expect(security_context[unexpected_key]).to eq(full_context[unexpected_key]) end - else - expect(security_context).to eq(expectedContext) end end end diff --git a/spec/helm_template_helper.rb b/spec/helm_template_helper.rb index 352b5e6363..b4c773f546 100644 --- a/spec/helm_template_helper.rb +++ b/spec/helm_template_helper.rb @@ -10,6 +10,11 @@ class HelmTemplate parts = `helm version -c`.match('Ver(sion)?:"v(\d)\.(\d+)\.') @_helm_major_version = parts[2].to_i @_helm_minor_version = parts[3].to_i + + # Check for Helm version below minimum supported version + if @_helm_major_version == 3 and @_helm_minor_version < 3 + raise RuntimeError("Helm version needs to be greater than 3.3.1") + end end @_helm_major_version -- GitLab From c86228722e151c17c3e288d7f1f35ca00c47bda6 Mon Sep 17 00:00:00 2001 From: Gerard Hickey Date: Wed, 20 Apr 2022 15:33:38 -0700 Subject: [PATCH 06/10] Exit RSpec testing when using unsupported Helm Could not get `rspec` to abort out of a test suite when an unsupported version of `helm` was used and an exception was raised. So instead failure message is printed and exit is called to terminate further processing of the test suite. Signed-off-by: Gerard Hickey --- spec/helm_template_helper.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/helm_template_helper.rb b/spec/helm_template_helper.rb index b4c773f546..46010a84de 100644 --- a/spec/helm_template_helper.rb +++ b/spec/helm_template_helper.rb @@ -12,8 +12,9 @@ class HelmTemplate @_helm_minor_version = parts[3].to_i # Check for Helm version below minimum supported version - if @_helm_major_version == 3 and @_helm_minor_version < 3 - raise RuntimeError("Helm version needs to be greater than 3.3.1") + if @_helm_major_version == 3 && @_helm_minor_version < 3 + puts "ERROR: Helm version needs to be greater than 3.3.1" + exit(1) end end -- GitLab From a7206a4f7ecd26e8be7a118b656afaa4ee9b21be Mon Sep 17 00:00:00 2001 From: Gerard Hickey Date: Wed, 20 Apr 2022 16:23:55 -0700 Subject: [PATCH 07/10] Removed comment for dropping support for Helm 3.1.x --- spec/configuration/gitaly_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/configuration/gitaly_spec.rb b/spec/configuration/gitaly_spec.rb index 2df84f47c6..5120129f59 100644 --- a/spec/configuration/gitaly_spec.rb +++ b/spec/configuration/gitaly_spec.rb @@ -142,8 +142,6 @@ describe 'Gitaly configuration' do gitaly_set = t.resources_by_kind('StatefulSet').select { |key| key == gitaly_stateful_set } security_context = gitaly_set[gitaly_stateful_set]['spec']['template']['spec']['securityContext'] - # This if statement can be simplified when testing support is - # dropped for Helm 3.1.x if HelmTemplate.helm_major_version == 3 && HelmTemplate.helm_minor_version > 1 # Helm 3.2+ renders the full security context. So we check given # the expected context from the table above and then check the -- GitLab From 7ed22747e362c2de41cb9a593c44f2749066a760 Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Fri, 22 Apr 2022 21:09:58 +0000 Subject: [PATCH 08/10] Catch when major version is less than supported minimum. --- spec/helm_template_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/helm_template_helper.rb b/spec/helm_template_helper.rb index 46010a84de..51b95ae29f 100644 --- a/spec/helm_template_helper.rb +++ b/spec/helm_template_helper.rb @@ -12,7 +12,7 @@ class HelmTemplate @_helm_minor_version = parts[3].to_i # Check for Helm version below minimum supported version - if @_helm_major_version == 3 && @_helm_minor_version < 3 + if @_helm_major_version < 3 || (@_helm_major_version == 3 && @_helm_minor_version < 3) puts "ERROR: Helm version needs to be greater than 3.3.1" exit(1) end -- GitLab From 41873a947135bbdcf787143db23701898f56d2e2 Mon Sep 17 00:00:00 2001 From: Gerard Hickey Date: Tue, 26 Apr 2022 11:53:04 -0700 Subject: [PATCH 09/10] Removed unneeded conditional --- spec/configuration/gitaly_spec.rb | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/spec/configuration/gitaly_spec.rb b/spec/configuration/gitaly_spec.rb index 5120129f59..5d8f4fea02 100644 --- a/spec/configuration/gitaly_spec.rb +++ b/spec/configuration/gitaly_spec.rb @@ -142,19 +142,17 @@ describe 'Gitaly configuration' do gitaly_set = t.resources_by_kind('StatefulSet').select { |key| key == gitaly_stateful_set } security_context = gitaly_set[gitaly_stateful_set]['spec']['template']['spec']['securityContext'] - if HelmTemplate.helm_major_version == 3 && HelmTemplate.helm_minor_version > 1 - # Helm 3.2+ renders the full security context. So we check given - # the expected context from the table above and then check the - # additional attributes that are not specified in the table above. - full_context = { "runAsUser" => 1000, "fsGroup" => 1000 } - expectedContext&.each_key do |expected_key| - expect(security_context[expected_key]).to eq(expectedContext[expected_key]) - full_context.delete(expected_key) - end - - full_context.each_key do |unexpected_key| - expect(security_context[unexpected_key]).to eq(full_context[unexpected_key]) - end + # Helm 3.2+ renders the full security context. So we check given + # the expected context from the table above and then check the + # additional attributes that are not specified in the table above. + full_context = { "runAsUser" => 1000, "fsGroup" => 1000 } + expectedContext&.each_key do |expected_key| + expect(security_context[expected_key]).to eq(expectedContext[expected_key]) + full_context.delete(expected_key) + end + + full_context.each_key do |unexpected_key| + expect(security_context[unexpected_key]).to eq(full_context[unexpected_key]) end end end -- GitLab From b7f5514dd60e30026268d6de8aabdc85a795a2da Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Tue, 26 Apr 2022 21:30:27 +0000 Subject: [PATCH 10/10] Apply 1 suggestion(s) to 1 file(s) --- spec/helm_template_helper.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/helm_template_helper.rb b/spec/helm_template_helper.rb index 51b95ae29f..56a0aa10b8 100644 --- a/spec/helm_template_helper.rb +++ b/spec/helm_template_helper.rb @@ -29,8 +29,6 @@ class HelmTemplate namespace_arg = namespace.nil? ? '' : "--namespace #{namespace}" case helm_major_version - when 2 then - "helm template -n #{release_name} -f #{path} #{namespace_arg} #{extra_args} ." when 3 then "helm template #{release_name} . -f #{path} #{namespace_arg} #{extra_args}" else -- GitLab