From d7c5692ba225803ff776cff811363802157ed743 Mon Sep 17 00:00:00 2001 From: David Cheung Date: Thu, 13 Oct 2022 22:24:48 +0000 Subject: [PATCH] Create Error State Interface Added error checking functions in transactionSyncer.go for syncer's error state get/set/reset. --- pkg/neg/manager_test.go | 1 + pkg/neg/syncers/syncer.go | 7 +++++++ pkg/neg/syncers/syncer_test.go | 6 ++++++ pkg/neg/syncers/transaction.go | 5 +++++ pkg/neg/types/interfaces.go | 2 ++ 5 files changed, 21 insertions(+) diff --git a/pkg/neg/manager_test.go b/pkg/neg/manager_test.go index ba097f349e..6d06d9f1e8 100644 --- a/pkg/neg/manager_test.go +++ b/pkg/neg/manager_test.go @@ -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 { diff --git a/pkg/neg/syncers/syncer.go b/pkg/neg/syncers/syncer.go index b74291cd31..47f6c63bf5 100644 --- a/pkg/neg/syncers/syncer.go +++ b/pkg/neg/syncers/syncer.go @@ -31,6 +31,9 @@ import ( type syncerCore interface { sync() error + inErrorState() bool + setErrorState() + resetErrorState() } // syncer is a NEG syncer skeleton. @@ -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() +} diff --git a/pkg/neg/syncers/syncer_test.go b/pkg/neg/syncers/syncer_test.go index dd43e52819..4441c24f83 100644 --- a/pkg/neg/syncers/syncer_test.go +++ b/pkg/neg/syncers/syncer_test.go @@ -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() diff --git a/pkg/neg/syncers/transaction.go b/pkg/neg/syncers/transaction.go index e27da180f0..95751cd899 100644 --- a/pkg/neg/syncers/transaction.go +++ b/pkg/neg/syncers/transaction.go @@ -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() diff --git a/pkg/neg/types/interfaces.go b/pkg/neg/types/interfaces.go index e34837730f..bd1f82e3c3 100644 --- a/pkg/neg/types/interfaces.go +++ b/pkg/neg/types/interfaces.go @@ -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