From b72d7e5e46a9224904041ab380029ab7b35fdee3 Mon Sep 17 00:00:00 2001 From: Prakash Kumar Date: Tue, 14 Nov 2023 21:26:43 +0530 Subject: [PATCH 1/2] adding nil checks for servicePortMapping, etc while extracting port from manifest --- pkg/k8s/K8sCommonService.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/k8s/K8sCommonService.go b/pkg/k8s/K8sCommonService.go index f8c7e3f3721..4ddc8221dd6 100644 --- a/pkg/k8s/K8sCommonService.go +++ b/pkg/k8s/K8sCommonService.go @@ -536,13 +536,19 @@ func (impl K8sCommonServiceImpl) PortNumberExtraction(resp []BatchResourceRespon } for key, _type := range value { if key == k8sCommonBean.Kind && _type == k8sCommonBean.EndpointsKind { - value[k8sCommonBean.Port] = endpointPortMapping[serviceName] + if len(endpointPortMapping) != 0 { + value[k8sCommonBean.Port] = endpointPortMapping[serviceName] + } } if key == k8sCommonBean.Kind && _type == k8sCommonBean.ServiceKind { - value[k8sCommonBean.Port] = servicePortMapping[serviceName] + if len(servicePortMapping) != 0 { + value[k8sCommonBean.Port] = servicePortMapping[serviceName] + } } if key == k8sCommonBean.Kind && _type == k8sCommonBean.EndPointsSlice { - value[k8sCommonBean.Port] = endpointSlicePortMapping[serviceName] + if len(endpointSlicePortMapping) != 0 { + value[k8sCommonBean.Port] = endpointSlicePortMapping[serviceName] + } } } } From cf63d89294f38d9b795d0602d00d13d4f44adaab Mon Sep 17 00:00:00 2001 From: Prakash Kumar Date: Fri, 17 Nov 2023 11:00:48 +0530 Subject: [PATCH 2/2] refactor --- pkg/k8s/K8sCommonService.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/k8s/K8sCommonService.go b/pkg/k8s/K8sCommonService.go index 4ddc8221dd6..26cc1cdc926 100644 --- a/pkg/k8s/K8sCommonService.go +++ b/pkg/k8s/K8sCommonService.go @@ -536,18 +536,18 @@ func (impl K8sCommonServiceImpl) PortNumberExtraction(resp []BatchResourceRespon } for key, _type := range value { if key == k8sCommonBean.Kind && _type == k8sCommonBean.EndpointsKind { - if len(endpointPortMapping) != 0 { - value[k8sCommonBean.Port] = endpointPortMapping[serviceName] + if port, ok := endpointPortMapping[serviceName]; ok { + value[k8sCommonBean.Port] = port } } if key == k8sCommonBean.Kind && _type == k8sCommonBean.ServiceKind { - if len(servicePortMapping) != 0 { - value[k8sCommonBean.Port] = servicePortMapping[serviceName] + if port, ok := servicePortMapping[serviceName]; ok { + value[k8sCommonBean.Port] = port } } if key == k8sCommonBean.Kind && _type == k8sCommonBean.EndPointsSlice { - if len(endpointSlicePortMapping) != 0 { - value[k8sCommonBean.Port] = endpointSlicePortMapping[serviceName] + if port, ok := endpointSlicePortMapping[serviceName]; ok { + value[k8sCommonBean.Port] = port } } }