Skip to content

Commit

Permalink
Create Error State Interface
Browse files Browse the repository at this point in the history
Added error checking functions in transactionSyncer.go for syncer's
error state get/set/reset.
  • Loading branch information
sawsa307 committed Oct 20, 2022
1 parent d745701 commit d7c5692
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/neg/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,7 @@ func (s *fakeSyncer) Stop() {}
func (s *fakeSyncer) Sync() bool { return s.syncFunc() }
func (s *fakeSyncer) IsStopped() bool { return s.isStopped }
func (s *fakeSyncer) IsShuttingDown() bool { return false }
func (s *fakeSyncer) InErrorState() bool { return false }

// getNegObjectRefs generates the NegObjectReference list of all negs with the specified negName in the specified zones
func getNegObjectRefs(t *testing.T, cloud negtypes.NetworkEndpointGroupCloud, zones []string, negName string, version meta.Version) []negv1beta1.NegObjectReference {
Expand Down
7 changes: 7 additions & 0 deletions pkg/neg/syncers/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import (

type syncerCore interface {
sync() error
inErrorState() bool
setErrorState()
resetErrorState()
}

// syncer is a NEG syncer skeleton.
Expand Down Expand Up @@ -164,3 +167,7 @@ func (s *syncer) IsShuttingDown() bool {
defer s.stateLock.Unlock()
return s.shuttingDown
}

func (s *syncer) InErrorState() bool {
return s.core.inErrorState()
}
6 changes: 6 additions & 0 deletions pkg/neg/syncers/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ func (t *syncerTester) sync() error {
return nil
}

func (t *syncerTester) inErrorState() bool { return false }

func (t *syncerTester) setErrorState() {}

func (t *syncerTester) resetErrorState() {}

func newSyncerTester() *syncerTester {
testNegName := "test-neg-name"
testContext := negtypes.NewTestContext()
Expand Down
5 changes: 5 additions & 0 deletions pkg/neg/syncers/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ func (s *transactionSyncer) sync() error {
}

func (s *transactionSyncer) syncInternal() error {
// TODO: enter degraded mode before reset and sync
if s.inErrorState() {
s.resetErrorState()
}

s.syncLock.Lock()
defer s.syncLock.Unlock()

Expand Down
2 changes: 2 additions & 0 deletions pkg/neg/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ type NegSyncer interface {
IsStopped() bool
// IsShuttingDown returns true if syncer is shutting down
IsShuttingDown() bool
// InErrorState returns true if syncer is in error state
InErrorState() bool
}

// NegSyncerManager is an interface for controllers to manage syncer
Expand Down

0 comments on commit d7c5692

Please sign in to comment.