summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTiger <twatson@gitlab.com>2019-03-18 13:02:39 +1100
committerTiger <twatson@gitlab.com>2019-03-20 12:04:46 +1100
commit325d504c3c9697c73130aef67e8b32c99544b453 (patch)
tree026504e8dbcd2218447bc78c07903167f1a05e33 /lib
parent89b0bc04b9927abc85ce5fc3735438f956a8d5a2 (diff)
downloadgitlab-ce-325d504c3c9697c73130aef67e8b32c99544b453.tar.gz
Don't recreate Kubernetes namespaces if they exist
Instead of attempting to create or update a Kubernetes namespace on every deploy, only do so when we know it doesn't exist yet.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/ci/build/prerequisite/base.rb2
-rw-r--r--lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb14
2 files changed, 9 insertions, 7 deletions
diff --git a/lib/gitlab/ci/build/prerequisite/base.rb b/lib/gitlab/ci/build/prerequisite/base.rb
index d3c37a3e02e..156aa22d95b 100644
--- a/lib/gitlab/ci/build/prerequisite/base.rb
+++ b/lib/gitlab/ci/build/prerequisite/base.rb
@@ -5,6 +5,8 @@ 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 3d66b13caa6..41135ae62bb 100644
--- a/lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb
+++ b/lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb
@@ -5,12 +5,8 @@ module Gitlab
module Build
module Prerequisite
class KubernetesNamespace < Base
- ##
- # Cluster settings may have changed since the last deploy,
- # so we must always ensure the namespace is up to date.
- #
def unmet?
- deployment_cluster.present?
+ deployment_cluster.present? && kubernetes_namespace.new_record?
end
def complete!
@@ -25,9 +21,13 @@ module Gitlab
build.deployment&.cluster
end
- def create_or_update_namespace
- kubernetes_namespace = deployment_cluster.find_or_initialize_kubernetes_namespace_for_project(build.project)
+ def kubernetes_namespace
+ strong_memoize(:kubernetes_namespace) do
+ deployment_cluster.find_or_initialize_kubernetes_namespace_for_project(build.project)
+ end
+ end
+ def create_or_update_namespace
Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService.new(
cluster: deployment_cluster,
kubernetes_namespace: kubernetes_namespace