@@ -40,7 +40,7 @@ import (
40
40
41
41
// Waiter is an interface for waiting for criteria in Kubernetes to happen
42
42
type Waiter interface {
43
- // WaitForControlPlaneComponents waits for all control plane components to report "ok" on /healthz
43
+ // WaitForControlPlaneComponents waits for all control plane components to be ready.
44
44
WaitForControlPlaneComponents (cfg * kubeadmapi.ClusterConfiguration ) error
45
45
// WaitForAPI waits for the API Server's /healthz endpoint to become "ok"
46
46
// TODO: remove WaitForAPI once WaitForAllControlPlaneComponents goes GA:
@@ -84,31 +84,58 @@ type controlPlaneComponent struct {
84
84
url string
85
85
}
86
86
87
+ const (
88
+ // TODO: switch to /livez once all components support it
89
+ // and delete the endpointHealthz constant.
90
+ // https://github.com/kubernetes/kubernetes/issues/118158
91
+ endpointHealthz = "healthz"
92
+ endpointLivez = "livez"
93
+ )
94
+
87
95
// getControlPlaneComponents takes a ClusterConfiguration and returns a slice of
88
- // control plane components and their secure ports .
96
+ // control plane components and their health check URLs .
89
97
func getControlPlaneComponents (cfg * kubeadmapi.ClusterConfiguration ) []controlPlaneComponent {
90
- portArg := "secure-port"
98
+ const (
99
+ portArg = "secure-port"
100
+ addressArg = "bind-address"
101
+ defaultAddress = "127.0.0.1"
102
+ )
103
+
91
104
portAPIServer , idx := kubeadmapi .GetArgValue (cfg .APIServer .ExtraArgs , portArg , - 1 )
92
105
if idx == - 1 {
93
- portAPIServer = "6443"
106
+ portAPIServer = fmt . Sprintf ( "%d" , constants . KubeAPIServerPort )
94
107
}
95
108
portKCM , idx := kubeadmapi .GetArgValue (cfg .ControllerManager .ExtraArgs , portArg , - 1 )
96
109
if idx == - 1 {
97
- portKCM = "10257"
110
+ portKCM = fmt . Sprintf ( "%d" , constants . KubeControllerManagerPort )
98
111
}
99
112
portScheduler , idx := kubeadmapi .GetArgValue (cfg .Scheduler .ExtraArgs , portArg , - 1 )
100
113
if idx == - 1 {
101
- portScheduler = "10259"
114
+ portScheduler = fmt .Sprintf ("%d" , constants .KubeSchedulerPort )
115
+ }
116
+
117
+ addressAPIServer , idx := kubeadmapi .GetArgValue (cfg .APIServer .ExtraArgs , addressArg , - 1 )
118
+ if idx == - 1 {
119
+ addressAPIServer = defaultAddress
120
+ }
121
+ addressKCM , idx := kubeadmapi .GetArgValue (cfg .ControllerManager .ExtraArgs , addressArg , - 1 )
122
+ if idx == - 1 {
123
+ addressKCM = defaultAddress
102
124
}
103
- urlFormat := "https://127.0.0.1:%s/healthz"
125
+ addressScheduler , idx := kubeadmapi .GetArgValue (cfg .Scheduler .ExtraArgs , addressArg , - 1 )
126
+ if idx == - 1 {
127
+ addressScheduler = defaultAddress
128
+ }
129
+
130
+ urlFormat := "https://%s:%s/%s"
104
131
return []controlPlaneComponent {
105
- {name : "kube-apiserver" , url : fmt .Sprintf (urlFormat , portAPIServer )},
106
- {name : "kube-controller-manager" , url : fmt .Sprintf (urlFormat , portKCM )},
107
- {name : "kube-scheduler" , url : fmt .Sprintf (urlFormat , portScheduler )},
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 )},
108
135
}
109
136
}
110
137
111
- // WaitForControlPlaneComponents waits for all control plane components to report "ok" on /healthz
138
+ // WaitForControlPlaneComponents waits for all control plane components to report "ok".
112
139
func (w * KubeWaiter ) WaitForControlPlaneComponents (cfg * kubeadmapi.ClusterConfiguration ) error {
113
140
fmt .Printf ("[control-plane-check] Waiting for healthy control plane components." +
114
141
" This can take up to %v\n " , w .timeout )
@@ -136,15 +163,16 @@ func (w *KubeWaiter) WaitForControlPlaneComponents(cfg *kubeadmapi.ClusterConfig
136
163
true , func (ctx context.Context ) (bool , error ) {
137
164
resp , err := client .Get (comp .url )
138
165
if err != nil {
139
- lastError = errors .WithMessagef (err , "%s /healthz check failed" , comp .name )
166
+ lastError = errors .WithMessagef (err , "%s check failed at %s " , comp .name , comp . url )
140
167
return false , nil
141
168
}
142
169
143
170
defer func () {
144
171
_ = resp .Body .Close ()
145
172
}()
146
173
if resp .StatusCode != http .StatusOK {
147
- lastError = errors .Errorf ("%s /healthz check failed with status: %d" , comp .name , resp .StatusCode )
174
+ lastError = errors .Errorf ("%s check failed at %s with status: %d" ,
175
+ comp .name , comp .url , resp .StatusCode )
148
176
return false , nil
149
177
}
150
178
0 commit comments