mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Merge pull request #90413 from PurelyApplied/nil-expiry
Improve error message when refresh token expiry is nil.
This commit is contained in:
commit
7297fbd0ce
@ -168,7 +168,9 @@ func (m *Manager) expired(t *authenticationv1.TokenRequest) bool {
|
|||||||
// ttl, or if the token is older than 24 hours.
|
// ttl, or if the token is older than 24 hours.
|
||||||
func (m *Manager) requiresRefresh(tr *authenticationv1.TokenRequest) bool {
|
func (m *Manager) requiresRefresh(tr *authenticationv1.TokenRequest) bool {
|
||||||
if tr.Spec.ExpirationSeconds == nil {
|
if tr.Spec.ExpirationSeconds == nil {
|
||||||
klog.Errorf("expiration seconds was nil for tr: %#v", tr)
|
cpy := tr.DeepCopy()
|
||||||
|
cpy.Status.Token = ""
|
||||||
|
klog.Errorf("expiration seconds was nil for tr: %#v", cpy)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
now := m.clock.Now()
|
now := m.clock.Now()
|
||||||
|
@ -130,6 +130,7 @@ func TestRequiresRefresh(t *testing.T) {
|
|||||||
cases := []struct {
|
cases := []struct {
|
||||||
now, exp time.Time
|
now, exp time.Time
|
||||||
expectRefresh bool
|
expectRefresh bool
|
||||||
|
requestTweaks func(*authenticationv1.TokenRequest)
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
now: start.Add(10 * time.Minute),
|
now: start.Add(10 * time.Minute),
|
||||||
@ -151,6 +152,15 @@ func TestRequiresRefresh(t *testing.T) {
|
|||||||
exp: start.Add(60 * time.Minute),
|
exp: start.Add(60 * time.Minute),
|
||||||
expectRefresh: true,
|
expectRefresh: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// expiry will be overwritten by the tweak below.
|
||||||
|
now: start.Add(0 * time.Minute),
|
||||||
|
exp: start.Add(60 * time.Minute),
|
||||||
|
expectRefresh: false,
|
||||||
|
requestTweaks: func(tr *authenticationv1.TokenRequest) {
|
||||||
|
tr.Spec.ExpirationSeconds = nil
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, c := range cases {
|
for i, c := range cases {
|
||||||
@ -165,6 +175,11 @@ func TestRequiresRefresh(t *testing.T) {
|
|||||||
ExpirationTimestamp: metav1.Time{Time: c.exp},
|
ExpirationTimestamp: metav1.Time{Time: c.exp},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.requestTweaks != nil {
|
||||||
|
c.requestTweaks(tr)
|
||||||
|
}
|
||||||
|
|
||||||
mgr := NewManager(nil)
|
mgr := NewManager(nil)
|
||||||
mgr.clock = clock
|
mgr.clock = clock
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user