Use regular http.Client in this test.

Signed-off-by: Matt Moyer <moyerm@vmware.com>
This commit is contained in:
Matt Moyer 2021-03-04 17:18:24 -06:00
parent 165fce67af
commit 16163b989b
No known key found for this signature in database
GPG Key ID: EAE88AD172C5AE2D

View File

@ -6,11 +6,14 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"context" "context"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix" "crypto/x509/pkix"
"encoding/base64" "encoding/base64"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http"
"net/url" "net/url"
"os" "os"
"os/exec" "os/exec"
@ -26,7 +29,6 @@ import (
authorizationv1 "k8s.io/api/authorization/v1" authorizationv1 "k8s.io/api/authorization/v1"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1" rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/client-go/rest"
authv1alpha "go.pinniped.dev/generated/latest/apis/concierge/authentication/v1alpha1" authv1alpha "go.pinniped.dev/generated/latest/apis/concierge/authentication/v1alpha1"
configv1alpha1 "go.pinniped.dev/generated/latest/apis/supervisor/config/v1alpha1" configv1alpha1 "go.pinniped.dev/generated/latest/apis/supervisor/config/v1alpha1"
@ -270,16 +272,33 @@ func TestE2EFullIntegration(t *testing.T) {
require.Equal(t, "you have been logged in and may now close this tab", msg) require.Equal(t, "you have been logged in and may now close this tab", msg)
// Verify that we can actually reach the endpoint in the kubeconfig. // Verify that we can actually reach the endpoint in the kubeconfig.
restClient, err := rest.UnversionedRESTClientFor(restConfig)
require.NoError(t, err)
require.Eventually(t, func() bool { require.Eventually(t, func() bool {
var status int kubeconfigCA := x509.NewCertPool()
_, err := restClient.Get().AbsPath("/version").Do(ctx).StatusCode(&status).Raw() require.True(t, kubeconfigCA.AppendCertsFromPEM(restConfig.TLSClientConfig.CAData), "expected to load kubeconfig CA")
if status == 200 || status == 403 {
return true // Create an HTTP client that can reach the downstream discovery endpoint using the CA certs.
httpClient := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{RootCAs: kubeconfigCA},
Proxy: func(req *http.Request) (*url.URL, error) {
if env.Proxy == "" {
t.Logf("passing request for %s with no proxy", req.URL)
return nil, nil
}
proxyURL, err := url.Parse(env.Proxy)
require.NoError(t, err)
t.Logf("passing request for %s through proxy %s", req.URL, proxyURL.String())
return proxyURL, nil
},
},
} }
t.Logf("attempted to connect to API server's /version endpoint, got response code %d with error %v", status, err) resp, err := httpClient.Get(restConfig.Host)
return false if err != nil {
t.Logf("could not connect to the API server at %q: %v", restConfig.Host, err)
return false
}
t.Logf("got %d response from API server at %q", resp.StatusCode, restConfig.Host)
return resp.StatusCode == 200 || resp.StatusCode == 403
}, 5*time.Minute, time.Second) }, 5*time.Minute, time.Second)
// Expect the CLI to output a list of namespaces in JSON format. // Expect the CLI to output a list of namespaces in JSON format.