mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +02:00
Enable the ability to cordon/uncordon/drain nodes (#4723)
* feat(node): Enable the ability to cordon/uncordon/drain nodes * feat(cluster): check if there is a drain operation somewhere * feat(kubernetes): allow to cordon, uncordon, drain nodes * refacto(kubernetes): set a constant for drain label name * fix(node): Relocate the warning message next to the dropdown and change the information message
This commit is contained in:
parent
660bc2dadf
commit
32a9a2e46b
10 changed files with 182 additions and 13 deletions
|
@ -10,7 +10,7 @@ import {
|
|||
} from 'Kubernetes/models/application/models';
|
||||
|
||||
import { createPayloadFactory } from './payloads/create';
|
||||
import { KubernetesPod, KubernetesPodToleration, KubernetesPodAffinity, KubernetesPodContainer, KubernetesPodContainerTypes } from './models';
|
||||
import { KubernetesPod, KubernetesPodToleration, KubernetesPodAffinity, KubernetesPodContainer, KubernetesPodContainerTypes, KubernetesPodEviction } from 'Kubernetes/pod/models';
|
||||
|
||||
function computeStatus(statuses) {
|
||||
const containerStatuses = _.map(statuses, 'state');
|
||||
|
@ -117,6 +117,13 @@ export default class KubernetesPodConverter {
|
|||
return res;
|
||||
}
|
||||
|
||||
static evictionPayload(pod) {
|
||||
const res = new KubernetesPodEviction();
|
||||
res.metadata.name = pod.Name;
|
||||
res.metadata.namespace = pod.Namespace;
|
||||
return res;
|
||||
}
|
||||
|
||||
static patchPayload(oldPod, newPod) {
|
||||
const oldPayload = createPayload(oldPod);
|
||||
const newPayload = createPayload(newPod);
|
||||
|
|
|
@ -65,6 +65,21 @@ export class KubernetesPodContainer {
|
|||
}
|
||||
}
|
||||
|
||||
const _KubernetesPodEviction = Object.freeze({
|
||||
apiVersion: 'policy/v1beta1',
|
||||
kind: 'Eviction',
|
||||
metadata: {
|
||||
name: '',
|
||||
namespace: '',
|
||||
},
|
||||
});
|
||||
|
||||
export class KubernetesPodEviction {
|
||||
constructor() {
|
||||
Object.assign(this, JSON.parse(JSON.stringify(_KubernetesPodEviction)));
|
||||
}
|
||||
}
|
||||
|
||||
export const KubernetesPodContainerTypes = {
|
||||
INIT: 1,
|
||||
APP: 2,
|
||||
|
|
|
@ -2,7 +2,7 @@ import angular from 'angular';
|
|||
import PortainerError from 'Portainer/error';
|
||||
|
||||
import { KubernetesCommonParams } from 'Kubernetes/models/common/params';
|
||||
import KubernetesPodConverter from './converter';
|
||||
import KubernetesPodConverter from 'Kubernetes/pod/converter';
|
||||
|
||||
class KubernetesPodService {
|
||||
/* @ngInject */
|
||||
|
@ -15,6 +15,7 @@ class KubernetesPodService {
|
|||
this.logsAsync = this.logsAsync.bind(this);
|
||||
this.deleteAsync = this.deleteAsync.bind(this);
|
||||
this.patchAsync = this.patchAsync.bind(this);
|
||||
this.evictionAsync = this.evictionAsync.bind(this);
|
||||
}
|
||||
|
||||
async getAsync(namespace, name) {
|
||||
|
@ -116,6 +117,26 @@ class KubernetesPodService {
|
|||
delete(pod) {
|
||||
return this.$async(this.deleteAsync, pod);
|
||||
}
|
||||
|
||||
/**
|
||||
* EVICT
|
||||
*/
|
||||
async evictionAsync(pod) {
|
||||
try {
|
||||
const params = new KubernetesCommonParams();
|
||||
params.id = pod.Name;
|
||||
params.action = 'eviction';
|
||||
const namespace = pod.Namespace;
|
||||
const podEvictionPayload = KubernetesPodConverter.evictionPayload(pod);
|
||||
await this.KubernetesPods(namespace).evict(params, podEvictionPayload).$promise;
|
||||
} catch (err) {
|
||||
throw new PortainerError('Unable to evict pod', err);
|
||||
}
|
||||
}
|
||||
|
||||
eviction(pod) {
|
||||
return this.$async(this.evictionAsync, pod);
|
||||
}
|
||||
}
|
||||
|
||||
export default KubernetesPodService;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue