From 8f32fe40d0916706cf2717364663555328376a60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20St=C3=A4bler?= Date: Fri, 29 Sep 2023 07:48:56 +0200 Subject: [PATCH] Remove discovery RestClient usage --- pkg/auth/token_handler.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/auth/token_handler.go b/pkg/auth/token_handler.go index 4b1abf59f52..bdac641f539 100644 --- a/pkg/auth/token_handler.go +++ b/pkg/auth/token_handler.go @@ -20,6 +20,7 @@ import ( "context" "encoding/json" "fmt" + "io" "net/http" "time" @@ -101,17 +102,21 @@ func (c *OIDCTokenHandler) getHTTPClientForKubeAPIServer() (*http.Client, error) } func (c *OIDCTokenHandler) getKubernetesOIDCConfiguration(ctx context.Context) (*openIDMetadata, error) { - req := c.kubeClient.Discovery().RESTClient().Get().RequestURI("/.well-known/openid-configuration") - - res := req.Do(ctx) - if err := res.Error(); err != nil { - return nil, fmt.Errorf("could not execute request: %w", err) + client, err := c.getHTTPClientForKubeAPIServer() + if err != nil { + return nil, fmt.Errorf("could not get HTTP client for API server: %w", err) } - body, err := res.Raw() + resp, err := client.Get(KubernetesDefaultIssuer + "/.well-known/openid-configuration") if err != nil { return nil, fmt.Errorf("could not get response: %w", err) } + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + return nil, fmt.Errorf("could not read response body: %w", err) + } openIdConfig := &openIDMetadata{} if err := json.Unmarshal(body, openIdConfig); err != nil {