From cc9975dadcb9be037e7217ccb09b7d17e6beb923 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Thu, 11 Jun 2020 16:54:14 +0300 Subject: [PATCH] Merge nonProxyHosts Signed-off-by: Anatoliy Bazko --- pkg/controller/che/proxy.go | 12 +++++++++--- pkg/deploy/proxy.go | 7 ++++++- pkg/deploy/proxy_test.go | 8 ++++---- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pkg/controller/che/proxy.go b/pkg/controller/che/proxy.go index 0ad809323a..f94274866c 100644 --- a/pkg/controller/che/proxy.go +++ b/pkg/controller/che/proxy.go @@ -33,16 +33,22 @@ func (r *ReconcileChe) getProxyConfiguration(checluster *orgv1.CheCluster) (*dep return nil, err } - // proxy configuration in CR overrides cluster proxy configuration + // If proxy configuration exists in CR then cluster wide proxy configuration is ignored + // otherwise cluster wide proxy configuration is used and non proxy hosts + // are merted with defined ones in CR if proxy.HttpProxy == "" && clusterProxy.Status.HTTPProxy != "" { - proxy, err = deploy.ReadClusterWideProxyConfiguration(clusterProxy) + proxy, err = deploy.ReadClusterWideProxyConfiguration(clusterProxy, proxy.NoProxy) if err != nil { return nil, err } - } } + if util.IsOpenShift { + publicHostname, err := util.GetClusterPublicHostname() + + } + return proxy, nil } diff --git a/pkg/deploy/proxy.go b/pkg/deploy/proxy.go index ac2a26bdbe..80f984df8c 100644 --- a/pkg/deploy/proxy.go +++ b/pkg/deploy/proxy.go @@ -28,7 +28,7 @@ import ( "github.com/sirupsen/logrus" ) -func ReadClusterWideProxyConfiguration(clusterProxy *configv1.Proxy) (*Proxy, error) { +func ReadClusterWideProxyConfiguration(clusterProxy *configv1.Proxy, noProxy string) (*Proxy, error) { proxy := &Proxy{} // Cluster components consume the status values to configure the proxy for their component. @@ -38,6 +38,11 @@ func ReadClusterWideProxyConfiguration(clusterProxy *configv1.Proxy) (*Proxy, er proxy.HttpsProxy = proxy.HttpProxy } proxy.NoProxy = clusterProxy.Status.NoProxy + if proxy.NoProxy == "" { + proxy.NoProxy = noProxy + } else if noProxy != "" { + proxy.NoProxy += "," + noProxy + } httpProxy, err := url.Parse(proxy.HttpProxy) if err != nil { diff --git a/pkg/deploy/proxy_test.go b/pkg/deploy/proxy_test.go index 8ceb47749d..37e3eeb0be 100644 --- a/pkg/deploy/proxy_test.go +++ b/pkg/deploy/proxy_test.go @@ -199,7 +199,7 @@ func TestReadClusterWideProxyConfiguration(t *testing.T) { NoProxy: "host1,host2", } - actualProxy, _ := ReadClusterWideProxyConfiguration(clusterProxy) + actualProxy, _ := ReadClusterWideProxyConfiguration(clusterProxy, "") if !reflect.DeepEqual(actualProxy, expectedProxy) { t.Errorf("Test failed. Expected '%v', but got '%v'", expectedProxy, actualProxy) @@ -225,7 +225,7 @@ func TestReadClusterWideProxyConfigurationNoUser(t *testing.T) { HttpsPort: "1234", } - actualProxy, _ := ReadClusterWideProxyConfiguration(clusterProxy) + actualProxy, _ := ReadClusterWideProxyConfiguration(clusterProxy, "") if !reflect.DeepEqual(actualProxy, expectedProxy) { t.Errorf("Test failed. Expected '%v', but got '%v'", expectedProxy, actualProxy) @@ -251,10 +251,10 @@ func TestReadClusterWideProxyConfigurationNoPort(t *testing.T) { HttpsPassword: "password", HttpsHost: "myproxy.com", - NoProxy: "host1,host2", + NoProxy: "host1,host2,host3", } - actualProxy, _ := ReadClusterWideProxyConfiguration(clusterProxy) + actualProxy, _ := ReadClusterWideProxyConfiguration(clusterProxy, "host3") if !reflect.DeepEqual(actualProxy, expectedProxy) { t.Errorf("Test failed. Expected '%v', but got '%v'", expectedProxy, actualProxy)