mirror of https://github.com/portainer/portainer
feat(k8s/node): Add the ability to apply taints and labels to nodes (#4176)
* feat(node): Add the ability to apply taints and labels to nodes * feat(k8s/node): minor UI update * feat(k8s/node): UI update and disable system labels * feat(k8s/node): minor UI update * fix(node): fix add first taint * refacto(node): add KubernetesNodeHelper * feat(node): add used label to labels * feat(node): add node update modals * fix(node): modal when used label changes * feat(k8s/node): minor UI update Co-authored-by: Anthony Lapenna <lapenna.anthony@gmail.com>pull/4202/head
parent
1f614ee95a
commit
1bf97426bf
@ -0,0 +1,40 @@
|
||||
const _KubernetesNodeFormValues = Object.freeze({
|
||||
Taints: [],
|
||||
Labels: [],
|
||||
});
|
||||
|
||||
export class KubernetesNodeFormValues {
|
||||
constructor() {
|
||||
Object.assign(JSON.parse(JSON.stringify(_KubernetesNodeFormValues)));
|
||||
}
|
||||
}
|
||||
|
||||
const _KubernetesNodeTaintFormValues = Object.freeze({
|
||||
Key: '',
|
||||
Values: '',
|
||||
Effect: '',
|
||||
NeedsDeletion: false,
|
||||
IsNew: false,
|
||||
IsChanged: false,
|
||||
});
|
||||
|
||||
export class KubernetesNodeTaintFormValues {
|
||||
constructor() {
|
||||
Object.assign(JSON.parse(JSON.stringify(_KubernetesNodeTaintFormValues)));
|
||||
}
|
||||
}
|
||||
|
||||
const _KubernetesNodeLabelFormValues = Object.freeze({
|
||||
Key: '',
|
||||
Values: '',
|
||||
NeedsDeletion: false,
|
||||
IsNew: false,
|
||||
IsUsed: false,
|
||||
IsChanged: false,
|
||||
});
|
||||
|
||||
export class KubernetesNodeLabelFormValues {
|
||||
constructor() {
|
||||
Object.assign(JSON.parse(JSON.stringify(_KubernetesNodeLabelFormValues)));
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
import _ from 'lodash-es';
|
||||
|
||||
export class KubernetesNodeHelper {
|
||||
static isSystemLabel(label) {
|
||||
return !label.IsNew && (_.startsWith(label.Key, 'beta.kubernetes.io') || _.startsWith(label.Key, 'kubernetes.io') || label.Key === 'node-role.kubernetes.io/master');
|
||||
}
|
||||
|
||||
static reorderLabels(labels) {
|
||||
return _.sortBy(labels, (label) => {
|
||||
return !KubernetesNodeHelper.isSystemLabel(label);
|
||||
});
|
||||
}
|
||||
|
||||
static computeUsedLabels(applications, labels) {
|
||||
const pods = _.flatten(_.map(applications, 'Pods'));
|
||||
const nodeSelectors = _.uniq(_.flatten(_.map(pods, 'NodeSelector')));
|
||||
|
||||
return _.map(labels, (label) => {
|
||||
label.IsUsed = _.find(nodeSelectors, (ns) => ns && ns[label.Key] === label.Value) ? true : false;
|
||||
return label;
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* KubernetesNode Create Payload Model
|
||||
* Note: The current payload is here just to create patch payload.
|
||||
*/
|
||||
const _KubernetesNodeCreatePayload = Object.freeze({
|
||||
metadata: {
|
||||
name: '',
|
||||
labels: {},
|
||||
},
|
||||
spec: {
|
||||
taints: undefined,
|
||||
},
|
||||
});
|
||||
|
||||
export class KubernetesNodeCreatePayload {
|
||||
constructor() {
|
||||
Object.assign(this, JSON.parse(JSON.stringify(_KubernetesNodeCreatePayload)));
|
||||
}
|
||||
}
|
||||
|
||||
const _KubernetesNodeTaintPayload = Object.freeze({
|
||||
key: '',
|
||||
value: '',
|
||||
effect: '',
|
||||
});
|
||||
|
||||
export class KubernetesNodeTaintPayload {
|
||||
constructor() {
|
||||
Object.assign(this, JSON.parse(JSON.stringify(_KubernetesNodeTaintPayload)));
|
||||
}
|
||||
}
|
Loading…
Reference in new issue