Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions test/extended/operators/routable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down
4 changes: 4 additions & 0 deletions test/extended/router/idle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 6 additions & 0 deletions test/extended/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion test/extended/util/jenkins/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions test/extended/util/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
18 changes: 16 additions & 2 deletions test/extended/util/url/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Tester struct {
namespace string
podName string
errorPassThrough bool
proxy string
}

func NewTester(client kclientset.Interface, ns string) *Tester {
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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{
Expand All @@ -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 {
Expand Down