From 7e28b3ca3f8f95ce4cdee6a1f6d22775ff480c54 Mon Sep 17 00:00:00 2001 From: Richard Wei <54336863+WaysonWei@users.noreply.github.com> Date: Wed, 6 Apr 2022 05:42:01 +1200 Subject: [PATCH] fix issue on editing app with persisted folder (#6646) Co-authored-by: Richard Wei --- app/kubernetes/helpers/application/index.js | 81 ++++++++++--------- app/kubernetes/services/applicationService.js | 2 +- .../views/applications/edit/application.html | 2 +- .../summary/resources/applicationResources.js | 60 +++++++------- 4 files changed, 75 insertions(+), 70 deletions(-) diff --git a/app/kubernetes/helpers/application/index.js b/app/kubernetes/helpers/application/index.js index ff405a3d6..1d358ed5c 100644 --- a/app/kubernetes/helpers/application/index.js +++ b/app/kubernetes/helpers/application/index.js @@ -281,47 +281,50 @@ class KubernetesApplicationHelper { let services = []; if (app.Services) { app.Services.forEach(function (service) { - const svc = new KubernetesService(); - svc.Namespace = service.metadata.namespace; - svc.Name = service.metadata.name; - svc.StackName = service.StackName; - svc.ApplicationOwner = app.ApplicationOwner; - svc.ApplicationName = app.ApplicationName; - svc.Type = service.spec.type; - if (service.spec.type === KubernetesServiceTypes.CLUSTER_IP) { - svc.Type = 1; - } else if (service.spec.type === KubernetesServiceTypes.NODE_PORT) { - svc.Type = 2; - } else if (service.spec.type === KubernetesServiceTypes.LOAD_BALANCER) { - svc.Type = 3; - } + //skip generate formValues if service = headless service ( clusterIp === "None" ) + if (service.spec.clusterIP !== 'None') { + const svc = new KubernetesService(); + svc.Namespace = service.metadata.namespace; + svc.Name = service.metadata.name; + svc.StackName = service.StackName; + svc.ApplicationOwner = app.ApplicationOwner; + svc.ApplicationName = app.ApplicationName; + svc.Type = service.spec.type; + if (service.spec.type === KubernetesServiceTypes.CLUSTER_IP) { + svc.Type = 1; + } else if (service.spec.type === KubernetesServiceTypes.NODE_PORT) { + svc.Type = 2; + } else if (service.spec.type === KubernetesServiceTypes.LOAD_BALANCER) { + svc.Type = 3; + } - let ports = []; - service.spec.ports.forEach(function (port) { - const svcport = new KubernetesServicePort(); - svcport.name = port.name; - svcport.port = port.port; - svcport.nodePort = port.nodePort; - svcport.protocol = port.protocol; - svcport.targetPort = port.targetPort; - - app.Ingresses.value.forEach((ingress) => { - const ingressMatched = _.find(ingress.Paths, { ServiceName: service.metadata.name }); - if (ingressMatched) { - svcport.ingress = { - IngressName: ingressMatched.IngressName, - Host: ingressMatched.Host, - Path: ingressMatched.Path, - }; - svc.Ingress = true; - } + let ports = []; + service.spec.ports.forEach(function (port) { + const svcport = new KubernetesServicePort(); + svcport.name = port.name; + svcport.port = port.port; + svcport.nodePort = port.nodePort; + svcport.protocol = port.protocol; + svcport.targetPort = port.targetPort; + + app.Ingresses.value.forEach((ingress) => { + const ingressMatched = _.find(ingress.Paths, { ServiceName: service.metadata.name }); + if (ingressMatched) { + svcport.ingress = { + IngressName: ingressMatched.IngressName, + Host: ingressMatched.Host, + Path: ingressMatched.Path, + }; + svc.Ingress = true; + } + }); + + ports.push(svcport); }); - - ports.push(svcport); - }); - svc.Ports = ports; - svc.Selector = app.Raw.spec.selector.matchLabels; - services.push(svc); + svc.Ports = ports; + svc.Selector = app.Raw.spec.selector.matchLabels; + services.push(svc); + } }); return services; diff --git a/app/kubernetes/services/applicationService.js b/app/kubernetes/services/applicationService.js index d2a736f58..cc7613081 100644 --- a/app/kubernetes/services/applicationService.js +++ b/app/kubernetes/services/applicationService.js @@ -429,10 +429,10 @@ class KubernetesApplicationService { if (apiService === this.KubernetesStatefulSetService) { const headlessServicePayload = angular.copy(payload); headlessServicePayload.Name = application instanceof KubernetesStatefulSet ? application.ServiceName : application.HeadlessServiceName; - await this.KubernetesServiceService.delete(headlessServicePayload); } if (application.ServiceType) { + // delete headless service && non-headless service await this.KubernetesServiceService.delete(application.Services); if (application.Ingresses.length) { diff --git a/app/kubernetes/views/applications/edit/application.html b/app/kubernetes/views/applications/edit/application.html index 5e5763ff7..9bdaaf941 100644 --- a/app/kubernetes/views/applications/edit/application.html +++ b/app/kubernetes/views/applications/edit/application.html @@ -257,7 +257,7 @@ This application is not exposing any port. -
+
diff --git a/app/kubernetes/views/summary/resources/applicationResources.js b/app/kubernetes/views/summary/resources/applicationResources.js index f25264b37..42acb432c 100644 --- a/app/kubernetes/views/summary/resources/applicationResources.js +++ b/app/kubernetes/views/summary/resources/applicationResources.js @@ -237,37 +237,39 @@ function getVolumeClaimUpdateResourceSummary(oldPVC, newPVC) { // getServiceUpdateResourceSummary replicates KubernetesServiceService.patch function getServiceUpdateResourceSummary(oldServices, newServices) { let summary = []; - newServices.forEach((newService) => { - const oldServiceMatched = _.find(oldServices, { Name: newService.Name }); - if (oldServiceMatched) { - const payload = KubernetesServiceConverter.patchPayload(oldServiceMatched, newService); - if (payload.length) { - const serviceUpdate = { - action: UPDATE, - kind: KubernetesResourceTypes.SERVICE, - name: oldServiceMatched.Name, - type: oldServiceMatched.Type || KubernetesServiceTypes.CLUSTER_IP, - }; - summary.push(serviceUpdate); - } - } else { - const emptyService = new KubernetesService(); - const payload = KubernetesServiceConverter.patchPayload(emptyService, newService); - if (payload.length) { - const serviceCreate = { action: CREATE, kind: KubernetesResourceTypes.SERVICE, name: newService.Name, type: newService.Type || KubernetesServiceTypes.CLUSTER_IP }; - summary.push(serviceCreate); + // skip update summary when service is headless service + if (!oldServices.Headless) { + newServices.forEach((newService) => { + const oldServiceMatched = _.find(oldServices, { Name: newService.Name }); + if (oldServiceMatched) { + const payload = KubernetesServiceConverter.patchPayload(oldServiceMatched, newService); + if (payload.length) { + const serviceUpdate = { + action: UPDATE, + kind: KubernetesResourceTypes.SERVICE, + name: oldServiceMatched.Name, + type: oldServiceMatched.Type || KubernetesServiceTypes.CLUSTER_IP, + }; + summary.push(serviceUpdate); + } + } else { + const emptyService = new KubernetesService(); + const payload = KubernetesServiceConverter.patchPayload(emptyService, newService); + if (payload.length) { + const serviceCreate = { action: CREATE, kind: KubernetesResourceTypes.SERVICE, name: newService.Name, type: newService.Type || KubernetesServiceTypes.CLUSTER_IP }; + summary.push(serviceCreate); + } } - } - }); - - oldServices.forEach((oldService) => { - const newServiceMatched = _.find(newServices, { Name: oldService.Name }); - if (!newServiceMatched) { - const serviceDelete = { action: DELETE, kind: KubernetesResourceTypes.SERVICE, name: oldService.Name, type: oldService.Type || KubernetesServiceTypes.CLUSTER_IP }; - summary.push(serviceDelete); - } - }); + }); + oldServices.forEach((oldService) => { + const newServiceMatched = _.find(newServices, { Name: oldService.Name }); + if (!newServiceMatched) { + const serviceDelete = { action: DELETE, kind: KubernetesResourceTypes.SERVICE, name: oldService.Name, type: oldService.Type || KubernetesServiceTypes.CLUSTER_IP }; + summary.push(serviceDelete); + } + }); + } if (summary.length !== 0) { return summary; }