@@ -737,20 +737,28 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
737
737
klet .statusManager = status .NewManager (klet .kubeClient , klet .podManager , klet )
738
738
739
739
if utilfeature .DefaultFeatureGate .Enabled (features .RotateKubeletServerCertificate ) && kubeDeps .TLSOptions != nil {
740
- var ips []net.IP
741
- cfgAddress := net .ParseIP (kubeCfg .Address )
742
- if cfgAddress == nil || cfgAddress .IsUnspecified () {
740
+ var (
741
+ ips []net.IP
742
+ names []string
743
+ )
744
+
745
+ // If the address was explicitly configured, use that. Otherwise, try to
746
+ // discover addresses from the cloudprovider. Otherwise, make a best guess.
747
+ if cfgAddress := net .ParseIP (kubeCfg .Address ); cfgAddress != nil && ! cfgAddress .IsUnspecified () {
748
+ ips = []net.IP {cfgAddress }
749
+ names = []string {klet .GetHostname (), hostnameOverride }
750
+ } else if len (cloudIPs ) != 0 || len (cloudNames ) != 0 {
751
+ ips = cloudIPs
752
+ names = cloudNames
753
+ } else {
743
754
localIPs , err := allGlobalUnicastIPs ()
744
755
if err != nil {
745
756
return nil , err
746
757
}
747
758
ips = localIPs
748
- } else {
749
- ips = []net.IP {cfgAddress }
759
+ names = []string {klet .GetHostname (), hostnameOverride }
750
760
}
751
761
752
- ips = append (ips , cloudIPs ... )
753
- names := append ([]string {klet .GetHostname (), hostnameOverride }, cloudNames ... )
754
762
klet .serverCertificateManager , err = kubeletcertificate .NewKubeletServerCertificateManager (klet .kubeClient , kubeCfg , klet .nodeName , ips , names , certDirectory )
755
763
if err != nil {
756
764
return nil , fmt .Errorf ("failed to initialize certificate manager: %v" , err )
0 commit comments