Skip to content

Commit

Permalink
Merge pull request #1835 from sawsa307/error-state-interface
Browse files Browse the repository at this point in the history
Create Error State Interface
  • Loading branch information
k8s-ci-robot authored Nov 8, 2022
2 parents 8195b0b + 25f4652 commit 839a894
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/neg/syncers/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ type transactionSyncer struct {
enableEndpointSlices bool

logger klog.Logger

// inError indicates if the syncer is in any of 4 error scenarios
// 1. Endpoint counts from EPS is different from calculated endpoint list
// 2. EndpontSlice has missing or invalid data
// 3. Attach/Detach EP fails due to incorrect batch information
// 4. Endpoint count from EPS or calculated endpoint list is 0
// Need to grab syncLock first for any reads or writes based on this value
inError bool
}

func NewTransactionSyncer(
Expand Down Expand Up @@ -136,6 +144,7 @@ func NewTransactionSyncer(
svcNegClient: svcNegClient,
customName: customName,
enableEndpointSlices: enableEndpointSlices,
inError: false,
logger: logger,
}
// Syncer implements life cycle logic
Expand Down Expand Up @@ -184,6 +193,12 @@ func (s *transactionSyncer) syncInternal() error {
}

func (s *transactionSyncer) syncInternalImpl() error {
// TODO(cheungdavid): for now we reset the boolean so it is a no-op, but
// in the future, it will be used to trigger degraded mode if the syncer is in error state.
if s.inErrorState() {
s.resetErrorState()
}

if s.needInit || s.isZoneChange() {
if err := s.ensureNetworkEndpointGroups(); err != nil {
return err
Expand Down Expand Up @@ -281,6 +296,21 @@ func (s *transactionSyncer) syncInternalImpl() error {
return s.syncNetworkEndpoints(addEndpoints, removeEndpoints)
}

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

// syncLock must already be acquired before execution
func (s *transactionSyncer) setErrorState() {
s.inError = true
}

// syncLock must already be acquired before execution
func (s *transactionSyncer) resetErrorState() {
s.inError = false
}

// ensureNetworkEndpointGroups ensures NEGs are created and configured correctly in the corresponding zones.
func (s *transactionSyncer) ensureNetworkEndpointGroups() error {
var err error
Expand Down

0 comments on commit 839a894

Please sign in to comment.