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

Wait until stores are filled before processing service account token events #8494

Merged
merged 1 commit into from May 21, 2015

Conversation

liggitt
Copy link
Member

@liggitt liggitt commented May 19, 2015

Since the service account tokens controller makes use of two stores, getting update events from the initial list operations caused misses if the other store wasn't populated yet. This adds a gate to prevent that.

@liggitt
Copy link
Member Author

liggitt commented May 19, 2015

@lavalamp PTAL. If there's a better way to coordinate two stores, I'd be happy to switch to it

@lavalamp
Copy link
Member

Yeah-- I know there's a general need to tell when a store has been initially populated.

This particular solution is not one I'd like to see copied everywhere (you know people will do that if it shows up in the codebase somewhere). (Also--I'm pretty sure the race detector is going to flag this.)

I have two ideas:

  1. Add plumbing to expose the last sync version; testing if it's not empty should do the trick. https://github.com/GoogleCloudPlatform/kubernetes/blob/master/pkg/client/cache/reflector.go#L148
  2. Add a HasSynced() bool method to Store which returns false until Replace() is called, and then afterwards returns true.

@liggitt liggitt force-pushed the gate_tokens_controller branch 2 times, most recently from 3cd33bb to 3b9ba54 Compare May 20, 2015 01:29
@liggitt
Copy link
Member Author

liggitt commented May 20, 2015

I combined your ideas and created HasSynced() on Controller... the warnings about thread-safety on LastSyncResourceVersion() made me leery of exposing an exact version for people to rely on. PTAL

@liggitt
Copy link
Member Author

liggitt commented May 20, 2015

You win the data race prediction:

WARNING: DATA RACE
Read by goroutine 247:
  github.com/GoogleCloudPlatform/kubernetes/pkg/controller/framework.(*Controller).HasSynced()

@liggitt
Copy link
Member Author

liggitt commented May 20, 2015

Guarded the lastSyncResourceVersion field with a RWMutex to prevent data races, but didn't pursue synchronizing with the underlying store.

@@ -112,6 +115,9 @@ type TokensController struct {
// Since we join two objects, we'll watch both of them with controllers.
serviceAccountController *framework.Controller
secretController *framework.Controller

serviceAccountsSynced func() bool
Copy link
Member

Choose a reason for hiding this comment

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

nit: // These are here so tests can inject a 'return true'.

@lavalamp
Copy link
Member

LGTM, but you should fix the (still remaining) data race.

@derekwaynecarr
Copy link
Member

I thought I was the only one writing controllers that needed to work against more than one store :-)

Sent from my iPhone

On May 20, 2015, at 5:59 PM, Daniel Smith notifications@github.com wrote:

LGTM, but you should fix the (still remaining) data race.


Reply to this email directly or view it on GitHub.

@liggitt
Copy link
Member Author

liggitt commented May 21, 2015

needed a mutex around the reflector nil check in HasSynced(). Added and testing comment added

@liggitt
Copy link
Member Author

liggitt commented May 21, 2015

Travis flaked on TestPersistentVolumeClaimBinder, but passed the data race checks

@lavalamp
Copy link
Member

LGTM

@lavalamp lavalamp added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 21, 2015
lavalamp added a commit that referenced this pull request May 21, 2015
Wait until stores are filled before processing service account token events
@lavalamp lavalamp merged commit 80c3506 into kubernetes:master May 21, 2015
@liggitt liggitt deleted the gate_tokens_controller branch May 23, 2015 20:07
@lavalamp lavalamp self-assigned this May 3, 2016
k8s-github-robot pushed a commit that referenced this pull request May 5, 2016
Automatic merge from submit-queue

remove inappropriate time.Sleep

Fixes #24815

@liggitt since you added this in #8494 :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants