Commit 96a7e162 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Refactor context variables in pipeline model class

parent 326dc7da
......@@ -31,8 +31,6 @@ module Ci
has_many :auto_canceled_jobs, class_name: 'CommitStatus', foreign_key: 'auto_canceled_by_id'
delegate :id, to: :project, prefix: true
delegate :deployment_variables, to: :project, prefix: true
delegate :secret_variables_for, to: :project, prefix: true
validates :source, exclusion: { in: %w(unknown), unless: :importing? }, on: :create
validates :sha, presence: { unless: :importing? }
......@@ -306,13 +304,19 @@ module Ci
@stage_seeds ||= config_processor.stage_seeds(self)
end
def variables
project_secret_variables_for(ref: ref).map(&:to_runner_variable) +
project_deployment_variables
def context_variables
@context_variables ||= project.secret_variables_for(ref: ref).to_a
.map(&:to_runner_variable) + project.deployment_variables.to_a
end
def has_kubernetes_available?
(variables.map { |v| v.fetch(:key) } & %w[KUBECONFIG KUBE_DOMAIN]).many?
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
def has_stage_seeds?
......
......@@ -27,14 +27,6 @@ describe Ci::Pipeline, :mailer do
it { is_expected.to respond_to :git_author_email }
it { is_expected.to respond_to :short_sha }
describe '#project_deployment_variables' do
it 'delegates deployment variables to project' do
expect(pipeline)
.to delegate_method(:deployment_variables)
.to(:project).with_prefix
end
end
describe '#source' do
context 'when creating new pipeline' do
let(:pipeline) do
......@@ -551,9 +543,9 @@ describe Ci::Pipeline, :mailer do
project: project)
end
describe '#variables' do
describe '#context_variables' do
it 'returns kubernetes-related variables' do
variables = pipeline.variables.map { |v| v.fetch(:key) }
variables = pipeline.context_variables.map { |v| v.fetch(:key) }
expect(variables).to include 'KUBECONFIG', 'KUBE_DOMAIN'
end
......@@ -567,9 +559,9 @@ describe Ci::Pipeline, :mailer do
end
context 'when kubernetes is not configured' do
describe '#variables' do
describe '#context_variables' do
it 'does not return kubernetes related variables' do
variables = pipeline.variables.map { |v| v.fetch(:key) }
variables = pipeline.context_variables.map { |v| v.fetch(:key) }
expect(variables).not_to include 'KUBECONFIG', 'KUBE_DOMAIN'
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