Skip to content

Commit

Permalink
Add EPMissingPod and PodNotFound to be error states
Browse files Browse the repository at this point in the history
  • Loading branch information
sawsa307 committed Mar 21, 2023
1 parent 180c2cb commit 8d0a99d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/neg/syncers/endpoints_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (l *L7EndpointsCalculator) Mode() types.EndpointsCalculatorMode {

// CalculateEndpoints determines the endpoints in the NEGs based on the current service endpoints and the current NEGs.
func (l *L7EndpointsCalculator) CalculateEndpoints(eds []types.EndpointsData, _ map[string]types.NetworkEndpointSet) (map[string]types.NetworkEndpointSet, types.EndpointPodMap, int, error) {
return toZoneNetworkEndpointMap(eds, l.zoneGetter, l.servicePortName, l.networkEndpointType, l.lpConfig)
return toZoneNetworkEndpointMap(eds, l.podLister, l.zoneGetter, l.servicePortName, l.networkEndpointType, l.lpConfig)
}

func nodeMapToString(nodeMap map[string][]*v1.Node) string {
Expand Down
16 changes: 14 additions & 2 deletions pkg/neg/syncers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func ensureNetworkEndpointGroup(svcNamespace, svcName, negName, zone, negService
}

// toZoneNetworkEndpointMap translates addresses in endpoints object into zone and endpoints map, and also return the count for duplicated endpoints
func toZoneNetworkEndpointMap(eds []negtypes.EndpointsData, zoneGetter negtypes.ZoneGetter, servicePortName string, networkEndpointType negtypes.NetworkEndpointType, lpConfig negtypes.PodLabelPropagationConfig) (map[string]negtypes.NetworkEndpointSet, negtypes.EndpointPodMap, int, error) {
func toZoneNetworkEndpointMap(eds []negtypes.EndpointsData, podLister cache.Indexer, zoneGetter negtypes.ZoneGetter, servicePortName string, networkEndpointType negtypes.NetworkEndpointType, lpConfig negtypes.PodLabelPropagationConfig) (map[string]negtypes.NetworkEndpointSet, negtypes.EndpointPodMap, int, error) {
zoneNetworkEndpointMap := map[string]negtypes.NetworkEndpointSet{}
networkEndpointPodMap := negtypes.EndpointPodMap{}
dupCount := 0
Expand Down Expand Up @@ -255,8 +255,20 @@ func toZoneNetworkEndpointMap(eds []negtypes.EndpointsData, zoneGetter negtypes.
}
if endpointAddress.TargetRef == nil {
klog.V(2).Infof("Endpoint %q in Endpoints %s/%s does not have an associated pod. Skipping", endpointAddress.Addresses, ed.Meta.Namespace, ed.Meta.Name)
continue
return nil, nil, dupCount, negtypes.ErrEPMissingPod
}
key := fmt.Sprintf("%s/%s", endpointAddress.TargetRef.Namespace, endpointAddress.TargetRef.Name)
obj, exists, err := podLister.GetByKey(key)
if err != nil || !exists {
klog.V(2).Infof("Endpoint %q in Endpoints %s/%s does not correspond to an existing pod. Skipping", endpointAddress.Addresses, ed.Meta.Namespace, ed.Meta.Name)
return nil, nil, dupCount, negtypes.ErrPodNotFound
}
_, ok := obj.(*apiv1.Pod)
if !ok {
klog.V(2).Infof("Endpoint %q in Endpoints %s/%s does not correspond to an existing pod. Skipping", endpointAddress.Addresses, ed.Meta.Namespace, ed.Meta.Name)
return nil, nil, dupCount, negtypes.ErrPodNotFound
}

zone, err := zoneGetter.GetZoneForNode(*endpointAddress.NodeName)
if err != nil {
return nil, nil, dupCount, negtypes.ErrNodeNotFound
Expand Down
6 changes: 6 additions & 0 deletions pkg/neg/types/sync_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import "errors"
const (
ResultEPCountsDiffer = "EPCountsDiffer"
ResultEPMissingNodeName = "EPMissingNodeName"
ResultEPMissingPod = "EPMissingPod"
ResultNodeNotFound = "NodeNotFound"
ResultPodNotFound = "PodNotFound"
ResultEPMissingZone = "EPMissingZone"
ResultEPSEndpointCountZero = "EPSEndpointCountZero"
ResultEPCalculationCountZero = "EPCalculationCountZero"
Expand All @@ -38,7 +40,9 @@ const (
var (
ErrEPCountsDiffer = errors.New("endpoint counts from endpointData and endpointPodMap differ")
ErrEPMissingNodeName = errors.New("endpoint has empty nodeName field")
ErrEPMissingPod = errors.New("endpoint has empty pod field")
ErrNodeNotFound = errors.New("failed to retrieve associated node of the endpoint")
ErrPodNotFound = errors.New("failed to retrieve associated pod of the endpoint")
ErrEPMissingZone = errors.New("endpoint has empty zone field")
ErrEPSEndpointCountZero = errors.New("endpoint count from endpointData cannot be zero")
ErrEPCalculationCountZero = errors.New("endpoint count from endpointPodMap cannot be zero")
Expand All @@ -49,8 +53,10 @@ var (
// use this map for conversion between errors and sync results
ErrorStateResult = map[error]string{
ErrEPMissingNodeName: ResultEPMissingNodeName,
ErrEPMissingPod: ResultEPMissingPod,
ErrEPMissingZone: ResultEPMissingZone,
ErrNodeNotFound: ResultNodeNotFound,
ErrPodNotFound: ResultNodeNotFound,
ErrEPCalculationCountZero: ResultEPCalculationCountZero,
ErrEPSEndpointCountZero: ResultEPSEndpointCountZero,
ErrEPCountsDiffer: ResultEPCountsDiffer,
Expand Down

0 comments on commit 8d0a99d

Please sign in to comment.