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