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

Fix GenerateName in test #301

Merged
merged 1 commit into from
Oct 29, 2019
Merged

Fix GenerateName in test #301

merged 1 commit into from
Oct 29, 2019

Conversation

mkmik
Copy link
Collaborator

@mkmik mkmik commented Oct 29, 2019

Currently the controller tests are plagued by:

Failed to generate new key : secrets "" already exists

which is caused by the tests creating secrets with empty Name assuming that GenerateName will issue a new name. Unfortunately the fake client doesn't honour GenerateName. According to kubernetes/client-go#439 users are supposed to implement this in their own testing code, so here we are.

I need this in order to implement the test for #299

@mkmik mkmik requested a review from atomatt October 29, 2019 16:18
func generateNameReactor(action ktesting.Action) (handled bool, ret runtime.Object, err error) {
s := action.(ktesting.CreateAction).GetObject().(*v1.Secret)
if s.Name == "" && s.GenerateName != "" {
s.Name = fmt.Sprintf("%s-%d", s.GenerateName, mathrand.Intn(10000))
Copy link

@atomatt atomatt Oct 29, 2019

Choose a reason for hiding this comment

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

This is probably good enough but may cause super weird failures if the same int is generated 2+ times.

Maybe it would be better to use a per-test generator? Would a simple counter then be sufficient to provide uniqueness?

But if you stick with rand, does it need to be Seeded?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

what if we just use the same random string function that k8s uses to generate ranm pod names? (yes there is still the theoretical chance of conflict, but if that was the only source of flakiness I think I can live with that)

Copy link

Choose a reason for hiding this comment

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

Works for me. I really just wanted to point out the potential issue in case it was likely to cause issues.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah indeed 1000 was too small a number

@mkmik
Copy link
Collaborator Author

mkmik commented Oct 29, 2019

image

travis is having an hiccup; I'm optimistic and merging this manually

@mkmik mkmik merged commit 4c05572 into master Oct 29, 2019
@mkmik mkmik deleted the fixsecret branch October 29, 2019 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants