diff options
author | Thong Kuah <tkuah@gitlab.com> | 2018-11-06 21:55:10 +1300 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2018-11-08 23:28:30 +1300 |
commit | 5a042ef2fbe1bd57b9428c89b49d2fa1e248ad46 (patch) | |
tree | 15130ca3700f2da12044087510128a715758d6e0 /app/models | |
parent | 530371840288af4bc54bc2c32c602e568ce20854 (diff) | |
download | gitlab-ce-5a042ef2fbe1bd57b9428c89b49d2fa1e248ad46.tar.gz |
Only project clusters has Project Namespace field
Group clusters should not allow Project Namespace so don't show that
field input too
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/clusters/cluster.rb | 2 | ||||
-rw-r--r-- | app/models/clusters/platforms/kubernetes.rb | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/app/models/clusters/cluster.rb b/app/models/clusters/cluster.rb index 48d6c0daa0f..4369d09a89c 100644 --- a/app/models/clusters/cluster.rb +++ b/app/models/clusters/cluster.rb @@ -29,7 +29,7 @@ module Clusters # we force autosave to happen when we save `Cluster` model has_one :provider_gcp, class_name: 'Clusters::Providers::Gcp', autosave: true - has_one :platform_kubernetes, class_name: 'Clusters::Platforms::Kubernetes', autosave: true + has_one :platform_kubernetes, class_name: 'Clusters::Platforms::Kubernetes', inverse_of: :cluster, autosave: true has_one :application_helm, class_name: 'Clusters::Applications::Helm' has_one :application_ingress, class_name: 'Clusters::Applications::Ingress' diff --git a/app/models/clusters/platforms/kubernetes.rb b/app/models/clusters/platforms/kubernetes.rb index a0933958b50..a90a5395749 100644 --- a/app/models/clusters/platforms/kubernetes.rb +++ b/app/models/clusters/platforms/kubernetes.rb @@ -38,6 +38,8 @@ module Clusters validates :namespace, exclusion: { in: RESERVED_NAMESPACES } + validate :no_namespace, unless: :project_type? + # We expect to be `active?` only when enabled and cluster is created (the api_url is assigned) validates :api_url, url: true, presence: true validates :token, presence: true @@ -52,6 +54,7 @@ module Clusters delegate :project, to: :cluster, allow_nil: true delegate :enabled?, to: :cluster, allow_nil: true delegate :managed?, to: :cluster, allow_nil: true + delegate :project_type?, to: :cluster, allow_nil: true delegate :kubernetes_namespace, to: :cluster alias_method :active?, :enabled? @@ -207,6 +210,12 @@ module Clusters self.token = self.token&.strip end + def no_namespace + if namespace + errors.add(:namespace, 'only allowed for project cluster') + end + end + def prevent_modification return unless managed? |