Skip to content

Commit

Permalink
Merge pull request #1661 from freehan/fix-omg-cp
Browse files Browse the repository at this point in the history
[Cherrypick #1660 into release-1.14] Fix unhandled err variable
  • Loading branch information
k8s-ci-robot authored Jan 28, 2022
2 parents e655569 + 09e1134 commit c3fd8a5
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions pkg/neg/syncers/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,15 @@ func (s *transactionSyncer) syncInternal() error {
s.syncLock.Lock()
defer s.syncLock.Unlock()

// NOTE: Error will be used to update the status on corresponding Neg CR if Neg CRD is enabled
// Please reuse and set err before returning
var err error
defer s.updateStatus(err)
start := time.Now()
defer metrics.PublishNegSyncMetrics(string(s.NegSyncerKey.NegType), string(s.endpointsCalculator.Mode()), err, start)
err := s.syncInternalImpl()

s.updateStatus(err)
metrics.PublishNegSyncMetrics(string(s.NegSyncerKey.NegType), string(s.endpointsCalculator.Mode()), err, start)
return err
}

func (s *transactionSyncer) syncInternalImpl() error {
if s.needInit || s.isZoneChange() {
if err := s.ensureNetworkEndpointGroups(); err != nil {
return err
Expand Down Expand Up @@ -218,6 +220,9 @@ func (s *transactionSyncer) syncInternal() error {
}
endpointsData := negtypes.EndpointsDataFromEndpointSlices(endpointSlices)
targetMap, endpointPodMap, err = s.endpointsCalculator.CalculateEndpoints(endpointsData, currentMap)
if err != nil {
return fmt.Errorf("endpoints calculation error in mode %q, err: %w", s.endpointsCalculator.Mode(), err)
}
} else {
ep, exists, err := s.endpointLister.Get(
&apiv1.Endpoints{
Expand All @@ -236,12 +241,11 @@ func (s *transactionSyncer) syncInternal() error {
}
endpointsData := negtypes.EndpointsDataFromEndpoints(ep.(*apiv1.Endpoints))
targetMap, endpointPodMap, err = s.endpointsCalculator.CalculateEndpoints(endpointsData, currentMap)
if err != nil {
return fmt.Errorf("endpoints calculation error in mode %q, err: %w", s.endpointsCalculator.Mode(), err)
}
}

if err != nil {
err = fmt.Errorf("endpoints calculation error in mode %q, err: %w", s.endpointsCalculator.Mode(), err)
return err
}
s.logStats(targetMap, "desired NEG endpoints")

// Calculate the endpoints to add and delete to transform the current state to desire state
Expand All @@ -268,9 +272,7 @@ func (s *transactionSyncer) syncInternal() error {
s.logEndpoints(addEndpoints, "adding endpoint")
s.logEndpoints(removeEndpoints, "removing endpoint")

// set err instead of returning directly so that synced condition on neg crd is properly updated in defer
err = s.syncNetworkEndpoints(addEndpoints, removeEndpoints)
return err
return s.syncNetworkEndpoints(addEndpoints, removeEndpoints)
}

// ensureNetworkEndpointGroups ensures NEGs are created and configured correctly in the corresponding zones.
Expand Down

0 comments on commit c3fd8a5

Please sign in to comment.