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