summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoão Cunha <j.a.cunha@gmail.com>2019-03-28 14:05:45 +0000
committerJoão Cunha <j.a.cunha@gmail.com>2019-03-28 14:05:45 +0000
commitc433e8bc4d48fe079680ea45d657c936723551da (patch)
tree43a08cc1e6f3b4257660fbb18422fc131ca91463
parent04496085c1b83ccf5d9bfa546daf2a92e9c644e7 (diff)
downloadgitlab-ce-refactor/services_list_of_apps_responsibility.tar.gz
Dry up and remove responsibilitiesrefactor/services_list_of_apps_responsibility
- Dry create_service.rb and update_service.rb duplicated code - Remove known list of applications responsibility from services - Refactor the complex builders->builder call from base_service.rb
-rw-r--r--app/models/clusters/cluster.rb12
-rw-r--r--app/services/clusters/applications/base_service.rb24
-rw-r--r--app/services/clusters/applications/create_service.rb22
-rw-r--r--app/services/clusters/applications/update_service.rb21
4 files changed, 32 insertions, 47 deletions
diff --git a/app/models/clusters/cluster.rb b/app/models/clusters/cluster.rb
index 5156c7d7514..c490a222c51 100644
--- a/app/models/clusters/cluster.rb
+++ b/app/models/clusters/cluster.rb
@@ -8,15 +8,17 @@ module Clusters
self.table_name = 'clusters'
+ PROJECT_ONLY_APPLICATIONS = {
+ Applications::Jupyter.application_name => Applications::Jupyter,
+ Applications::Knative.application_name => Applications::Knative,
+ Applications::Prometheus.application_name => Applications::Prometheus
+ }.freeze
APPLICATIONS = {
Applications::Helm.application_name => Applications::Helm,
Applications::Ingress.application_name => Applications::Ingress,
Applications::CertManager.application_name => Applications::CertManager,
- Applications::Prometheus.application_name => Applications::Prometheus,
- Applications::Runner.application_name => Applications::Runner,
- Applications::Jupyter.application_name => Applications::Jupyter,
- Applications::Knative.application_name => Applications::Knative
- }.freeze
+ Applications::Runner.application_name => Applications::Runner
+ }.merge(PROJECT_ONLY_APPLICATIONS).freeze
DEFAULT_ENVIRONMENT = '*'.freeze
KUBE_INGRESS_BASE_DOMAIN = 'KUBE_INGRESS_BASE_DOMAIN'.freeze
diff --git a/app/services/clusters/applications/base_service.rb b/app/services/clusters/applications/base_service.rb
index cbd1cf03ae1..14a45437287 100644
--- a/app/services/clusters/applications/base_service.rb
+++ b/app/services/clusters/applications/base_service.rb
@@ -41,7 +41,7 @@ module Clusters
raise NotImplementedError
end
- def builders
+ def builder
raise NotImplementedError
end
@@ -50,11 +50,27 @@ module Clusters
end
def instantiate_application
- builder.call(@cluster) || raise(InvalidApplicationError, "invalid application: #{application_name}")
+ raise_invalid_application_error if invalid_application?
+
+ builder || raise(InvalidApplicationError, "invalid application: #{application_name}")
end
- def builder
- builders[application_name] || raise(InvalidApplicationError, "invalid application: #{application_name}")
+ def raise_invalid_application_error
+ raise(InvalidApplicationError, "invalid application: #{application_name}")
+ end
+
+ def invalid_application?
+ unknown_application? || (!cluster.project_type? && project_only_application?)
+ end
+
+ def unknown_application?
+ Clusters::Cluster::APPLICATIONS.keys.exclude?(application_name)
+ end
+
+ # These applications will need extra configuration to enable them to work
+ # with groups of projects
+ def project_only_application?
+ Clusters::Cluster::PROJECT_ONLY_APPLICATIONS.include?(application_name)
end
def application_name
diff --git a/app/services/clusters/applications/create_service.rb b/app/services/clusters/applications/create_service.rb
index c6f729aaa8a..ae36da7b3dd 100644
--- a/app/services/clusters/applications/create_service.rb
+++ b/app/services/clusters/applications/create_service.rb
@@ -9,25 +9,9 @@ module Clusters
application.updateable? ? ClusterUpgradeAppWorker : ClusterInstallAppWorker
end
- def builders
- {
- "helm" => -> (cluster) { cluster.application_helm || cluster.build_application_helm },
- "ingress" => -> (cluster) { cluster.application_ingress || cluster.build_application_ingress },
- "cert_manager" => -> (cluster) { cluster.application_cert_manager || cluster.build_application_cert_manager },
- "runner" => -> (cluster) { cluster.application_runner || cluster.build_application_runner }
- }.tap do |hash|
- hash.merge!(project_builders) if cluster.project_type?
- end
- end
-
- # These applications will need extra configuration to enable them to work
- # with groups of projects
- def project_builders
- {
- "prometheus" => -> (cluster) { cluster.application_prometheus || cluster.build_application_prometheus },
- "jupyter" => -> (cluster) { cluster.application_jupyter || cluster.build_application_jupyter },
- "knative" => -> (cluster) { cluster.application_knative || cluster.build_application_knative }
- }
+ def builder
+ cluster.method("application_#{application_name}").call ||
+ cluster.method("build_application_#{application_name}").call
end
end
end
diff --git a/app/services/clusters/applications/update_service.rb b/app/services/clusters/applications/update_service.rb
index a9d4e609992..5071c31839c 100644
--- a/app/services/clusters/applications/update_service.rb
+++ b/app/services/clusters/applications/update_service.rb
@@ -9,25 +9,8 @@ module Clusters
ClusterPatchAppWorker
end
- def builders
- {
- "helm" => -> (cluster) { cluster.application_helm },
- "ingress" => -> (cluster) { cluster.application_ingress },
- "cert_manager" => -> (cluster) { cluster.application_cert_manager }
- }.tap do |hash|
- hash.merge!(project_builders) if cluster.project_type?
- end
- end
-
- # These applications will need extra configuration to enable them to work
- # with groups of projects
- def project_builders
- {
- "prometheus" => -> (cluster) { cluster.application_prometheus },
- "runner" => -> (cluster) { cluster.application_runner },
- "jupyter" => -> (cluster) { cluster.application_jupyter },
- "knative" => -> (cluster) { cluster.application_knative }
- }
+ def builder
+ cluster.method("application_#{application_name}").call
end
end
end