@@ -117,8 +117,9 @@ func NewKubeWaiter(client clientset.Interface, timeout time.Duration, writer io.
117
117
// controlPlaneComponent holds a component name and an URL
118
118
// on which to perform health checks.
119
119
type controlPlaneComponent struct {
120
- name string
121
- url string
120
+ name string
121
+ addressPort string
122
+ endpoint string
122
123
}
123
124
124
125
// getControlPlaneComponentAddressAndPort parses the command in a static Pod
@@ -181,7 +182,6 @@ func getControlPlaneComponents(podMap map[string]*v1.Pod, addressAPIServer strin
181
182
182
183
type componentConfig struct {
183
184
name string
184
- podKey string
185
185
args []string
186
186
defaultAddr string
187
187
defaultPort string
@@ -190,24 +190,21 @@ func getControlPlaneComponents(podMap map[string]*v1.Pod, addressAPIServer strin
190
190
191
191
components := []componentConfig {
192
192
{
193
- name : "kube-apiserver" ,
194
- podKey : constants .KubeAPIServer ,
193
+ name : constants .KubeAPIServer ,
195
194
args : []string {argAdvertiseAddress , argPort },
196
195
defaultAddr : addressAPIServer ,
197
196
defaultPort : portAPIServer ,
198
197
endpoint : endpointLivez ,
199
198
},
200
199
{
201
- name : "kube-controller-manager" ,
202
- podKey : constants .KubeControllerManager ,
200
+ name : constants .KubeControllerManager ,
203
201
args : []string {argBindAddress , argPort },
204
202
defaultAddr : addressKCM ,
205
203
defaultPort : portKCM ,
206
204
endpoint : endpointHealthz ,
207
205
},
208
206
{
209
- name : "kube-scheduler" ,
210
- podKey : constants .KubeScheduler ,
207
+ name : constants .KubeScheduler ,
211
208
args : []string {argBindAddress , argPort },
212
209
defaultAddr : addressScheduler ,
213
210
defaultPort : portScheduler ,
@@ -219,8 +216,8 @@ func getControlPlaneComponents(podMap map[string]*v1.Pod, addressAPIServer strin
219
216
address , port := component .defaultAddr , component .defaultPort
220
217
221
218
values , err := getControlPlaneComponentAddressAndPort (
222
- podMap [component .podKey ],
223
- component .podKey ,
219
+ podMap [component .name ],
220
+ component .name ,
224
221
component .args ,
225
222
)
226
223
if err != nil {
@@ -235,8 +232,9 @@ func getControlPlaneComponents(podMap map[string]*v1.Pod, addressAPIServer strin
235
232
}
236
233
237
234
result = append (result , controlPlaneComponent {
238
- name : component .name ,
239
- url : fmt .Sprintf ("https://%s/%s" , net .JoinHostPort (address , port ), component .endpoint ),
235
+ name : component .name ,
236
+ addressPort : net .JoinHostPort (address , port ),
237
+ endpoint : component .endpoint ,
240
238
})
241
239
}
242
240
@@ -260,33 +258,47 @@ func (w *KubeWaiter) WaitForControlPlaneComponents(podMap map[string]*v1.Pod, ap
260
258
errChan := make (chan error , len (components ))
261
259
262
260
for _ , comp := range components {
263
- fmt .Printf ("[control-plane-check] Checking %s at %s\n " , comp .name , comp .url )
261
+ url := fmt .Sprintf ("https://%s/%s" , comp .addressPort , comp .endpoint )
262
+ fmt .Printf ("[control-plane-check] Checking %s at %s\n " , comp .name , url )
264
263
265
264
go func (comp controlPlaneComponent ) {
266
265
tr := & http.Transport {
267
266
TLSClientConfig : & tls.Config {InsecureSkipVerify : true },
268
267
}
269
268
client := & http.Client {Transport : tr }
270
269
start := time .Now ()
270
+ statusCode := 0
271
271
var lastError error
272
272
273
273
err := wait .PollUntilContextTimeout (
274
274
context .Background (),
275
275
constants .KubernetesAPICallRetryInterval ,
276
276
w .timeout ,
277
277
true , func (ctx context.Context ) (bool , error ) {
278
- resp , err := client .Get (comp .url )
279
- if err != nil {
280
- lastError = errors .WithMessagef (err , "%s check failed at %s" , comp .name , comp .url )
281
- return false , nil
278
+ // The kube-apiserver check should use the client defined in the waiter
279
+ // or otherwise the regular http client can fail when anonymous auth is enabled.
280
+ if comp .name == constants .KubeAPIServer {
281
+ result := w .client .Discovery ().RESTClient ().
282
+ Get ().AbsPath (comp .endpoint ).Do (ctx ).StatusCode (& statusCode )
283
+ if err := result .Error (); err != nil {
284
+ lastError = errors .WithMessagef (err , "%s check failed at %s" , comp .name , url )
285
+ return false , nil
286
+ }
287
+ } else {
288
+ resp , err := client .Get (url )
289
+ if err != nil {
290
+ lastError = errors .WithMessagef (err , "%s check failed at %s" , comp .name , url )
291
+ return false , nil
292
+ }
293
+ defer func () {
294
+ _ = resp .Body .Close ()
295
+ }()
296
+ statusCode = resp .StatusCode
282
297
}
283
298
284
- defer func () {
285
- _ = resp .Body .Close ()
286
- }()
287
- if resp .StatusCode != http .StatusOK {
299
+ if statusCode != http .StatusOK {
288
300
lastError = errors .Errorf ("%s check failed at %s with status: %d" ,
289
- comp .name , comp . url , resp . StatusCode )
301
+ comp .name , url , statusCode )
290
302
return false , nil
291
303
}
292
304
0 commit comments