Commit b8118a65 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'refactor/services_list_of_apps_responsibility' into 'master'

Dry up and remove responsibilities from services

Closes #58646

See merge request gitlab-org/gitlab-ce!26731
parents 09061504 5aade0b0
...@@ -8,15 +8,17 @@ module Clusters ...@@ -8,15 +8,17 @@ module Clusters
self.table_name = '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 = {
Applications::Helm.application_name => Applications::Helm, Applications::Helm.application_name => Applications::Helm,
Applications::Ingress.application_name => Applications::Ingress, Applications::Ingress.application_name => Applications::Ingress,
Applications::CertManager.application_name => Applications::CertManager, Applications::CertManager.application_name => Applications::CertManager,
Applications::Prometheus.application_name => Applications::Prometheus, Applications::Runner.application_name => Applications::Runner
Applications::Runner.application_name => Applications::Runner, }.merge(PROJECT_ONLY_APPLICATIONS).freeze
Applications::Jupyter.application_name => Applications::Jupyter,
Applications::Knative.application_name => Applications::Knative
}.freeze
DEFAULT_ENVIRONMENT = '*'.freeze DEFAULT_ENVIRONMENT = '*'.freeze
KUBE_INGRESS_BASE_DOMAIN = 'KUBE_INGRESS_BASE_DOMAIN'.freeze KUBE_INGRESS_BASE_DOMAIN = 'KUBE_INGRESS_BASE_DOMAIN'.freeze
......
...@@ -41,7 +41,7 @@ module Clusters ...@@ -41,7 +41,7 @@ module Clusters
raise NotImplementedError raise NotImplementedError
end end
def builders def builder
raise NotImplementedError raise NotImplementedError
end end
...@@ -50,11 +50,27 @@ module Clusters ...@@ -50,11 +50,27 @@ module Clusters
end end
def instantiate_application 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 end
def builder def raise_invalid_application_error
builders[application_name] || raise(InvalidApplicationError, "invalid application: #{application_name}") 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 end
def application_name def application_name
......
...@@ -9,25 +9,9 @@ module Clusters ...@@ -9,25 +9,9 @@ module Clusters
application.updateable? ? ClusterUpgradeAppWorker : ClusterInstallAppWorker application.updateable? ? ClusterUpgradeAppWorker : ClusterInstallAppWorker
end end
def builders def builder
{ cluster.method("application_#{application_name}").call ||
"helm" => -> (cluster) { cluster.application_helm || cluster.build_application_helm }, cluster.method("build_application_#{application_name}").call
"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 }
}
end end
end end
end end
......
...@@ -9,25 +9,8 @@ module Clusters ...@@ -9,25 +9,8 @@ module Clusters
ClusterPatchAppWorker ClusterPatchAppWorker
end end
def builders def builder
{ cluster.method("application_#{application_name}").call
"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 }
}
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