Skip to content

Commit

Permalink
Create skeleton for degraded mode procedure
Browse files Browse the repository at this point in the history
Create skeleton for degraded mode procedure
  • Loading branch information
sawsa307 committed Feb 14, 2023
1 parent 8ed95f6 commit 3bce024
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions pkg/neg/syncers/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ func (s *transactionSyncer) syncInternalImpl() error {
endpointSlices[i] = slice.(*discovery.EndpointSlice)
}
if s.inErrorState() {
targetMap, endpointPodMap, err = s.computeTargetMapInDegradedMode(endpointSlices)
if err != nil {
return err
}
s.resetErrorState()
} else {
targetMap, endpointPodMap, err = s.computeTargetMap(endpointSlices)
Expand Down Expand Up @@ -314,6 +318,47 @@ func (s *transactionSyncer) computeTargetMap(endpointSlices []*discovery.Endpoin
return targetMap, endpointPodMap, err
}

// degradedMode does endpoint calculation differently to fix the error in NEG controller
func (s *transactionSyncer) computeTargetMapInDegradedMode(slices []*discovery.EndpointSlice) (map[string]negtypes.NetworkEndpointSet, negtypes.EndpointPodMap, error) {
var targetMap map[string]negtypes.NetworkEndpointSet
var endpointPodMap negtypes.EndpointPodMap
var err error

for _, slice := range slices {
// if it is a custom endpoint slice, don't include it
// so it won't block the neg api call from succeeding
if val, ok := slice.ObjectMeta.Labels[discovery.LabelManagedBy]; !ok || val != "endpointslice-controller.k8s.io" {
continue
}

for _, ep := range slice.Endpoints {
if ep.TargetRef == nil {
continue
}
networkEndpoint, valid := s.validateEndpoint(ep)
if valid {
zone, err := s.zoneGetter.GetZoneForNode(networkEndpoint.Node)
if err != nil {
continue
}
if targetMap[zone] == nil {
targetMap[zone] = negtypes.NewNetworkEndpointSet()
}
targetMap[zone].Insert(networkEndpoint)
endpointPodMap[networkEndpoint] = types.NamespacedName{Namespace: ep.TargetRef.Namespace, Name: ep.TargetRef.Name}
}
}
}
return targetMap, endpointPodMap, err
}

// validateEndpoint fill in endpoint's nodeName if missing,
// validate it against the nodeName from the pod
// and determine whether it should be kept based on the pod
func (s *transactionSyncer) validateEndpoint(ep discovery.Endpoint) (negtypes.NetworkEndpoint, bool) {
return negtypes.NetworkEndpoint{}, true
}

// syncLock must already be acquired before execution
func (s *transactionSyncer) inErrorState() bool {
return s.inError
Expand Down

0 comments on commit 3bce024

Please sign in to comment.