diff --git a/controllers/imagerepository_controller.go b/controllers/imagerepository_controller.go index ea8c418e..368dfd60 100644 --- a/controllers/imagerepository_controller.go +++ b/controllers/imagerepository_controller.go @@ -280,7 +280,9 @@ func getGCRLoginAuth(ctx context.Context) (authn.AuthConfig, error) { if err != nil { return authConfig, err } - + defer io.Copy(io.Discard, response.Body) + defer response.Body.Close() + if response.StatusCode != http.StatusOK { return authConfig, fmt.Errorf("unexpected status from metadata service: %s", response.Status) } @@ -291,14 +293,6 @@ func getGCRLoginAuth(ctx context.Context) (authn.AuthConfig, error) { return authConfig, err } - if _, err := io.Copy(io.Discard, response.Body); err != nil { - return authConfig, err - } - - if err := response.Body.Close(); err != nil { - return authConfig, err - } - authConfig = authn.AuthConfig{ Username: "oauth2accesstoken", Password: accessToken.AccessToken,