@@ -21,6 +21,7 @@ import (
21
21
"crypto/tls"
22
22
"fmt"
23
23
"io"
24
+ "net"
24
25
"net/http"
25
26
"time"
26
27
@@ -40,7 +41,7 @@ import (
40
41
// Waiter is an interface for waiting for criteria in Kubernetes to happen
41
42
type Waiter interface {
42
43
// WaitForControlPlaneComponents waits for all control plane components to be ready.
43
- WaitForControlPlaneComponents (cfg * kubeadmapi.ClusterConfiguration ) error
44
+ WaitForControlPlaneComponents (cfg * kubeadmapi.ClusterConfiguration , apiServerAddress string ) error
44
45
// WaitForAPI waits for the API Server's /healthz endpoint to become "ok"
45
46
// TODO: remove WaitForAPI once WaitForAllControlPlaneComponents goes GA:
46
47
// https://github.com/kubernetes/kubeadm/issues/2907
@@ -91,11 +92,17 @@ const (
91
92
92
93
// getControlPlaneComponents takes a ClusterConfiguration and returns a slice of
93
94
// control plane components and their health check URLs.
94
- func getControlPlaneComponents (cfg * kubeadmapi.ClusterConfiguration ) []controlPlaneComponent {
95
+ func getControlPlaneComponents (cfg * kubeadmapi.ClusterConfiguration , defaultAddressAPIServer string ) []controlPlaneComponent {
95
96
const (
96
97
portArg = "secure-port"
97
- addressArg = "bind-address"
98
- defaultAddress = "127.0.0.1"
98
+ bindAddressArg = "bind-address"
99
+ // By default, for kube-api-server, kubeadm does not apply a --bind-address flag.
100
+ // Check --advertise-address instead, which can override the defaultAddressAPIServer value.
101
+ advertiseAddressArg = "advertise-address"
102
+ // By default kubeadm deploys the kube-controller-manager and kube-scheduler
103
+ // with --bind-address=127.0.0.1. This should match get{Scheduler|ControllerManager}Command().
104
+ defaultAddressKCM = "127.0.0.1"
105
+ defaultAddressScheduler = "127.0.0.1"
99
106
)
100
107
101
108
portAPIServer , idx := kubeadmapi .GetArgValue (cfg .APIServer .ExtraArgs , portArg , - 1 )
@@ -111,33 +118,39 @@ func getControlPlaneComponents(cfg *kubeadmapi.ClusterConfiguration) []controlPl
111
118
portScheduler = fmt .Sprintf ("%d" , constants .KubeSchedulerPort )
112
119
}
113
120
114
- addressAPIServer , idx := kubeadmapi .GetArgValue (cfg .APIServer .ExtraArgs , addressArg , - 1 )
121
+ addressAPIServer , idx := kubeadmapi .GetArgValue (cfg .APIServer .ExtraArgs , advertiseAddressArg , - 1 )
115
122
if idx == - 1 {
116
- addressAPIServer = defaultAddress
123
+ addressAPIServer = defaultAddressAPIServer
117
124
}
118
- addressKCM , idx := kubeadmapi .GetArgValue (cfg .ControllerManager .ExtraArgs , addressArg , - 1 )
125
+ addressKCM , idx := kubeadmapi .GetArgValue (cfg .ControllerManager .ExtraArgs , bindAddressArg , - 1 )
119
126
if idx == - 1 {
120
- addressKCM = defaultAddress
127
+ addressKCM = defaultAddressKCM
121
128
}
122
- addressScheduler , idx := kubeadmapi .GetArgValue (cfg .Scheduler .ExtraArgs , addressArg , - 1 )
129
+ addressScheduler , idx := kubeadmapi .GetArgValue (cfg .Scheduler .ExtraArgs , bindAddressArg , - 1 )
123
130
if idx == - 1 {
124
- addressScheduler = defaultAddress
131
+ addressScheduler = defaultAddressScheduler
125
132
}
126
133
127
- urlFormat := "https://%s:%s/%s"
134
+ getURL := func (address , port , endpoint string ) string {
135
+ return fmt .Sprintf (
136
+ "https://%s/%s" ,
137
+ net .JoinHostPort (address , port ),
138
+ endpoint ,
139
+ )
140
+ }
128
141
return []controlPlaneComponent {
129
- {name : "kube-apiserver" , url : fmt . Sprintf ( urlFormat , addressAPIServer , portAPIServer , endpointLivez )},
130
- {name : "kube-controller-manager" , url : fmt . Sprintf ( urlFormat , addressKCM , portKCM , endpointHealthz )},
131
- {name : "kube-scheduler" , url : fmt . Sprintf ( urlFormat , addressScheduler , portScheduler , endpointLivez )},
142
+ {name : "kube-apiserver" , url : getURL ( addressAPIServer , portAPIServer , endpointLivez )},
143
+ {name : "kube-controller-manager" , url : getURL ( addressKCM , portKCM , endpointHealthz )},
144
+ {name : "kube-scheduler" , url : getURL ( addressScheduler , portScheduler , endpointLivez )},
132
145
}
133
146
}
134
147
135
148
// WaitForControlPlaneComponents waits for all control plane components to report "ok".
136
- func (w * KubeWaiter ) WaitForControlPlaneComponents (cfg * kubeadmapi.ClusterConfiguration ) error {
149
+ func (w * KubeWaiter ) WaitForControlPlaneComponents (cfg * kubeadmapi.ClusterConfiguration , apiSeverAddress string ) error {
137
150
fmt .Printf ("[control-plane-check] Waiting for healthy control plane components." +
138
151
" This can take up to %v\n " , w .timeout )
139
152
140
- components := getControlPlaneComponents (cfg )
153
+ components := getControlPlaneComponents (cfg , apiSeverAddress )
141
154
142
155
var errs []error
143
156
errChan := make (chan error , len (components ))
0 commit comments