diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-08-31 14:56:25 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-08-31 14:56:25 +0200 |
commit | ef030709ebffdecdce67f2693d8c54669edfb7a7 (patch) | |
tree | c1115d74b7aa6c56150e97e05360d1c71e7ac3dc | |
parent | 92673c2c63c5928279fdb1985357fa8596c97397 (diff) | |
download | gitlab-ce-ef030709ebffdecdce67f2693d8c54669edfb7a7.tar.gz |
Change kubernetes job policy allowed values
It is now possible to use `kubernetes: configured`.
-rw-r--r-- | lib/ci/gitlab_ci_yaml_processor.rb | 5 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/policy.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/validators.rb | 8 | ||||
-rw-r--r-- | spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/policy_spec.rb | 44 |
5 files changed, 56 insertions, 5 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb index 5676618f7fd..434b8948f41 100644 --- a/lib/ci/gitlab_ci_yaml_processor.rb +++ b/lib/ci/gitlab_ci_yaml_processor.rb @@ -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) diff --git a/lib/gitlab/ci/config/entry/policy.rb b/lib/gitlab/ci/config/entry/policy.rb index a8bba3d3ea4..922d568f0ab 100644 --- a/lib/gitlab/ci/config/entry/policy.rb +++ b/lib/gitlab/ci/config/entry/policy.rb @@ -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 diff --git a/lib/gitlab/ci/config/entry/validators.rb b/lib/gitlab/ci/config/entry/validators.rb index b2ca3c881e4..0159179f0a9 100644 --- a/lib/gitlab/ci/config/entry/validators.rb +++ b/lib/gitlab/ci/config/entry/validators.rb @@ -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 diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index dbe30807595..e8908ebec8d 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -172,7 +172,7 @@ module Ci YAML.dump( spinach: { stage: 'test', script: 'spinach' }, production: { stage: 'deploy', script: 'cap', only: { - kubernetes: true } } + kubernetes: 'configured' } } ) end diff --git a/spec/lib/gitlab/ci/config/entry/policy_spec.rb b/spec/lib/gitlab/ci/config/entry/policy_spec.rb index ab69a2e8bcc..a5c2e3f1989 100644 --- a/spec/lib/gitlab/ci/config/entry/policy_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/policy_spec.rb @@ -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' } |