Commit 5b8c2c5d authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'remove-cluster-association-code-duplication' into 'master'

Remove cluster association code duplication

See merge request gitlab-org/gitlab!16615
parents a6e8d5c9 2b82ab1c
......@@ -37,13 +37,18 @@ module Clusters
has_one :platform_kubernetes, class_name: 'Clusters::Platforms::Kubernetes', inverse_of: :cluster, autosave: true
has_one :application_helm, class_name: 'Clusters::Applications::Helm'
has_one :application_ingress, class_name: 'Clusters::Applications::Ingress'
has_one :application_cert_manager, class_name: 'Clusters::Applications::CertManager'
has_one :application_prometheus, class_name: 'Clusters::Applications::Prometheus'
has_one :application_runner, class_name: 'Clusters::Applications::Runner'
has_one :application_jupyter, class_name: 'Clusters::Applications::Jupyter'
has_one :application_knative, class_name: 'Clusters::Applications::Knative'
def self.has_one_cluster_application(name) # rubocop:disable Naming/PredicateName
application = APPLICATIONS[name.to_s]
has_one application.association_name, class_name: application.to_s # rubocop:disable Rails/ReflectionClassName
end
has_one_cluster_application :helm
has_one_cluster_application :ingress
has_one_cluster_application :cert_manager
has_one_cluster_application :prometheus
has_one_cluster_application :runner
has_one_cluster_application :jupyter
has_one_cluster_application :knative
has_many :kubernetes_namespaces
......@@ -127,15 +132,9 @@ module Clusters
end
def applications
[
application_helm || build_application_helm,
application_ingress || build_application_ingress,
application_cert_manager || build_application_cert_manager,
application_prometheus || build_application_prometheus,
application_runner || build_application_runner,
application_jupyter || build_application_jupyter,
application_knative || build_application_knative
]
APPLICATIONS.values.map do |application_class|
public_send(application_class.association_name) || public_send("build_#{application_class.association_name}") # rubocop:disable GitlabSecurity/PublicSend
end
end
def provider
......
......@@ -32,6 +32,10 @@ module Clusters
self.to_s.demodulize.underscore
end
def self.association_name
:"application_#{application_name}"
end
def name
self.class.application_name
end
......
......@@ -77,6 +77,10 @@ module Clusters
params[:application]
end
def application_class
Clusters::Cluster::APPLICATIONS[application_name]
end
def create_oauth_application(application, request)
oauth_application_params = {
name: params[:application],
......
......@@ -10,7 +10,7 @@ module Clusters
end
def builder
cluster.public_send(:"application_#{application_name}") || # rubocop:disable GitlabSecurity/PublicSend
cluster.public_send(application_class.association_name) || # rubocop:disable GitlabSecurity/PublicSend
cluster.public_send(:"build_application_#{application_name}") # rubocop:disable GitlabSecurity/PublicSend
end
end
......
......@@ -16,7 +16,7 @@ module Clusters
private
def builder
cluster.public_send(:"application_#{application_name}") # rubocop:disable GitlabSecurity/PublicSend
cluster.public_send(application_class.association_name) # rubocop:disable GitlabSecurity/PublicSend
end
end
end
......
......@@ -10,7 +10,7 @@ module Clusters
end
def builder
cluster.public_send(:"application_#{application_name}") # rubocop:disable GitlabSecurity/PublicSend
cluster.public_send(application_class.association_name) # rubocop:disable GitlabSecurity/PublicSend
end
end
end
......
......@@ -21,4 +21,8 @@ shared_examples 'cluster application core specs' do |application_name|
expect(Clusters::Cluster::APPLICATIONS[subject.name]).to eq(described_class)
end
end
describe '.association_name' do
it { expect(described_class.association_name).to eq(:"application_#{subject.name}") }
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