Commit 44c9bf36 authored by Tiger's avatar Tiger

Use nullify_if_blank for cluster_platforms_kubernetes.namespace

parent 5e149b3d
......@@ -7,6 +7,7 @@ module Clusters
include EnumWithNil
include AfterCommitQueue
include ReactiveCaching
include NullifyIfBlank
RESERVED_NAMESPACES = %w(gitlab-managed-apps).freeze
......@@ -25,7 +26,6 @@ module Clusters
key: Settings.attr_encrypted_db_key_base_truncated,
algorithm: 'aes-256-cbc'
before_validation :nullify_blank_namespace
before_validation :enforce_namespace_to_lower_case
before_validation :enforce_ca_whitespace_trimming
......@@ -64,6 +64,8 @@ module Clusters
default_value_for :authorization_type, :rbac
nullify_if_blank :namespace
def predefined_variables(project:, environment_name:, kubernetes_namespace: nil)
Gitlab::Ci::Variables::Collection.new.tap do |variables|
variables.append(key: 'KUBE_URL', value: api_url)
......@@ -255,10 +257,6 @@ module Clusters
true
end
def nullify_blank_namespace
self.namespace = nil if namespace.blank?
end
def extract_relevant_pod_data(pods)
pods.map do |pod|
{
......
......@@ -17,6 +17,8 @@ RSpec.describe Clusters::Platforms::Kubernetes do
it { is_expected.to delegate_method(:enabled?).to(:cluster) }
it { is_expected.to delegate_method(:provided_by_user?).to(:cluster) }
it { is_expected.to nullify_if_blank(:namespace) }
it_behaves_like 'having unique enum values'
describe 'before_validation' do
......@@ -29,14 +31,6 @@ RSpec.describe Clusters::Platforms::Kubernetes do
expect(kubernetes.namespace).to eq('abc')
end
end
context 'when namespace is blank' do
let(:namespace) { '' }
it 'nullifies the namespace' do
expect(kubernetes.namespace).to be_nil
end
end
end
describe 'validation' do
......
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