Commit 73d0cafb authored by Grzegorz Bizon's avatar Grzegorz Bizon

Check if service active when using CI/CD kubernetes policy

parent dc4d9386
...@@ -304,19 +304,8 @@ module Ci ...@@ -304,19 +304,8 @@ module Ci
@stage_seeds ||= config_processor.stage_seeds(self) @stage_seeds ||= config_processor.stage_seeds(self)
end end
def context_variables def has_kubernetes_active?
@context_variables ||= project.secret_variables_for(ref: ref).to_a project.kubernetes_service&.active?
.map(&:to_runner_variable) + project.deployment_variables.to_a
end
def has_kubernetes_available?
kubernetes_variables = context_variables.select do |variable|
variable.fetch(:key).in?(%w[KUBECONFIG KUBE_DOMAIN])
end
return false if kubernetes_variables.empty?
kubernetes_variables.map { |var| var.fetch(:value).present? }.all?
end end
def has_stage_seeds? def has_stage_seeds?
......
...@@ -89,7 +89,7 @@ module Ci ...@@ -89,7 +89,7 @@ module Ci
builds.select do |build| builds.select do |build|
job = @jobs[build.fetch(:name).to_sym] job = @jobs[build.fetch(:name).to_sym]
has_kubernetes = pipeline.has_kubernetes_available? has_kubernetes = pipeline.has_kubernetes_active?
only_kubernetes = job.dig(:only, :kubernetes) only_kubernetes = job.dig(:only, :kubernetes)
except_kubernetes = job.dig(:except, :kubernetes) except_kubernetes = job.dig(:except, :kubernetes)
......
...@@ -546,42 +546,18 @@ describe Ci::Pipeline, :mailer do ...@@ -546,42 +546,18 @@ describe Ci::Pipeline, :mailer do
end end
end end
context 'when kubernetes is configured' do describe '#has_kubernetes_active?' do
let(:project) { create(:kubernetes_project) } context 'when kubernetes is configured' do
let(:project) { create(:kubernetes_project) }
before do
create(:ci_variable, key: 'KUBE_DOMAIN',
protected: false,
project: project)
end
describe '#context_variables' do
it 'returns kubernetes-related variables' do
variables = pipeline.context_variables.map { |v| v.fetch(:key) }
expect(variables).to include 'KUBECONFIG', 'KUBE_DOMAIN'
end
end
describe '#has_kubernetes_available?' do
it 'returns true' do it 'returns true' do
expect(pipeline).to have_kubernetes_available expect(pipeline).to have_kubernetes_active
end
end
end
context 'when kubernetes is not configured' do
describe '#context_variables' do
it 'does not return kubernetes related variables' do
variables = pipeline.context_variables.map { |v| v.fetch(:key) }
expect(variables).not_to include 'KUBECONFIG', 'KUBE_DOMAIN'
end end
end end
describe '#has_kubernetes_available?' do context 'when kubernetes is not configured' do
it 'returns false' do it 'returns false' do
expect(pipeline).not_to have_kubernetes_available expect(pipeline).not_to have_kubernetes_active
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment