diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/clusters/applications/knative.rb | 36 | ||||
-rw-r--r-- | app/models/clusters/cluster.rb | 10 |
2 files changed, 44 insertions, 2 deletions
diff --git a/app/models/clusters/applications/knative.rb b/app/models/clusters/applications/knative.rb index c0aaa8dce20..168a24da738 100644 --- a/app/models/clusters/applications/knative.rb +++ b/app/models/clusters/applications/knative.rb @@ -15,6 +15,9 @@ module Clusters include ::Clusters::Concerns::ApplicationVersion include ::Clusters::Concerns::ApplicationData include AfterCommitQueue + include ReactiveCaching + + self.reactive_cache_key = ->(knative) { [knative.class.model_name.singular, knative.id] } state_machine :status do before_transition any => [:installed] do |application| @@ -29,6 +32,8 @@ module Clusters validates :hostname, presence: true, hostname: true + scope :for_cluster, -> (cluster) { where(cluster: cluster) } + def chart 'knative/knative' end @@ -55,12 +60,39 @@ module Clusters ClusterWaitForIngressIpAddressWorker.perform_async(name, id) end + def client + cluster.kubeclient.knative_client + end + + def services + with_reactive_cache do |data| + data[:services] + end + end + + def calculate_reactive_cache + { services: read_services } + end + def ingress_service cluster.kubeclient.get_service('knative-ingressgateway', 'istio-system') end - def client - cluster.platform_kubernetes.kubeclient.knative_client + def services_for(ns: namespace) + return unless services + return [] unless ns + + services.select do |service| + service.dig('metadata', 'namespace') == ns + end + end + + private + + def read_services + client.get_services.as_json + rescue Kubeclient::ResourceNotFoundError + [] end end end diff --git a/app/models/clusters/cluster.rb b/app/models/clusters/cluster.rb index c9bd1728dbd..7fe43cd2de0 100644 --- a/app/models/clusters/cluster.rb +++ b/app/models/clusters/cluster.rb @@ -93,6 +93,16 @@ module Clusters where('NOT EXISTS (?)', subquery) end + scope :with_knative_installed, -> { joins(:application_knative).merge(Clusters::Applications::Knative.installed) } + + scope :preload_knative, -> { + preload( + :kubernetes_namespace, + :platform_kubernetes, + :application_knative + ) + } + def self.ancestor_clusters_for_clusterable(clusterable, hierarchy_order: :asc) hierarchy_groups = clusterable.ancestors_upto(hierarchy_order: hierarchy_order).eager_load(:clusters) hierarchy_groups = hierarchy_groups.merge(current_scope) if current_scope |