Skip to content
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

Merged
merged 1 commit into from
Nov 14, 2018
Merged

Add Syncer Skeleton #509

merged 1 commit into from
Nov 14, 2018

Conversation

freehan
Copy link
Contributor

@freehan freehan commented Oct 2, 2018

The syncer skeleton contains all the mechanism that handles syncer life cycle, including

  • Start/Stop
  • Sync signal handling, reporting error and retry handling
  • The syncer only requires the extension struct to provide the sync function.

cc @agau4779

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 2, 2018
@freehan freehan force-pushed the noop branch 2 times, most recently from f66130e to 68e38a0 Compare October 15, 2018 22:43
@freehan freehan mentioned this pull request Nov 2, 2018
Copy link
Contributor

@rramkumar1 rramkumar1 left a 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.


// noopNegSyncer is a NEG syncer template.
// It handles state transitions and backoff retry operations.
type noopNegSyncer struct {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

backoff backoffHandler
}

func newNoopSyncer(negSyncerKey NegSyncerKey, networkEndpointGroupName string, serviceLister cache.Indexer, recorder record.EventRecorder) *noopNegSyncer {
Copy link
Contributor

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.

Copy link
Contributor Author

@freehan freehan Nov 13, 2018

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

type noopNegSyncer struct {
// metadata
NegSyncerKey
negName string
Copy link
Contributor

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?

Copy link
Contributor Author

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


// syncer states
stateLock sync.Mutex
stopped bool
Copy link
Contributor

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
...
)

Copy link
Contributor Author

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.

}
}

func (s *noopNegSyncer) Sync() bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who would call Sync()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SyncerManager

}
}

func (s *noopNegSyncer) IsStopped() bool {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

t.Fatalf("Failed to start syncer: %v", err)
}

if err := wait.PollImmediate(time.Second, 30*time.Second, func() (bool, error) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@freehan freehan force-pushed the noop branch 4 times, most recently from 4e1b54a to f949f9c Compare November 13, 2018 20:02
@freehan freehan changed the title Add a noop Syncer Add Syncer Skeleton Nov 13, 2018
@freehan
Copy link
Contributor Author

freehan commented Nov 13, 2018

Ready for another round.

@rramkumar1
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 14, 2018
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit c17650e into kubernetes:master Nov 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants