@@ -57,6 +57,7 @@ import (
57
57
"k8s.io/client-go/tools/record"
58
58
certutil "k8s.io/client-go/util/cert"
59
59
"k8s.io/client-go/util/certificate"
60
+ "k8s.io/client-go/util/connrotation"
60
61
"k8s.io/client-go/util/keyutil"
61
62
cloudprovider "k8s.io/cloud-provider"
62
63
cliflag "k8s.io/component-base/cli/flag"
@@ -567,6 +568,9 @@ func run(s *options.KubeletServer, kubeDeps *kubelet.Dependencies, stopCh <-chan
567
568
if err != nil {
568
569
return err
569
570
}
571
+ if closeAllConns == nil {
572
+ return errors .New ("closeAllConns must be a valid function other than nil" )
573
+ }
570
574
kubeDeps .OnHeartbeatFailure = closeAllConns
571
575
572
576
kubeDeps .KubeClient , err = clientset .NewForConfig (clientConfig )
@@ -806,8 +810,21 @@ func buildKubeletClientConfig(s *options.KubeletServer, nodeName types.NodeName)
806
810
}
807
811
808
812
kubeClientConfigOverrides (s , clientConfig )
813
+ closeAllConns , err := updateDialer (clientConfig )
814
+ if err != nil {
815
+ return nil , nil , err
816
+ }
817
+ return clientConfig , closeAllConns , nil
818
+ }
809
819
810
- return clientConfig , nil , nil
820
+ // updateDialer instruments a restconfig with a dial. the returned function allows forcefully closing all active connections.
821
+ func updateDialer (clientConfig * restclient.Config ) (func (), error ) {
822
+ if clientConfig .Transport != nil || clientConfig .Dial != nil {
823
+ return nil , fmt .Errorf ("there is already a transport or dialer configured" )
824
+ }
825
+ d := connrotation .NewDialer ((& net.Dialer {Timeout : 30 * time .Second , KeepAlive : 30 * time .Second }).DialContext )
826
+ clientConfig .Dial = d .DialContext
827
+ return d .CloseAll , nil
811
828
}
812
829
813
830
// buildClientCertificateManager creates a certificate manager that will use certConfig to request a client certificate
0 commit comments