Commit ef030709 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Change kubernetes job policy allowed values

It is now possible to use `kubernetes: configured`.
parent 92673c2c
......@@ -99,7 +99,6 @@ module Ci
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' }
......
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