-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Make sure cache Reader still works #39
Conversation
@pwittrock @droot I'll do some more tests (either here or in a follow-up PR), but here's enough to get started. |
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.
Awesome looks good, minor nits.
pkg/cache/informer_cache.go
Outdated
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] |
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.
strings.TrimSuffix(gvk.Kind, "List")
is more safe for this use-case ?
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'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.
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.
Thats fair point.
pkg/cache/informer_cache.go
Outdated
cacheTypeObj, ok := cacheTypeValue.Interface().(runtime.Object) | ||
if !ok { | ||
return fmt.Errorf("cannot get cache for %T, its element is not a runtime.Object", out) | ||
} |
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.
Pl. add %T for cacheTypeValue in the error, will help in debugging.
@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. |
@DirectXMan12 Travis tests are also not passing. complaining about missing some pkgs. |
@DirectXMan12 @droot The errors should be legit now. Seem to be linting errors. |
11eb5ac
to
a94b0ce
Compare
@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.
a94b0ce
to
9db07f6
Compare
man, that error message from the linter is terrible. It doesn't really say what the problem is. |
@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 :) |
/approve |
/lgtm |
…t-reflection Make sure cache Reader still works
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.