diff options
author | Shinya Maeda <shinya@gitlab.com> | 2017-11-02 23:19:11 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2017-11-02 23:19:11 +0900 |
commit | b129f06733c7994fb81cef4d0bae6d6611647a83 (patch) | |
tree | 7dc99e8583a50502218ef0f9ad0bd3f4fa305f91 /app/models/clusters | |
parent | 438591436842b34689ea2eea32c90ee8c379f391 (diff) | |
download | gitlab-ce-b129f06733c7994fb81cef4d0bae6d6611647a83.tar.gz |
Fix out of sync with KubernetesService. Remove namespace pramas from controller. Use time_with_zone in schema. Remove Gcp::Clusters from safe_model_attributes.ym
Diffstat (limited to 'app/models/clusters')
-rw-r--r-- | app/models/clusters/cluster.rb | 6 | ||||
-rw-r--r-- | app/models/clusters/platforms/kubernetes.rb | 37 |
2 files changed, 22 insertions, 21 deletions
diff --git a/app/models/clusters/cluster.rb b/app/models/clusters/cluster.rb index ca09b939f34..955dba51745 100644 --- a/app/models/clusters/cluster.rb +++ b/app/models/clusters/cluster.rb @@ -21,10 +21,16 @@ module Clusters validates :name, cluster_name: true validate :restrict_modification, on: :update + # TODO: Move back this into Clusters::Platforms::Kubernetes in 10.3 + # We need callback here because `enabled` belongs to Clusters::Cluster + # Callbacks in Clusters::Platforms::Kubernetes will not be called after update + after_save :update_kubernetes_integration! + delegate :status, to: :provider, allow_nil: true delegate :status_reason, to: :provider, allow_nil: true delegate :status_name, to: :provider, allow_nil: true delegate :on_creation?, to: :provider, allow_nil: true + delegate :update_kubernetes_integration!, to: :platform, allow_nil: true enum platform_type: { kubernetes: 1 diff --git a/app/models/clusters/platforms/kubernetes.rb b/app/models/clusters/platforms/kubernetes.rb index 3ad2ffe531d..8b00f1dac0b 100644 --- a/app/models/clusters/platforms/kubernetes.rb +++ b/app/models/clusters/platforms/kubernetes.rb @@ -1,8 +1,6 @@ module Clusters module Platforms class Kubernetes < ActiveRecord::Base - include Gitlab::CurrentSettings - self.table_name = 'cluster_platforms_kubernetes' belongs_to :cluster, inverse_of: :platform_kubernetes, class_name: 'Clusters::Cluster' @@ -28,13 +26,10 @@ module Clusters } # We expect to be `active?` only when enabled and cluster is created (the api_url is assigned) - with_options presence: true, if: :enabled? do - validates :api_url, url: true, presence: true - validates :token, presence: true - end + validates :api_url, url: true, presence: true + validates :token, presence: true # TODO: Glue code till we migrate Kubernetes Integration into Platforms::Kubernetes - after_save :update_kubernetes_integration! after_destroy :destroy_kubernetes_integration! alias_attribute :ca_pem, :ca_cert @@ -60,6 +55,18 @@ module Clusters self.class.namespace_for_project(project) if project end + def update_kubernetes_integration! + raise 'Kubernetes service already configured' unless manages_kubernetes_service? + + ensure_kubernetes_service.update!( + active: enabled?, + api_url: api_url, + namespace: namespace, + token: token, + ca_pem: ca_cert + ) + end + private def enforce_namespace_to_lower_case @@ -79,24 +86,12 @@ module Clusters kubernetes_service.destroy! end - def update_kubernetes_integration! - return raise 'Kubernetes service already configured' unless manages_kubernetes_service? - - ensure_kubernetes_service.update!( - active: enabled?, - api_url: api_url, - namespace: namespace, - token: token, - ca_pem: ca_cert, - ) - end - def kubernetes_service - @kubernetes_service ||= project.kubernetes_service || project.build_kubernetes_service + @kubernetes_service ||= project&.kubernetes_service end def ensure_kubernetes_service - @kubernetes_service ||= kubernetes_service || project.build_kubernetes_service + @kubernetes_service ||= kubernetes_service || project&.build_kubernetes_service end end end |