Skip to content

Commit 7297fbd

Browse files
authored
Merge pull request kubernetes#90413 from PurelyApplied/nil-expiry
Improve error message when refresh token expiry is nil.
2 parents 5555cc1 + 5ea1cef commit 7297fbd

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pkg/kubelet/token/token_manager.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ func (m *Manager) expired(t *authenticationv1.TokenRequest) bool {
168168
// ttl, or if the token is older than 24 hours.
169169
func (m *Manager) requiresRefresh(tr *authenticationv1.TokenRequest) bool {
170170
if tr.Spec.ExpirationSeconds == nil {
171-
klog.Errorf("expiration seconds was nil for tr: %#v", tr)
171+
cpy := tr.DeepCopy()
172+
cpy.Status.Token = ""
173+
klog.Errorf("expiration seconds was nil for tr: %#v", cpy)
172174
return false
173175
}
174176
now := m.clock.Now()

pkg/kubelet/token/token_manager_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func TestRequiresRefresh(t *testing.T) {
130130
cases := []struct {
131131
now, exp time.Time
132132
expectRefresh bool
133+
requestTweaks func(*authenticationv1.TokenRequest)
133134
}{
134135
{
135136
now: start.Add(10 * time.Minute),
@@ -151,6 +152,15 @@ func TestRequiresRefresh(t *testing.T) {
151152
exp: start.Add(60 * time.Minute),
152153
expectRefresh: true,
153154
},
155+
{
156+
// expiry will be overwritten by the tweak below.
157+
now: start.Add(0 * time.Minute),
158+
exp: start.Add(60 * time.Minute),
159+
expectRefresh: false,
160+
requestTweaks: func(tr *authenticationv1.TokenRequest) {
161+
tr.Spec.ExpirationSeconds = nil
162+
},
163+
},
154164
}
155165

156166
for i, c := range cases {
@@ -165,6 +175,11 @@ func TestRequiresRefresh(t *testing.T) {
165175
ExpirationTimestamp: metav1.Time{Time: c.exp},
166176
},
167177
}
178+
179+
if c.requestTweaks != nil {
180+
c.requestTweaks(tr)
181+
}
182+
168183
mgr := NewManager(nil)
169184
mgr.clock = clock
170185

0 commit comments

Comments
 (0)