Change kubernetes job policy allowed values
It is now possible to use `kubernetes: configured`.
This commit is contained in:
parent
92673c2c63
commit
ef030709eb
|
|
@ -94,12 +94,11 @@ module Ci
|
|||
except_kubernetes = job.dig(:except, :kubernetes)
|
||||
|
||||
[!only_kubernetes && !except_kubernetes,
|
||||
only_kubernetes && has_kubernetes,
|
||||
except_kubernetes && !has_kubernetes].any?
|
||||
only_kubernetes && has_kubernetes,
|
||||
except_kubernetes && !has_kubernetes].any?
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def jobs_for_ref(ref, tag = false, source = nil)
|
||||
@jobs.select do |_, job|
|
||||
process?(job.dig(:only, :refs), job.dig(:except, :refs), ref, tag, source)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ module Gitlab
|
|||
|
||||
with_options allow_nil: true do
|
||||
validates :refs, array_of_strings_or_regexps: true
|
||||
validates :kubernetes, inclusion: { in: [true] }
|
||||
validates :kubernetes, allowed_values: %w[configured]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -14,6 +14,14 @@ module Gitlab
|
|||
end
|
||||
end
|
||||
|
||||
class AllowedValuesValidator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
unless options[:in].include?(value.to_s)
|
||||
record.errors.add(attribute, "unknown value: #{value}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ArrayOfStringsValidator < ActiveModel::EachValidator
|
||||
include LegacyValidationHelpers
|
||||
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ module Ci
|
|||
YAML.dump(
|
||||
spinach: { stage: 'test', script: 'spinach' },
|
||||
production: { stage: 'deploy', script: 'cap', only: {
|
||||
kubernetes: true } }
|
||||
kubernetes: 'configured' } }
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -56,6 +56,50 @@ describe Gitlab::Ci::Config::Entry::Policy do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when using complex policy' do
|
||||
context 'when specifiying refs policy' do
|
||||
let(:config) { { refs: ['master'] } }
|
||||
|
||||
it 'is a correct configuraton' do
|
||||
expect(entry).to be_valid
|
||||
expect(entry.value).to eq(refs: %w[master])
|
||||
end
|
||||
end
|
||||
|
||||
context 'when specifying kubernetes policy' do
|
||||
let(:config) { { kubernetes: 'configured' } }
|
||||
|
||||
it 'is a correct configuraton' do
|
||||
expect(entry).to be_valid
|
||||
expect(entry.value).to eq(kubernetes: 'configured')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when specifying invalid kubernetes policy' do
|
||||
let(:config) { { kubernetes: 'active' } }
|
||||
|
||||
it 'reports an error about invalid policy' do
|
||||
expect(entry.errors).to include /unknown value: active/
|
||||
end
|
||||
end
|
||||
|
||||
context 'when specifying unknown policy' do
|
||||
let(:config) { { refs: ['master'], invalid: :something } }
|
||||
|
||||
it 'returns error about invalid key' do
|
||||
expect(entry.errors).to include /unknown keys: invalid/
|
||||
end
|
||||
end
|
||||
|
||||
context 'when policy is empty' do
|
||||
let(:config) { {} }
|
||||
|
||||
it 'is not a valid configuration' do
|
||||
expect(entry.errors).to include /can't be blank/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when policy strategy does not match' do
|
||||
let(:config) { 'string strategy' }
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue