Skip to content

Commit 7d054a6

Browse files
authored
Accept 401 and 200 as OK on kube api check (#134)
Signed-off-by: Jussi Nummelin <[email protected]>
1 parent 04f6ac4 commit 7d054a6

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

config/cluster/host.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,24 +285,27 @@ func (h *Host) UncordonNode(node *Host) error {
285285
}
286286

287287
// CheckHTTPStatus will perform a web request to the url and return an error if the http status is not the expected
288-
func (h *Host) CheckHTTPStatus(url string, expected int) error {
288+
func (h *Host) CheckHTTPStatus(url string, expected ...int) error {
289289
status, err := h.Configurer.HTTPStatus(h, url)
290290
if err != nil {
291291
return err
292292
}
293293

294-
if status != expected {
295-
return fmt.Errorf("expected response code %d but received %d", expected, status)
294+
for _, e := range expected {
295+
if status == e {
296+
return nil
297+
}
296298
}
297299

298-
return nil
300+
return fmt.Errorf("expected response code %d but received %d", expected, status)
301+
299302
}
300303

301304
// WaitHTTPStatus waits until http status received for a GET from the URL is the expected one
302-
func (h *Host) WaitHTTPStatus(url string, expected int) error {
305+
func (h *Host) WaitHTTPStatus(url string, expected ...int) error {
303306
return retry.Do(
304307
func() error {
305-
return h.CheckHTTPStatus(url, expected)
308+
return h.CheckHTTPStatus(url, expected...)
306309
},
307310
retry.DelayType(retry.CombineDelay(retry.FixedDelay, retry.RandomDelay)),
308311
retry.MaxJitter(time.Second*2),
@@ -364,5 +367,7 @@ func (h *Host) NeedIPTables() bool {
364367

365368
// WaitKubeAPIReady blocks until the local kube api responds to /version
366369
func (h *Host) WaitKubeAPIReady() error {
367-
return h.WaitHTTPStatus("https://localhost:6443/version", 200)
370+
// If the anon-auth is disabled on kube api the version endpoint will give 401
371+
// thus we need to accept both 200 and 401 as valid statuses when checking kube api
372+
return h.WaitHTTPStatus("https://localhost:6443/version", 200, 401)
368373
}

0 commit comments

Comments
 (0)