diff options
author | Tiger <twatson@gitlab.com> | 2019-03-13 14:06:54 +1100 |
---|---|---|
committer | Tiger <twatson@gitlab.com> | 2019-03-20 12:04:46 +1100 |
commit | 89b0bc04b9927abc85ce5fc3735438f956a8d5a2 (patch) | |
tree | 29355d49ce1a784b4695b4897880c6fe2879d353 /lib | |
parent | 759dab5b69f53a861045ebbc84836f83c7502af2 (diff) | |
download | gitlab-ce-89b0bc04b9927abc85ce5fc3735438f956a8d5a2.tar.gz |
Create one Kubernetes namespace for a deployment
Instead of creating a Kubernetes namespace on every
cluster related to a project, only create one on the
cluster the project is about to be deployed to.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ci/build/prerequisite/base.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb | 22 |
2 files changed, 7 insertions, 17 deletions
diff --git a/lib/gitlab/ci/build/prerequisite/base.rb b/lib/gitlab/ci/build/prerequisite/base.rb index 156aa22d95b..d3c37a3e02e 100644 --- a/lib/gitlab/ci/build/prerequisite/base.rb +++ b/lib/gitlab/ci/build/prerequisite/base.rb @@ -5,8 +5,6 @@ module Gitlab module Build module Prerequisite class Base - include Utils::StrongMemoize - attr_reader :build def initialize(build) diff --git a/lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb b/lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb index d1b59d0a64c..3d66b13caa6 100644 --- a/lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb +++ b/lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb @@ -10,37 +10,29 @@ module Gitlab # so we must always ensure the namespace is up to date. # def unmet? - build.has_deployment? && clusters_missing_namespaces.present? + deployment_cluster.present? end def complete! return unless unmet? - clusters_missing_namespaces.each do |cluster| - create_or_update_namespace(cluster) - end + create_or_update_namespace end private - def project - build.project + def deployment_cluster + build.deployment&.cluster end - def create_or_update_namespace(cluster) - kubernetes_namespace = cluster.find_or_initialize_kubernetes_namespace_for_project(project) + def create_or_update_namespace + kubernetes_namespace = deployment_cluster.find_or_initialize_kubernetes_namespace_for_project(build.project) Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService.new( - cluster: cluster, + cluster: deployment_cluster, kubernetes_namespace: kubernetes_namespace ).execute end - - def clusters_missing_namespaces - strong_memoize(:clusters_missing_namespaces) do - project.all_clusters.missing_kubernetes_namespace(project.kubernetes_namespaces).to_a - end - end end end end |