mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 20:35:25 +02:00
feat(k8s/application): expose tolerations and affinities (#4063)
* feat(k8s/application): expose placement conditions * feat(k8s/applications): minor UI update * feat(k8s/application): update message for admin and non admin users * feat(kubernetes/applications): minor UI update Co-authored-by: Anthony Lapenna <lapenna.anthony@gmail.com>
This commit is contained in:
parent
63bf654d8d
commit
4431d748c2
22 changed files with 635 additions and 112 deletions
|
@ -1,65 +0,0 @@
|
|||
import _ from 'lodash-es';
|
||||
|
||||
import { KubernetesNode, KubernetesNodeDetails } from 'Kubernetes/models/node/models';
|
||||
import KubernetesResourceReservationHelper from 'Kubernetes/helpers/resourceReservationHelper';
|
||||
|
||||
class KubernetesNodeConverter {
|
||||
static apiToNode(data, res) {
|
||||
if (!res) {
|
||||
res = new KubernetesNode();
|
||||
}
|
||||
res.Id = data.metadata.uid;
|
||||
const hostName = _.find(data.status.addresses, { type: 'Hostname' });
|
||||
res.Name = hostName ? hostName.address : data.metadata.Name;
|
||||
res.Role = _.has(data.metadata.labels, 'node-role.kubernetes.io/master') ? 'Master' : 'Worker';
|
||||
|
||||
const ready = _.find(data.status.conditions, { type: KubernetesNodeConditionTypes.READY });
|
||||
const memoryPressure = _.find(data.status.conditions, { type: KubernetesNodeConditionTypes.MEMORY_PRESSURE });
|
||||
const PIDPressure = _.find(data.status.conditions, { type: KubernetesNodeConditionTypes.PID_PRESSURE });
|
||||
const diskPressure = _.find(data.status.conditions, { type: KubernetesNodeConditionTypes.DISK_PRESSURE });
|
||||
const networkUnavailable = _.find(data.status.conditions, { type: KubernetesNodeConditionTypes.NETWORK_UNAVAILABLE });
|
||||
|
||||
res.Conditions = {
|
||||
MemoryPressure: memoryPressure && memoryPressure.status === 'True',
|
||||
PIDPressure: PIDPressure && PIDPressure.status === 'True',
|
||||
DiskPressure: diskPressure && diskPressure.status === 'True',
|
||||
NetworkUnavailable: networkUnavailable && networkUnavailable.status === 'True',
|
||||
};
|
||||
|
||||
if (ready.status === 'False') {
|
||||
res.Status = 'Unhealthy';
|
||||
} else if (ready.status === 'Unknown' || res.Conditions.MemoryPressure || res.Conditions.PIDPressure || res.Conditions.DiskPressure || res.Conditions.NetworkUnavailable) {
|
||||
res.Status = 'Warning';
|
||||
} else {
|
||||
res.Status = 'Ready';
|
||||
}
|
||||
|
||||
res.CPU = KubernetesResourceReservationHelper.parseCPU(data.status.allocatable.cpu);
|
||||
res.Memory = data.status.allocatable.memory;
|
||||
res.Version = data.status.nodeInfo.kubeletVersion;
|
||||
const internalIP = _.find(data.status.addresses, { type: 'InternalIP' });
|
||||
res.IPAddress = internalIP ? internalIP.address : '-';
|
||||
return res;
|
||||
}
|
||||
|
||||
static apiToNodeDetails(data, yaml) {
|
||||
let res = new KubernetesNodeDetails();
|
||||
res = KubernetesNodeConverter.apiToNode(data, res);
|
||||
res.CreationDate = data.metadata.creationTimestamp;
|
||||
res.OS.Architecture = data.status.nodeInfo.architecture;
|
||||
res.OS.Platform = data.status.nodeInfo.operatingSystem;
|
||||
res.OS.Image = data.status.nodeInfo.osImage;
|
||||
res.Yaml = yaml ? yaml.data : '';
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
export const KubernetesNodeConditionTypes = Object.freeze({
|
||||
READY: 'Ready',
|
||||
MEMORY_PRESSURE: 'MemoryPressure',
|
||||
PID_PRESSURE: 'PIDPressure',
|
||||
DISK_PRESSURE: 'DiskPressure',
|
||||
NETWORK_UNAVAILABLE: 'NetworkUnavailable',
|
||||
});
|
||||
|
||||
export default KubernetesNodeConverter;
|
|
@ -1,32 +0,0 @@
|
|||
import _ from 'lodash-es';
|
||||
import { KubernetesPod } from 'Kubernetes/models/pod/models';
|
||||
class KubernetesPodConverter {
|
||||
static computeStatus(statuses) {
|
||||
const containerStatuses = _.map(statuses, 'state');
|
||||
const running = _.filter(containerStatuses, (s) => s.running).length;
|
||||
const waiting = _.filter(containerStatuses, (s) => s.waiting).length;
|
||||
if (waiting) {
|
||||
return 'Waiting';
|
||||
} else if (!running) {
|
||||
return 'Terminated';
|
||||
}
|
||||
return 'Running';
|
||||
}
|
||||
|
||||
static apiToPod(data) {
|
||||
const res = new KubernetesPod();
|
||||
res.Id = data.metadata.uid;
|
||||
res.Name = data.metadata.name;
|
||||
res.Namespace = data.metadata.namespace;
|
||||
res.Images = _.map(data.spec.containers, 'image');
|
||||
res.Status = KubernetesPodConverter.computeStatus(data.status.containerStatuses);
|
||||
res.Restarts = _.sumBy(data.status.containerStatuses, 'restartCount');
|
||||
res.Node = data.spec.nodeName;
|
||||
res.CreationDate = data.status.startTime;
|
||||
res.Containers = data.spec.containers;
|
||||
res.Labels = data.metadata.labels;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
export default KubernetesPodConverter;
|
Loading…
Add table
Add a link
Reference in a new issue