Commit 080a359e authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'fix/sm/34762-bad-validation-message' into 'master'

Enforce namespace of Kubernetes to lowercase

Closes #34762

See merge request !13732
parents d3005c98 38cb3293
...@@ -24,6 +24,8 @@ class KubernetesService < DeploymentService ...@@ -24,6 +24,8 @@ class KubernetesService < DeploymentService
validates :token validates :token
end end
before_validation :enforce_namespace_to_lower_case
validates :namespace, validates :namespace,
allow_blank: true, allow_blank: true,
length: 1..63, length: 1..63,
...@@ -207,4 +209,8 @@ class KubernetesService < DeploymentService ...@@ -207,4 +209,8 @@ class KubernetesService < DeploymentService
max_session_time: current_application_settings.terminal_max_session_time max_session_time: current_application_settings.terminal_max_session_time
} }
end end
def enforce_namespace_to_lower_case
self.namespace = self.namespace&.downcase
end
end end
...@@ -53,7 +53,8 @@ module Gitlab ...@@ -53,7 +53,8 @@ module Gitlab
end end
def kubernetes_namespace_regex_message def kubernetes_namespace_regex_message
"can contain only letters, digits or '-', and cannot start or end with '-'" "can contain only lowercase letters, digits, and '-'. " \
"Must start with a letter, and cannot end with '-'"
end end
def environment_slug_regex def environment_slug_regex
......
...@@ -38,7 +38,8 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do ...@@ -38,7 +38,8 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
'a' * 63 => true, 'a' * 63 => true,
'a' * 64 => false, 'a' * 64 => false,
'a.b' => false, 'a.b' => false,
'a*b' => false 'a*b' => false,
'FOO' => true
}.each do |namespace, validity| }.each do |namespace, validity|
it "validates #{namespace} as #{validity ? 'valid' : 'invalid'}" do it "validates #{namespace} as #{validity ? 'valid' : 'invalid'}" do
subject.namespace = namespace subject.namespace = namespace
......
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