Skip to content
Snippets Groups Projects
Commit b341c4b0 authored by Hordur Freyr Yngvason's avatar Hordur Freyr Yngvason Committed by Mayra Cabrera
Browse files

Move kubernetes_variables to scoped_variables

parent 876909a2
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -539,7 +539,6 @@ def variables
.concat(persisted_variables)
.concat(dependency_proxy_variables)
.concat(job_jwt_variables)
.concat(kubernetes_variables)
.concat(scoped_variables)
.concat(job_variables)
.concat(persisted_environment_variables)
Loading
Loading
@@ -1161,22 +1160,6 @@ def job_jwt_variables
end
end
 
def kubernetes_variables
::Gitlab::Ci::Variables::Collection.new.tap do |collection|
# A cluster deployemnt may also define a KUBECONFIG variable, so to keep existing
# configurations working we shouldn't overwrite it here.
# This check will be removed when Cluster and Agent configurations are
# merged in https://gitlab.com/gitlab-org/gitlab/-/issues/335089
break collection if deployment&.deployment_cluster
template = ::Ci::GenerateKubeconfigService.new(self).execute # rubocop: disable CodeReuse/ServiceClass
if template.valid?
collection.append(key: 'KUBECONFIG', value: template.to_yaml, public: false, file: true)
end
end
end
def conditionally_allow_failure!(exit_code)
return unless exit_code
 
Loading
Loading
Loading
Loading
@@ -17,6 +17,7 @@ def scoped_variables(environment: expanded_environment_name, dependencies: true)
variables.concat(project.predefined_variables)
variables.concat(pipeline.predefined_variables)
variables.concat(runner.predefined_variables) if runnable? && runner
variables.concat(kubernetes_variables)
variables.concat(deployment_variables(environment: environment))
variables.concat(yaml_variables)
variables.concat(user_variables)
Loading
Loading
@@ -88,6 +89,18 @@ def predefined_variables
end
end
 
def kubernetes_variables
::Gitlab::Ci::Variables::Collection.new.tap do |collection|
# Should get merged with the cluster kubeconfig in deployment_variables, see
# https://gitlab.com/gitlab-org/gitlab/-/issues/335089
template = ::Ci::GenerateKubeconfigService.new(self).execute
if template.valid?
collection.append(key: 'KUBECONFIG', value: template.to_yaml, public: false, file: true)
end
end
end
def deployment_variables(environment:)
return [] unless environment
 
Loading
Loading
Loading
Loading
@@ -3398,31 +3398,6 @@
 
it { is_expected.to include(key: job_variable.key, value: job_variable.value, public: false, masked: false) }
end
describe 'kubernetes variables' do
let(:service) { double(execute: template) }
let(:template) { double(to_yaml: 'example-kubeconfig', valid?: template_valid) }
let(:template_valid) { true }
before do
allow(Ci::GenerateKubeconfigService).to receive(:new).with(build).and_return(service)
end
it { is_expected.to include(key: 'KUBECONFIG', value: 'example-kubeconfig', public: false, file: true) }
context 'job is deploying to a cluster' do
let(:deployment) { create(:deployment, deployment_cluster: create(:deployment_cluster)) }
let(:build) { create(:ci_build, pipeline: pipeline, deployment: deployment) }
it { is_expected.not_to include(key: 'KUBECONFIG', value: 'example-kubeconfig', public: false, file: true) }
end
context 'generated config is invalid' do
let(:template_valid) { false }
it { is_expected.not_to include(key: 'KUBECONFIG', value: 'example-kubeconfig', public: false, file: true) }
end
end
end
 
describe '#scoped_variables' do
Loading
Loading
@@ -3631,6 +3606,27 @@
include_examples "secret CI variables"
end
 
describe '#kubernetes_variables' do
let(:build) { create(:ci_build) }
let(:service) { double(execute: template) }
let(:template) { double(to_yaml: 'example-kubeconfig', valid?: template_valid) }
let(:template_valid) { true }
subject { build.kubernetes_variables }
before do
allow(Ci::GenerateKubeconfigService).to receive(:new).with(build).and_return(service)
end
it { is_expected.to include(key: 'KUBECONFIG', value: 'example-kubeconfig', public: false, file: true) }
context 'generated config is invalid' do
let(:template_valid) { false }
it { is_expected.not_to include(key: 'KUBECONFIG', value: 'example-kubeconfig', public: false, file: true) }
end
end
describe '#deployment_variables' do
let(:build) { create(:ci_build, environment: environment) }
let(:environment) { 'production' }
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment