Commit f2f98d7f authored by João Cunha's avatar João Cunha

Improve logic to associate applications

parent 4a990ecb
...@@ -37,10 +37,19 @@ module Clusters ...@@ -37,10 +37,19 @@ 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
APPLICATIONS.values.each do |application| def self.has_one_cluster_application(name)
application = APPLICATIONS[name.to_s]
has_one application.association_name, class_name: application.to_s # rubocop:disable Rails/ReflectionClassName has_one application.association_name, class_name: application.to_s # rubocop:disable Rails/ReflectionClassName
end 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 has_many :kubernetes_namespaces
accepts_nested_attributes_for :provider_gcp, update_only: true accepts_nested_attributes_for :provider_gcp, update_only: true
...@@ -123,8 +132,8 @@ module Clusters ...@@ -123,8 +132,8 @@ module Clusters
end end
def applications def applications
APPLICATIONS.values.map do |application| APPLICATIONS.values.map do |application_class|
public_send(application.association_name) || public_send("build_#{application.association_name}") # rubocop:disable GitlabSecurity/PublicSend public_send(application_class.association_name) || public_send("build_#{application_class.association_name}") # rubocop:disable GitlabSecurity/PublicSend
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