1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-02 20:35:25 +02:00

refactor(app): migrate app summary section [EE-6239] (#10910)
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run

This commit is contained in:
Ali 2024-01-05 15:42:36 +13:00 committed by GitHub
parent 7a4314032a
commit abf517de28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
61 changed files with 1461 additions and 661 deletions

View file

@ -1,15 +1,12 @@
import _ from 'lodash-es';
import filesizeParser from 'filesize-parser';
import { KubernetesApplicationDataAccessPolicies, KubernetesApplicationDeploymentTypes, KubernetesApplicationTypes } from 'Kubernetes/models/application/models/appConstants';
import {
KubernetesApplication,
KubernetesApplicationConfigurationVolume,
KubernetesApplicationDataAccessPolicies,
KubernetesApplicationDeploymentTypes,
KubernetesApplicationPersistedFolder,
KubernetesApplicationPort,
KubernetesApplicationPublishingTypes,
KubernetesApplicationTypes,
KubernetesPortainerApplicationNameLabel,
KubernetesPortainerApplicationNote,
KubernetesPortainerApplicationOwnerLabel,
@ -241,16 +238,16 @@ class KubernetesApplicationConverter {
static apiPodToApplication(data, pods, service, ingresses) {
const res = new KubernetesApplication();
KubernetesApplicationConverter.applicationCommon(res, data, pods, service, ingresses);
res.ApplicationType = KubernetesApplicationTypes.POD;
res.ApplicationType = KubernetesApplicationTypes.Pod;
return res;
}
static apiDeploymentToApplication(data, pods, service, ingresses) {
const res = new KubernetesApplication();
KubernetesApplicationConverter.applicationCommon(res, data, pods, service, ingresses);
res.ApplicationType = KubernetesApplicationTypes.DEPLOYMENT;
res.DeploymentType = KubernetesApplicationDeploymentTypes.REPLICATED;
res.DataAccessPolicy = KubernetesApplicationDataAccessPolicies.SHARED;
res.ApplicationType = KubernetesApplicationTypes.Deployment;
res.DeploymentType = KubernetesApplicationDeploymentTypes.Replicated;
res.DataAccessPolicy = KubernetesApplicationDataAccessPolicies.Shared;
res.RunningPodsCount = data.status.availableReplicas || data.status.replicas - data.status.unavailableReplicas || 0;
res.TotalPodsCount = data.spec.replicas;
return res;
@ -259,9 +256,9 @@ class KubernetesApplicationConverter {
static apiDaemonSetToApplication(data, pods, service, ingresses) {
const res = new KubernetesApplication();
KubernetesApplicationConverter.applicationCommon(res, data, pods, service, ingresses);
res.ApplicationType = KubernetesApplicationTypes.DAEMONSET;
res.DeploymentType = KubernetesApplicationDeploymentTypes.GLOBAL;
res.DataAccessPolicy = KubernetesApplicationDataAccessPolicies.SHARED;
res.ApplicationType = KubernetesApplicationTypes.DaemonSet;
res.DeploymentType = KubernetesApplicationDeploymentTypes.Global;
res.DataAccessPolicy = KubernetesApplicationDataAccessPolicies.Shared;
res.RunningPodsCount = data.status.numberAvailable || data.status.desiredNumberScheduled - data.status.numberUnavailable || 0;
res.TotalPodsCount = data.status.desiredNumberScheduled;
return res;
@ -270,9 +267,9 @@ class KubernetesApplicationConverter {
static apiStatefulSetToapplication(data, pods, service, ingresses) {
const res = new KubernetesApplication();
KubernetesApplicationConverter.applicationCommon(res, data, pods, service, ingresses);
res.ApplicationType = KubernetesApplicationTypes.STATEFULSET;
res.DeploymentType = KubernetesApplicationDeploymentTypes.REPLICATED;
res.DataAccessPolicy = KubernetesApplicationDataAccessPolicies.ISOLATED;
res.ApplicationType = KubernetesApplicationTypes.StatefulSet;
res.DeploymentType = KubernetesApplicationDeploymentTypes.Replicated;
res.DataAccessPolicy = KubernetesApplicationDataAccessPolicies.Isolated;
res.RunningPodsCount = data.status.readyReplicas || 0;
res.TotalPodsCount = data.spec.replicas;
res.HeadlessServiceName = data.spec.serviceName;
@ -313,16 +310,7 @@ class KubernetesApplicationConverter {
res.PublishedPorts = KubernetesApplicationHelper.generatePublishedPortsFormValuesFromPublishedPorts(app.ServiceType, app.PublishedPorts, ingresses);
res.Containers = app.Containers;
const isIngress = _.filter(res.PublishedPorts, (p) => p.IngressName).length;
if (app.ServiceType === KubernetesServiceTypes.LOAD_BALANCER) {
res.PublishingType = KubernetesApplicationPublishingTypes.LOAD_BALANCER;
} else if (app.ServiceType === KubernetesServiceTypes.NODE_PORT) {
res.PublishingType = KubernetesApplicationPublishingTypes.NODE_PORT;
} else if (app.ServiceType === KubernetesServiceTypes.CLUSTER_IP && isIngress) {
res.PublishingType = KubernetesApplicationPublishingTypes.INGRESS;
} else {
res.PublishingType = KubernetesApplicationPublishingTypes.CLUSTER_IP;
}
res.PublishingType = app.ServiceType;
if (app.Pods && app.Pods.length) {
KubernetesApplicationHelper.generatePlacementsFormValuesFromAffinity(res, app.Pods[0].Affinity);
@ -338,20 +326,20 @@ class KubernetesApplicationConverter {
const rwx = KubernetesApplicationHelper.hasRWX(claims);
const deployment =
(formValues.DeploymentType === KubernetesApplicationDeploymentTypes.REPLICATED &&
(claims.length === 0 || (claims.length > 0 && formValues.DataAccessPolicy === KubernetesApplicationDataAccessPolicies.SHARED))) ||
formValues.ApplicationType === KubernetesApplicationTypes.DEPLOYMENT;
(formValues.DeploymentType === KubernetesApplicationDeploymentTypes.Replicated &&
(claims.length === 0 || (claims.length > 0 && formValues.DataAccessPolicy === KubernetesApplicationDataAccessPolicies.Shared))) ||
formValues.ApplicationType === KubernetesApplicationTypes.Deployment;
const statefulSet =
(formValues.DeploymentType === KubernetesApplicationDeploymentTypes.REPLICATED &&
(formValues.DeploymentType === KubernetesApplicationDeploymentTypes.Replicated &&
claims.length > 0 &&
formValues.DataAccessPolicy === KubernetesApplicationDataAccessPolicies.ISOLATED) ||
formValues.ApplicationType === KubernetesApplicationTypes.STATEFULSET;
formValues.DataAccessPolicy === KubernetesApplicationDataAccessPolicies.Isolated) ||
formValues.ApplicationType === KubernetesApplicationTypes.StatefulSet;
const daemonSet =
(formValues.DeploymentType === KubernetesApplicationDeploymentTypes.GLOBAL &&
(claims.length === 0 || (claims.length > 0 && formValues.DataAccessPolicy === KubernetesApplicationDataAccessPolicies.SHARED && rwx))) ||
formValues.ApplicationType === KubernetesApplicationTypes.DAEMONSET;
(formValues.DeploymentType === KubernetesApplicationDeploymentTypes.Global &&
(claims.length === 0 || (claims.length > 0 && formValues.DataAccessPolicy === KubernetesApplicationDataAccessPolicies.Shared && rwx))) ||
formValues.ApplicationType === KubernetesApplicationTypes.DaemonSet;
let app;
if (deployment) {
@ -363,6 +351,7 @@ class KubernetesApplicationConverter {
} else {
throw new PortainerError('Unable to determine which association to use to convert form');
}
app.ApplicationType = formValues.ApplicationType;
let headlessService;
if (statefulSet) {

View file

@ -71,7 +71,7 @@ class KubernetesPersistentVolumeClaimConverter {
res.metadata.namespace = pvc.Namespace;
res.spec.resources.requests.storage = pvc.Storage;
res.spec.storageClassName = pvc.storageClass ? pvc.storageClass.Name : '';
const accessModes = pvc.StorageClass && pvc.StorageClass.AccessModes ? pvc.StorageClass.AccessModes.map((accessMode) => storageClassToPVCAccessModes[accessMode]) : [];
const accessModes = pvc.storageClass && pvc.storageClass.AccessModes ? pvc.storageClass.AccessModes.map((accessMode) => storageClassToPVCAccessModes[accessMode]) : [];
res.spec.accessModes = accessModes;
res.metadata.labels.app = pvc.ApplicationName;
res.metadata.labels[KubernetesPortainerApplicationOwnerLabel] = pvc.ApplicationOwner;

View file

@ -3,7 +3,6 @@ import * as JsonPatch from 'fast-json-patch';
import { KubernetesServiceCreatePayload } from 'Kubernetes/models/service/payloads';
import {
KubernetesApplicationPublishingTypes,
KubernetesPortainerApplicationNameLabel,
KubernetesPortainerApplicationOwnerLabel,
KubernetesPortainerApplicationStackNameLabel,
@ -42,11 +41,7 @@ class KubernetesServiceConverter {
res.StackName = formValues.StackName ? formValues.StackName : formValues.Name;
res.ApplicationOwner = formValues.ApplicationOwner;
res.ApplicationName = formValues.Name;
if (formValues.PublishingType === KubernetesApplicationPublishingTypes.NODE_PORT) {
res.Type = KubernetesServiceTypes.NODE_PORT;
} else if (formValues.PublishingType === KubernetesApplicationPublishingTypes.LOAD_BALANCER) {
res.Type = KubernetesServiceTypes.LOAD_BALANCER;
}
res.Type = formValues.PublishingType;
const ports = _.map(formValues.PublishedPorts, (item) => _publishedPortToServicePort(formValues, item, res.Type));
res.Ports = _.uniqBy(_.without(ports, undefined), (p) => p.targetPort + p.protocol);
return res;
@ -61,13 +56,7 @@ class KubernetesServiceConverter {
res.StackName = formValues.StackName ? formValues.StackName : formValues.Name;
res.ApplicationOwner = formValues.ApplicationOwner;
res.ApplicationName = formValues.Name;
if (service.Type === KubernetesApplicationPublishingTypes.NODE_PORT) {
res.Type = KubernetesServiceTypes.NODE_PORT;
} else if (service.Type === KubernetesApplicationPublishingTypes.LOAD_BALANCER) {
res.Type = KubernetesServiceTypes.LOAD_BALANCER;
} else if (service.Type === KubernetesApplicationPublishingTypes.CLUSTER_IP) {
res.Type = KubernetesServiceTypes.CLUSTER_IP;
}
res.Type = service.Type;
res.Ingress = service.Ingress;
if (service.Selector !== undefined) {
@ -120,18 +109,7 @@ class KubernetesServiceConverter {
payload.metadata.labels[KubernetesPortainerApplicationNameLabel] = service.ApplicationName;
payload.metadata.labels[KubernetesPortainerApplicationOwnerLabel] = service.ApplicationOwner;
const ports = [];
service.Ports.forEach((port) => {
const p = {};
p.name = port.name;
p.port = port.port;
p.nodePort = port.nodePort;
p.protocol = port.protocol;
p.targetPort = port.targetPort;
ports.push(p);
});
payload.spec.ports = ports;
payload.spec.ports = service.Ports;
payload.spec.selector = service.Selector;
if (service.Headless) {
payload.spec.clusterIP = KubernetesServiceHeadlessClusterIP;