Skip to content

Make sure cache Reader still works #39

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

Merged

Conversation

DirectXMan12
Copy link
Contributor

The cache refactor broke the cache reader implementation (invalid
assumptions about names, arguments, and the way reflection works).
This fixes it, and adds back in some working tests to ensure that
it doesn't break again.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 15, 2018
@DirectXMan12
Copy link
Contributor Author

@pwittrock @droot I'll do some more tests (either here or in a follow-up PR), but here's enough to get started.

Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

Awesome looks good, minor nits.

gvk, err := apiutil.GVKForObject(out, ip.Scheme)
if err != nil {
return err
}

cache, err := ip.InformersMap.Get(gvk, cacheType)
// we need the non-list GVK, so chop off the "List" from the end of the kind
gvk.Kind = gvk.Kind[:len(gvk.Kind)-4]
Copy link
Contributor

Choose a reason for hiding this comment

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

strings.TrimSuffix(gvk.Kind, "List") is more safe for this use-case ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd argue that it's less correct. We have an invariant that you must pass a list type, and the list type must be of name FooList. We should either error out or panic if that's not the case, but failing silently (like what we do here, or your suggestion) is probably not the right answer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thats fair point.

cacheTypeObj, ok := cacheTypeValue.Interface().(runtime.Object)
if !ok {
return fmt.Errorf("cannot get cache for %T, its element is not a runtime.Object", out)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Pl. add %T for cacheTypeValue in the error, will help in debugging.

@droot
Copy link
Contributor

droot commented Jun 15, 2018

@DirectXMan12 I can address the comments I posted in follow-up PR if you think you won't have time to get to it today.

@droot
Copy link
Contributor

droot commented Jun 15, 2018

@DirectXMan12 Travis tests are also not passing. complaining about missing some pkgs.

@pwittrock pwittrock closed this Jun 16, 2018
@pwittrock pwittrock reopened this Jun 16, 2018
@pwittrock
Copy link
Contributor

@DirectXMan12 @droot The errors should be legit now. Seem to be linting errors.

@DirectXMan12 DirectXMan12 force-pushed the bug/cache-list-reflection branch from 11eb5ac to a94b0ce Compare June 18, 2018 17:10
@droot
Copy link
Contributor

droot commented Jun 18, 2018

@DirectXMan12 You will have to run "goimports -w" on informer_cache.go to fix the lint error thrown in travis test, then we are good to go.

The cache refactor broke the cache reader implementation (invalid
assumptions about names, arguments, and the way reflection works).
This fixes it, and adds back in some working tests to ensure that
it doesn't break again.
@DirectXMan12 DirectXMan12 force-pushed the bug/cache-list-reflection branch from a94b0ce to 9db07f6 Compare June 18, 2018 17:31
@DirectXMan12
Copy link
Contributor Author

man, that error message from the linter is terrible. It doesn't really say what the problem is.
Should be fixed now.

@droot
Copy link
Contributor

droot commented Jun 18, 2018

@DirectXMan12 Yes, that message it terrible, I ran in to the other day and it took me sometime to figure out what it really meant :)

@droot
Copy link
Contributor

droot commented Jun 18, 2018

/approve

@droot
Copy link
Contributor

droot commented Jun 18, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 18, 2018
@droot droot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 18, 2018
@k8s-ci-robot k8s-ci-robot merged commit 8a087d9 into kubernetes-sigs:master Jun 18, 2018
@DirectXMan12 DirectXMan12 deleted the bug/cache-list-reflection branch August 23, 2018 19:37
justinsb pushed a commit to justinsb/controller-runtime that referenced this pull request Dec 7, 2018
…t-reflection

Make sure cache Reader still works
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