From a79aa221d32da59a021a028bd9f1120a1fd3829e Mon Sep 17 00:00:00 2001 From: Richard Wei <54336863+WaysonWei@users.noreply.github.com> Date: Thu, 20 Jan 2022 08:21:03 +1300 Subject: [PATCH] fix error when edit pod application (#6418) --- app/kubernetes/helpers/application/index.js | 88 +++++++++++---------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/app/kubernetes/helpers/application/index.js b/app/kubernetes/helpers/application/index.js index 8777c0cd4..ff405a3d6 100644 --- a/app/kubernetes/helpers/application/index.js +++ b/app/kubernetes/helpers/application/index.js @@ -279,56 +279,60 @@ class KubernetesApplicationHelper { /* #region SERVICES -> SERVICES FORM VALUES */ static generateServicesFormValuesFromServices(app) { let 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; - } + 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; + } - 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; + 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; - } + 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; + return services; + } } /* #endregion */ static generateSelectorFromService(app) { - const selector = app.Raw.spec.selector.matchLabels; - return selector; + if (app.Raw.kind !== 'Pod') { + const selector = app.Raw.spec.selector.matchLabels; + return selector; + } } /* #region PUBLISHED PORTS FV <> PUBLISHED PORTS */