diff --git a/shell/chart/monitoring/index.vue b/shell/chart/monitoring/index.vue index 48758eaf2bc..6eefae26e87 100644 --- a/shell/chart/monitoring/index.vue +++ b/shell/chart/monitoring/index.vue @@ -53,20 +53,41 @@ export default { async fetch() { const { $store } = this; - const hash = await allHash({ + // Fetch all the resources required for all the tabs asyncronously up front + const hashPromises = { namespaces: $store.getters['namespaces'](), pvcs: $store.dispatch('cluster/findAll', { type: PVC }), + // Used in Alerting tab monitoringSecrets: $store.dispatch('cluster/findAll', { type: SECRET, opt: { namespaced: CATTLE_MONITORING_NAMESPACE } }), storageClasses: $store.dispatch('cluster/findAll', { type: STORAGE_CLASS }), + }; + + // Are we editing an existing chart? + // (ported from shell/chart/monitoring/prometheus/index.vue) + // const { existing = false } = this.$attrs; // TODO: RC + const existing = false; + + // If needed, fetch all the workloads that have prometheus operator like containers + this.workloadTypes = !existing ? Object.values(WORKLOAD_TYPES) : []; + + this.workloadTypes.forEach((type) => { + // We'll use a filter to fetch the results. Atm there's no neat way to differentiate between ALL results and JUST filtered + // So to avoid calls to all getting these filtered (and vice-versa) forget type before and after + $store.dispatch('cluster/forgetType', type); + hashPromises[type] = $store.dispatch('cluster/findAll', { + type, + opt: { + watch: false, + // We're only interested in images with operator like names (note: these will match partial strings) + filter: { 'spec.template.spec.containers.image': ['quay.io/coreos/prometheus-operator', 'rancher/coreos-prometheus-operator'] } + } + }); }); - await Promise.all( - Object.values(WORKLOAD_TYPES).map((type) => this.$store.dispatch('cluster/findAll', { type }) - ) - ); + const hash = await allHash(hashPromises); this.targetNamespace = hash.namespaces[this.chart.targetNamespace] || false; @@ -81,6 +102,18 @@ export default { if (!isEmpty(hash.monitoringSecrets)) { this.monitoringSecrets = hash.monitoringSecrets; } + + this.workloadTypes.forEach((type) => { + if (hash[type]) { + this.filteredWorkloads.push(...hash[type]); + } + }); + }, + + beforeDestroy() { + this.workloadTypes.forEach((type) => { + this.$store.dispatch('cluster/forgetType', type); + }); }, data() { @@ -106,6 +139,8 @@ export default { monitoringSecrets: [], storageClasses: [], targetNamespace: null, + filteredWorkloads: [], + workloadTypes: [] }; }, @@ -114,10 +149,6 @@ export default { provider() { return this.currentCluster.status.provider.toLowerCase(); }, - workloads() { - return Object.values(WORKLOAD_TYPES).flatMap((type) => this.$store.getters['cluster/all'](type) - ); - }, }, watch: { @@ -282,7 +313,7 @@ export default { :mode="mode" :storage-classes="storageClasses" :prometheus-pods="prometheusResources" - :workloads="workloads" + :filteredWorkloads="filteredWorkloads" /> diff --git a/shell/chart/monitoring/prometheus/index.vue b/shell/chart/monitoring/prometheus/index.vue index 133ae5d51ec..27ce19e5165 100644 --- a/shell/chart/monitoring/prometheus/index.vue +++ b/shell/chart/monitoring/prometheus/index.vue @@ -1,5 +1,4 @@