-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Syncer Skeleton #509
Add Syncer Skeleton #509
Conversation
f66130e
to
68e38a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First round of comments.
pkg/neg/syncers/noop.go
Outdated
|
||
// noopNegSyncer is a NEG syncer template. | ||
// It handles state transitions and backoff retry operations. | ||
type noopNegSyncer struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the biggest fan of calling this noopNegSyncer.
I would just call this Syncer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM
pkg/neg/syncers/noop.go
Outdated
backoff backoffHandler | ||
} | ||
|
||
func newNoopSyncer(negSyncerKey NegSyncerKey, networkEndpointGroupName string, serviceLister cache.Indexer, recorder record.EventRecorder) *noopNegSyncer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make more sense to pass in a RecordProducer? (see pkg/events)
Right now the ControllerContext implements that interface so in whatever code calls newNoopSyncer, you can just pass a context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. That sounds good.
But not sure why there is recorder per namespace
pkg/neg/syncers/noop.go
Outdated
type noopNegSyncer struct { | ||
// metadata | ||
NegSyncerKey | ||
negName string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like NegSyncerKey contains the name so how come you need negName?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NegSyncerKey
contains the name, namespace, port of the service
pkg/neg/syncers/noop.go
Outdated
|
||
// syncer states | ||
stateLock sync.Mutex | ||
stopped bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest abstracting these states into a type like:
type SyncState int
const (
StateStopped SyncState = iota
StateShuttingDown SyncState
...
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then I only have one variable to store state, right?
when state == ShuttingDown
. Should IsStopped
return true?
Otherwise, it would be the same as having 2 booleans.
pkg/neg/syncers/noop.go
Outdated
} | ||
} | ||
|
||
func (s *noopNegSyncer) Sync() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who would call Sync()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SyncerManager
pkg/neg/syncers/noop.go
Outdated
} | ||
} | ||
|
||
func (s *noopNegSyncer) IsStopped() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these need to be exposed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Because the SyncerManager calls it.
pkg/neg/syncers/noop_test.go
Outdated
t.Fatalf("Failed to start syncer: %v", err) | ||
} | ||
|
||
if err := wait.PollImmediate(time.Second, 30*time.Second, func() (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestion would be to make the retry handler an interface and then implement a fake which retries at a much faster pace. That way, unit test completion won't be blocked on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a block/unblock mechanism for the tester.
But it still needs to poll for a few seconds just to make sure the other go routine can execute completely. This is to make sure the test does not flak.
4e1b54a
to
f949f9c
Compare
Ready for another round. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: freehan, rramkumar1 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
The syncer skeleton contains all the mechanism that handles syncer life cycle, including
cc @agau4779