mirror of https://github.com/portainer/portainer
using new app metadata property to distinguish helm apps (#5627)
parent
05efac44f6
commit
d2cbdf935a
|
@ -56,6 +56,7 @@ class KubernetesApplicationConverter {
|
||||||
const containers = data.spec.template ? _.without(_.concat(data.spec.template.spec.containers, data.spec.template.spec.initContainers), undefined) : data.spec.containers;
|
const containers = data.spec.template ? _.without(_.concat(data.spec.template.spec.containers, data.spec.template.spec.initContainers), undefined) : data.spec.containers;
|
||||||
res.Id = data.metadata.uid;
|
res.Id = data.metadata.uid;
|
||||||
res.Name = data.metadata.name;
|
res.Name = data.metadata.name;
|
||||||
|
res.Metadata = data.metadata;
|
||||||
|
|
||||||
if (data.metadata.labels) {
|
if (data.metadata.labels) {
|
||||||
const { labels } = data.metadata;
|
const { labels } = data.metadata;
|
||||||
|
|
|
@ -449,8 +449,8 @@ class KubernetesApplicationHelper {
|
||||||
// filter out all the applications that are managed by helm
|
// filter out all the applications that are managed by helm
|
||||||
// to identify the helm managed applications, we need to check if the applications pod labels include
|
// to identify the helm managed applications, we need to check if the applications pod labels include
|
||||||
// `app.kubernetes.io/instance` and `app.kubernetes.io/managed-by` = `helm`
|
// `app.kubernetes.io/instance` and `app.kubernetes.io/managed-by` = `helm`
|
||||||
const helmManagedApps = applications.filter((app) =>
|
const helmManagedApps = applications.filter(
|
||||||
app.Pods.flatMap((pod) => pod.Labels).some((label) => label && label[PodKubernetesInstanceLabel] && label[PodManagedByLabel] === 'Helm')
|
(app) => app.Metadata.labels && app.Metadata.labels[PodKubernetesInstanceLabel] && app.Metadata.labels[PodManagedByLabel] === 'Helm'
|
||||||
);
|
);
|
||||||
|
|
||||||
// groups the helm managed applications by helm release name
|
// groups the helm managed applications by helm release name
|
||||||
|
@ -467,16 +467,13 @@ class KubernetesApplicationHelper {
|
||||||
const namespacedHelmReleases = {};
|
const namespacedHelmReleases = {};
|
||||||
helmManagedApps.forEach((app) => {
|
helmManagedApps.forEach((app) => {
|
||||||
const namespace = app.ResourcePool;
|
const namespace = app.ResourcePool;
|
||||||
const labels = app.Pods.filter((p) => p.Labels).map((p) => p.Labels[PodKubernetesInstanceLabel]);
|
const instanceLabel = app.Metadata.labels[PodKubernetesInstanceLabel];
|
||||||
const uniqueLabels = [...new Set(labels)];
|
|
||||||
uniqueLabels.forEach((instanceStr) => {
|
|
||||||
if (namespacedHelmReleases[namespace]) {
|
if (namespacedHelmReleases[namespace]) {
|
||||||
namespacedHelmReleases[namespace][instanceStr] = [...(namespacedHelmReleases[namespace][instanceStr] || []), app];
|
namespacedHelmReleases[namespace][instanceLabel] = [...(namespacedHelmReleases[namespace][instanceLabel] || []), app];
|
||||||
} else {
|
} else {
|
||||||
namespacedHelmReleases[namespace] = { [instanceStr]: [app] };
|
namespacedHelmReleases[namespace] = { [instanceLabel]: [app] };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// `helmAppsEntriesList` object structure:
|
// `helmAppsEntriesList` object structure:
|
||||||
// [
|
// [
|
||||||
|
@ -511,5 +508,25 @@ class KubernetesApplicationHelper {
|
||||||
|
|
||||||
return helmAppsList;
|
return helmAppsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get nested applications -
|
||||||
|
* @param {KubernetesApplication[]} applications Application list
|
||||||
|
* @returns {Object} { helmApplications: [app1, app2, ...], nonHelmApplications: [app3, app4, ...] }
|
||||||
|
*/
|
||||||
|
static getNestedApplications(applications) {
|
||||||
|
const helmApplications = KubernetesApplicationHelper.getHelmApplications(applications);
|
||||||
|
|
||||||
|
// filter out helm managed applications
|
||||||
|
const helmAppNames = [...new Set(helmApplications.map((hma) => hma.Name))]; // distinct helm app names
|
||||||
|
const nonHelmApplications = applications.filter((app) => {
|
||||||
|
if (app.Metadata.labels) {
|
||||||
|
return !helmAppNames.includes(app.Metadata.labels[PodKubernetesInstanceLabel]);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
return { helmApplications, nonHelmApplications };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
export default KubernetesApplicationHelper;
|
export default KubernetesApplicationHelper;
|
||||||
|
|
|
@ -16,6 +16,7 @@ const _KubernetesApplication = Object.freeze({
|
||||||
CreationDate: 0,
|
CreationDate: 0,
|
||||||
Pods: [],
|
Pods: [],
|
||||||
Containers: [],
|
Containers: [],
|
||||||
|
Metadata: {},
|
||||||
Limits: {},
|
Limits: {},
|
||||||
ServiceType: '',
|
ServiceType: '',
|
||||||
ServiceId: '',
|
ServiceId: '',
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import angular from 'angular';
|
import angular from 'angular';
|
||||||
import _ from 'lodash-es';
|
import _ from 'lodash-es';
|
||||||
import KubernetesStackHelper from 'Kubernetes/helpers/stackHelper';
|
import KubernetesStackHelper from 'Kubernetes/helpers/stackHelper';
|
||||||
import KubernetesApplicationHelper, { PodKubernetesInstanceLabel } from 'Kubernetes/helpers/application';
|
import KubernetesApplicationHelper from 'Kubernetes/helpers/application';
|
||||||
import KubernetesConfigurationHelper from 'Kubernetes/helpers/configurationHelper';
|
import KubernetesConfigurationHelper from 'Kubernetes/helpers/configurationHelper';
|
||||||
import { KubernetesApplicationTypes } from 'Kubernetes/models/application/models';
|
import { KubernetesApplicationTypes } from 'Kubernetes/models/application/models';
|
||||||
|
|
||||||
|
@ -109,18 +109,9 @@ class KubernetesApplicationsController {
|
||||||
try {
|
try {
|
||||||
const [applications, configurations] = await Promise.all([this.KubernetesApplicationService.get(), this.KubernetesConfigurationService.get()]);
|
const [applications, configurations] = await Promise.all([this.KubernetesApplicationService.get(), this.KubernetesConfigurationService.get()]);
|
||||||
const configuredApplications = KubernetesConfigurationHelper.getApplicationConfigurations(applications, configurations);
|
const configuredApplications = KubernetesConfigurationHelper.getApplicationConfigurations(applications, configurations);
|
||||||
const helmApplications = KubernetesApplicationHelper.getHelmApplications(configuredApplications);
|
const { helmApplications, nonHelmApplications } = KubernetesApplicationHelper.getNestedApplications(configuredApplications);
|
||||||
|
|
||||||
// filter out multi-chart helm managed applications
|
this.state.applications = [...helmApplications, ...nonHelmApplications];
|
||||||
const helmAppNames = [...new Set(helmApplications.map((hma) => hma.Name))]; // distinct helm app names
|
|
||||||
const nonHelmApps = configuredApplications.filter(
|
|
||||||
(app) =>
|
|
||||||
!app.Pods.flatMap((pod) => pod.Labels) // flatten pod labels
|
|
||||||
.filter((label) => label) // filter out empty labels
|
|
||||||
.some((label) => helmAppNames.includes(label[PodKubernetesInstanceLabel])) // check if label key is in helmAppNames
|
|
||||||
);
|
|
||||||
|
|
||||||
this.state.applications = [...nonHelmApps, ...helmApplications];
|
|
||||||
this.state.stacks = KubernetesStackHelper.stacksFromApplications(applications);
|
this.state.stacks = KubernetesStackHelper.stacksFromApplications(applications);
|
||||||
this.state.ports = KubernetesApplicationHelper.portMappingsFromApplications(applications);
|
this.state.ports = KubernetesApplicationHelper.portMappingsFromApplications(applications);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
Loading…
Reference in New Issue