mirror of https://github.com/portainer/portainer
Co-authored-by: Simon Meng <simon.meng@portainer.io>pull/4798/head^2
parent
590b6f69bf
commit
86335a4357
|
@ -27,4 +27,5 @@ angular
|
|||
.constant('APPLICATION_CACHE_VALIDITY', 3600)
|
||||
.constant('CONSOLE_COMMANDS_LABEL_PREFIX', 'io.portainer.commands.')
|
||||
.constant('PREDEFINED_NETWORKS', ['host', 'bridge', 'none'])
|
||||
.constant('KUBERNETES_DEFAULT_NAMESPACE', 'default')
|
||||
.constant('KUBERNETES_SYSTEM_NAMESPACES', ['kube-system', 'kube-public', 'kube-node-lease', 'portainer']);
|
||||
|
|
|
@ -3,13 +3,18 @@ import angular from 'angular';
|
|||
|
||||
class KubernetesNamespaceHelper {
|
||||
/* @ngInject */
|
||||
constructor(KUBERNETES_SYSTEM_NAMESPACES) {
|
||||
constructor(KUBERNETES_SYSTEM_NAMESPACES, KUBERNETES_DEFAULT_NAMESPACE) {
|
||||
this.KUBERNETES_SYSTEM_NAMESPACES = KUBERNETES_SYSTEM_NAMESPACES;
|
||||
this.KUBERNETES_DEFAULT_NAMESPACE = KUBERNETES_DEFAULT_NAMESPACE;
|
||||
}
|
||||
|
||||
isSystemNamespace(namespace) {
|
||||
return _.includes(this.KUBERNETES_SYSTEM_NAMESPACES, namespace);
|
||||
}
|
||||
|
||||
isDefaultNamespace(namespace) {
|
||||
return namespace === this.KUBERNETES_DEFAULT_NAMESPACE;
|
||||
}
|
||||
}
|
||||
|
||||
export default KubernetesNamespaceHelper;
|
||||
|
|
|
@ -9,7 +9,19 @@ import { KubernetesIngressClassTypes } from 'Kubernetes/ingress/constants';
|
|||
class KubernetesConfigureController {
|
||||
/* #region CONSTRUCTOR */
|
||||
/* @ngInject */
|
||||
constructor($async, $state, $stateParams, Notifications, KubernetesStorageService, EndpointService, EndpointProvider, ModalService) {
|
||||
constructor(
|
||||
$async,
|
||||
$state,
|
||||
$stateParams,
|
||||
Notifications,
|
||||
KubernetesStorageService,
|
||||
EndpointService,
|
||||
EndpointProvider,
|
||||
ModalService,
|
||||
KubernetesNamespaceHelper,
|
||||
KubernetesResourcePoolService,
|
||||
KubernetesIngressService
|
||||
) {
|
||||
this.$async = $async;
|
||||
this.$state = $state;
|
||||
this.$stateParams = $stateParams;
|
||||
|
@ -18,6 +30,9 @@ class KubernetesConfigureController {
|
|||
this.EndpointService = EndpointService;
|
||||
this.EndpointProvider = EndpointProvider;
|
||||
this.ModalService = ModalService;
|
||||
this.KubernetesNamespaceHelper = KubernetesNamespaceHelper;
|
||||
this.KubernetesResourcePoolService = KubernetesResourcePoolService;
|
||||
this.KubernetesIngressService = KubernetesIngressService;
|
||||
|
||||
this.IngressClassTypes = KubernetesIngressClassTypes;
|
||||
|
||||
|
@ -115,11 +130,37 @@ class KubernetesConfigureController {
|
|||
return [storageClasses, ingressClasses];
|
||||
}
|
||||
|
||||
async removeIngressesAcrossNamespaces() {
|
||||
const promises = [];
|
||||
const ingressesToDel = _.filter(this.formValues.IngressClasses, { NeedsDeletion: true });
|
||||
const allResourcePools = await this.KubernetesResourcePoolService.get();
|
||||
const resourcePools = _.filter(
|
||||
allResourcePools,
|
||||
(resourcePool) =>
|
||||
!this.KubernetesNamespaceHelper.isSystemNamespace(resourcePool.Namespace.Name) && !this.KubernetesNamespaceHelper.isDefaultNamespace(resourcePool.Namespace.Name)
|
||||
);
|
||||
|
||||
ingressesToDel.forEach((ingress) => {
|
||||
resourcePools.forEach((resourcePool) => {
|
||||
promises.push(this.KubernetesIngressService.delete({ IngressClass: ingress, Namespace: resourcePool.Namespace.Name }));
|
||||
});
|
||||
});
|
||||
|
||||
const responses = await Promise.allSettled(promises);
|
||||
responses.forEach((respons) => {
|
||||
if (respons.status == 'rejected' && respons.reason.err.status != 404) {
|
||||
throw respons.reason;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async configureAsync() {
|
||||
try {
|
||||
this.state.actionInProgress = true;
|
||||
const [storageClasses, ingressClasses] = this.transformFormValues();
|
||||
|
||||
await this.removeIngressesAcrossNamespaces();
|
||||
|
||||
this.assignFormValuesToEndpoint(this.endpoint, storageClasses, ingressClasses);
|
||||
await this.EndpointService.updateEndpoint(this.endpoint.Id, this.endpoint);
|
||||
|
||||
|
@ -150,7 +191,7 @@ class KubernetesConfigureController {
|
|||
const toDel = _.filter(this.formValues.IngressClasses, { NeedsDeletion: true });
|
||||
if (toDel.length) {
|
||||
this.ModalService.confirmUpdate(
|
||||
`Removing ingress controllers will make them unavailable for future use.<br/>Existing resources linked to these ingress controllers will continue to live in cluster but you will not be able to remove them from Portainer.<br/><br/>Do you wish to continue?`,
|
||||
`Removing ingress controllers may cause applications to be unaccessible. All ingress configurations from affected applications will be removed.<br/><br/>Do you wish to continue?`,
|
||||
(confirmed) => {
|
||||
if (confirmed) {
|
||||
return this.$async(this.configureAsync);
|
||||
|
|
Loading…
Reference in New Issue