diff --git a/test/extended/operators/routable.go b/test/extended/operators/routable.go index 377b65912193..7bb5e7da4715 100644 --- a/test/extended/operators/routable.go +++ b/test/extended/operators/routable.go @@ -52,6 +52,9 @@ var _ = g.Describe("[sig-arch] Managed cluster should", func() { ns := oc.KubeFramework().Namespace.Name tester := exurl.NewTester(oc.AdminKubeClient(), ns).WithErrorPassthrough(true) + // Ammend cluster proxy settings to tester pod when applicable + proxy := exutil.GetClusterProxyConfig(oc.AdminConfig()) + tester.WithProxy(proxy.Spec.HTTPProxy) tests := []*exurl.Test{} diff --git a/test/extended/router/idle.go b/test/extended/router/idle.go index 8a17ee7ff7b5..04c1f4eff0f7 100644 --- a/test/extended/router/idle.go +++ b/test/extended/router/idle.go @@ -48,6 +48,10 @@ var _ = g.Describe("[sig-network-edge][Conformance][Area:Networking][Feature:Rou o.Expect(err).NotTo(o.HaveOccurred()) urlTester := url.NewTester(oc.AdminKubeClient(), oc.Namespace()).WithErrorPassthrough(true) + // Get cluster proxy config + proxy := exutil.GetClusterProxyConfig(oc.AdminConfig()) + urlTester.WithProxy(proxy.Spec.HTTPProxy) + defer urlTester.Close() hostname := getHostnameForRoute(oc, "idle-test") urlTester.Within(urlTimeout, url.Expect("GET", "http://"+hostname).Through(hostname).HasStatusCode(200)) diff --git a/test/extended/router/router.go b/test/extended/router/router.go index 4aaeaaed3556..9e379bf11414 100644 --- a/test/extended/router/router.go +++ b/test/extended/router/router.go @@ -59,6 +59,9 @@ var _ = g.Describe("[sig-network][Feature:Router]", func() { g.Describe("The HAProxy router", func() { g.It("should respond with 503 to unrecognized hosts", func() { t := url.NewTester(oc.AdminKubeClient(), ns).WithErrorPassthrough(true) + // Get cluster proxy config + proxy := exutil.GetClusterProxyConfig(oc.AdminConfig()) + t.WithProxy(proxy.Spec.HTTPProxy) defer t.Close() t.Within( time.Minute, @@ -85,6 +88,9 @@ var _ = g.Describe("[sig-network][Feature:Router]", func() { g.By("verifying the router reports the correct behavior") t := url.NewTester(oc.AdminKubeClient(), ns).WithErrorPassthrough(true) + // Get cluster proxy config + proxy := exutil.GetClusterProxyConfig(oc.AdminConfig()) + t.WithProxy(proxy.Spec.HTTPProxy) defer t.Close() t.Within( 3*time.Minute, diff --git a/test/extended/util/jenkins/ref.go b/test/extended/util/jenkins/ref.go index 55dced6cbe26..10087fca21ec 100644 --- a/test/extended/util/jenkins/ref.go +++ b/test/extended/util/jenkins/ref.go @@ -70,13 +70,18 @@ func NewRef(oc *exutil.CLI) *JenkinsRef { token, err := oc.Run("whoami").Args("-t").Output() o.Expect(err).NotTo(o.HaveOccurred()) + t := exurl.NewTester(oc.AdminKubeClient(), oc.Namespace()) + // Get cluster proxy config + proxy := exutil.GetClusterProxyConfig(oc.AdminConfig()) + t.WithProxy(proxy.Spec.HTTPProxy) + j := &JenkinsRef{ oc: oc, host: serviceIP, port: port, namespace: oc.Namespace(), token: token, - uri_tester: exurl.NewTester(oc.AdminKubeClient(), oc.Namespace()), + uri_tester: t, } return j } diff --git a/test/extended/util/proxy.go b/test/extended/util/proxy.go index 03771d3c6daa..0b05969abb29 100644 --- a/test/extended/util/proxy.go +++ b/test/extended/util/proxy.go @@ -3,8 +3,13 @@ package util import ( "context" + v1 "github.com/openshift/api/config/v1" + kerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + rest "k8s.io/client-go/rest" + + configclientset "github.com/openshift/client-go/config/clientset/versioned" ) // IsClusterProxyEnabled returns true if the cluster has a global proxy enabled @@ -18,3 +23,10 @@ func IsClusterProxyEnabled(oc *CLI) (bool, error) { } return len(proxy.Status.HTTPProxy) > 0 || len(proxy.Status.HTTPSProxy) > 0, nil } + +func GetClusterProxyConfig(oc *rest.Config) *v1.Proxy { + configClient := configclientset.NewForConfigOrDie(oc) + proxy, _ := configClient.ConfigV1().Proxies().Get(context.Background(), "cluster", metav1.GetOptions{}) + + return proxy +} diff --git a/test/extended/util/url/url.go b/test/extended/util/url/url.go index 5315ee4b70f8..4ba5674de2b6 100644 --- a/test/extended/util/url/url.go +++ b/test/extended/util/url/url.go @@ -31,6 +31,7 @@ type Tester struct { namespace string podName string errorPassThrough bool + proxy string } func NewTester(client kclientset.Interface, ns string) *Tester { @@ -57,7 +58,7 @@ func (ut *Tester) Response(test *Test) *Response { func (ut *Tester) Responses(tests ...*Test) []*Response { if len(ut.podName) == 0 { - _, err := createExecPod(ut.client, ut.namespace, "execpod") + _, err := createExecPod(ut.client, ut.namespace, ut.proxy, "execpod") if err != nil && !apierrs.IsAlreadyExists(err) { // exit even on error passthrough, unless the exec pod // was already created by a test running in parallel @@ -105,6 +106,11 @@ func (ut *Tester) WithErrorPassthrough(pt bool) *Tester { return ut } +func (ut *Tester) WithProxy(proxy string) *Tester { + ut.proxy = proxy + return ut +} + func (ut *Tester) Podname() string { return ut.podName } @@ -140,7 +146,7 @@ func (ut *Tester) Within(t time.Duration, tests ...*Test) { // createExecPod creates a simple bash pod in a sleep loop used as a // vessel for kubectl exec commands. // Returns the name of the created pod. -func createExecPod(clientset kclientset.Interface, ns, name string) (string, error) { +func createExecPod(clientset kclientset.Interface, ns, proxy, name string) (string, error) { e2e.Logf("Creating new exec pod") immediate := int64(0) execPod := &v1.Pod{ @@ -161,6 +167,14 @@ func createExecPod(clientset kclientset.Interface, ns, name string) (string, err TerminationGracePeriodSeconds: &immediate, }, } + // If cluster is using an egress proxy, add the proxy settings to the + // execpod's env + if len(proxy) > 0 { + execPod.Spec.Containers[0].Env = []v1.EnvVar{ + {Name: "HTTP_PROXY", Value: proxy}, + {Name: "HTTPS_PROXY", Value: proxy}, + } + } client := clientset.CoreV1() created, err := client.Pods(ns).Create(context.Background(), execPod, metav1.CreateOptions{}) if err != nil {