Commit 9c140b7d authored by Thong Kuah's avatar Thong Kuah

DRY up refresh service

The two pieces of code are identical so use a private method
parent 885ea5c3
...@@ -7,12 +7,7 @@ module Clusters ...@@ -7,12 +7,7 @@ module Clusters
# Create all namespaces that are missing for each project # Create all namespaces that are missing for each project
cluster.all_projects.missing_kubernetes_namespace(cluster_namespaces).each do |project| cluster.all_projects.missing_kubernetes_namespace(cluster_namespaces).each do |project|
kubernetes_namespace = cluster.find_or_initialize_kubernetes_namespace_for_project(project) create_or_update_namespace(cluster, project)
::Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService.new(
cluster: cluster,
kubernetes_namespace: kubernetes_namespace
).execute
end end
end end
...@@ -21,6 +16,13 @@ module Clusters ...@@ -21,6 +16,13 @@ module Clusters
# Create all namespaces that are missing for each cluster # Create all namespaces that are missing for each cluster
project.all_clusters.missing_kubernetes_namespace(project_namespaces).each do |cluster| project.all_clusters.missing_kubernetes_namespace(project_namespaces).each do |cluster|
create_or_update_namespace(cluster, project)
end
end
private
def create_or_update_namespace(cluster, project)
kubernetes_namespace = cluster.find_or_initialize_kubernetes_namespace_for_project(project) kubernetes_namespace = cluster.find_or_initialize_kubernetes_namespace_for_project(project)
::Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService.new( ::Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService.new(
...@@ -29,5 +31,4 @@ module Clusters ...@@ -29,5 +31,4 @@ module Clusters
).execute ).execute
end end
end end
end
end end
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