mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
Check for initial kubelet certificates more frequently
This commit is contained in:
parent
4db6bde859
commit
933494ab8d
@ -22,6 +22,8 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
@ -97,7 +99,16 @@ func addCertRotation(stopCh <-chan struct{}, period time.Duration, clientConfig
|
|||||||
|
|
||||||
lastCertAvailable := time.Now()
|
lastCertAvailable := time.Now()
|
||||||
lastCert := clientCertificateManager.Current()
|
lastCert := clientCertificateManager.Current()
|
||||||
go wait.Until(func() {
|
|
||||||
|
var hasCert atomic.Bool
|
||||||
|
hasCert.Store(lastCert != nil)
|
||||||
|
|
||||||
|
checkLock := &sync.Mutex{}
|
||||||
|
checkNewCertificateAndRotate := func() {
|
||||||
|
// don't run concurrently
|
||||||
|
checkLock.Lock()
|
||||||
|
defer checkLock.Unlock()
|
||||||
|
|
||||||
curr := clientCertificateManager.Current()
|
curr := clientCertificateManager.Current()
|
||||||
|
|
||||||
if exitAfter > 0 {
|
if exitAfter > 0 {
|
||||||
@ -131,6 +142,7 @@ func addCertRotation(stopCh <-chan struct{}, period time.Duration, clientConfig
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
lastCert = curr
|
lastCert = curr
|
||||||
|
hasCert.Store(lastCert != nil)
|
||||||
|
|
||||||
klog.InfoS("Certificate rotation detected, shutting down client connections to start using new credentials")
|
klog.InfoS("Certificate rotation detected, shutting down client connections to start using new credentials")
|
||||||
// The cert has been rotated. Close all existing connections to force the client
|
// The cert has been rotated. Close all existing connections to force the client
|
||||||
@ -138,7 +150,18 @@ func addCertRotation(stopCh <-chan struct{}, period time.Duration, clientConfig
|
|||||||
//
|
//
|
||||||
// See: https://github.com/kubernetes-incubator/bootkube/pull/663#issuecomment-318506493
|
// See: https://github.com/kubernetes-incubator/bootkube/pull/663#issuecomment-318506493
|
||||||
d.CloseAll()
|
d.CloseAll()
|
||||||
}, period, stopCh)
|
}
|
||||||
|
|
||||||
|
// start long-term check
|
||||||
|
go wait.Until(checkNewCertificateAndRotate, period, stopCh)
|
||||||
|
|
||||||
|
if !hasCert.Load() {
|
||||||
|
// start a faster check until we get the initial certificate
|
||||||
|
go wait.PollUntil(time.Second, func() (bool, error) {
|
||||||
|
checkNewCertificateAndRotate()
|
||||||
|
return hasCert.Load(), nil
|
||||||
|
}, stopCh)
|
||||||
|
}
|
||||||
|
|
||||||
clientConfig.Transport = utilnet.SetTransportDefaults(&http.Transport{
|
clientConfig.Transport = utilnet.SetTransportDefaults(&http.Transport{
|
||||||
Proxy: http.ProxyFromEnvironment,
|
Proxy: http.ProxyFromEnvironment,
|
||||||
|
Loading…
Reference in New Issue
Block a user