diff --git a/pkg/k8s/K8sCommonService.go b/pkg/k8s/K8sCommonService.go index f8c7e3f3721..26cc1cdc926 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 port, ok := endpointPortMapping[serviceName]; ok { + value[k8sCommonBean.Port] = port + } } if key == k8sCommonBean.Kind && _type == k8sCommonBean.ServiceKind { - value[k8sCommonBean.Port] = servicePortMapping[serviceName] + if port, ok := servicePortMapping[serviceName]; ok { + value[k8sCommonBean.Port] = port + } } if key == k8sCommonBean.Kind && _type == k8sCommonBean.EndPointsSlice { - value[k8sCommonBean.Port] = endpointSlicePortMapping[serviceName] + if port, ok := endpointSlicePortMapping[serviceName]; ok { + value[k8sCommonBean.Port] = port + } } } }