-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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 token controller keyFunc bug #68119
fix token controller keyFunc bug #68119
Conversation
/assign mikedanese |
239bf62
to
6f1dfa6
Compare
/retest |
@awly PTAL thanks |
pkg/kubelet/token/token_manager.go
Outdated
return "", fmt.Errorf("bound object was nil for tr: %#v", tr) | ||
} | ||
|
||
specKey := fmt.Sprintf("%#v:%d:%#v", tr.Spec.Audiences, *tr.Spec.ExpirationSeconds, *tr.Spec.BoundObjectRef) |
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.
Call fmt.Sprintf only once, with all of the vars.
Also, any reason to use :
here as separator vs /
below?
pkg/kubelet/token/token_manager.go
Outdated
func keyFunc(name, namespace string, tr *authenticationv1.TokenRequest) string { | ||
return fmt.Sprintf("%q/%q/%#v", name, namespace, tr.Spec) | ||
func keyFunc(name, namespace string, tr *authenticationv1.TokenRequest) (string, error) { | ||
if tr.Spec.ExpirationSeconds == nil { |
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 don't think this should return error just because dereferencing the pointers would panic. Declare vars with empty values for these fields and set them if fields aren't nil.
_, hit := mgr.get(getKey(c.target)) | ||
|
||
if hit != c.shouldHit { | ||
t.Errorf("%s: got unexpected hit result", c.name) |
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.
Add hit/shouldHit to the message
ExpirationSeconds: getInt64Point(2000), | ||
BoundObjectRef: &authenticationv1.BoundObjectReference{ | ||
Kind: "pod", | ||
APIVersion: "", |
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.
Remove this line on all TokenRequests
@@ -221,3 +221,197 @@ func TestCleanup(t *testing.T) { | |||
}) | |||
} | |||
} | |||
|
|||
type tokenRequestUnit struct { |
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.
Move this into TestKeyFunc
6f1dfa6
to
a329709
Compare
@awly comments addressed, PTAL |
pkg/kubelet/token/token_manager.go
Outdated
@@ -147,5 +148,16 @@ func (m *Manager) requiresRefresh(tr *authenticationv1.TokenRequest) bool { | |||
|
|||
// keys should be nonconfidential and safe to log | |||
func keyFunc(name, namespace string, tr *authenticationv1.TokenRequest) string { | |||
return fmt.Sprintf("%q/%q/%#v", name, namespace, tr.Spec) | |||
if tr.Spec.ExpirationSeconds == nil { |
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 don't like that this modifies the the provided token request. I pushed a change that fixes that.
…name, namespace, tr.Spec)`. Since tr.Spec contains point fields, new token request would not reuse the cache at all. This patch fix this, also adds unit test. Signed-off-by: Mike Danese <mikedanese@google.com>
a329709
to
794e665
Compare
/lgtm |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: awly, mikedanese, WanLinghao 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 |
@WanLinghao I pushed a slight change since I want to get this into 1.12. You are preserved as the author. Thanks for finding this! |
/test all [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue (batch tested with PRs 68119, 68191). If you want to cherry-pick this change to another branch, please follow the instructions here: https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md. |
@WanLinghao: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Currently, token manager use keyFunc like:
fmt.Sprintf("%q/%q/%#v", name, namespace, tr.Spec)
.Since tr.Spec contains point fields, new token request would not reuse the cache at all.
This patch fix this, also adds unit test.