Skip to content

Commit

Permalink
Merge nonProxyHosts
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoliy Bazko <abazko@redhat.com>
  • Loading branch information
tolusha committed Jun 11, 2020
1 parent b118844 commit cc9975d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
12 changes: 9 additions & 3 deletions pkg/controller/che/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/deploy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/deploy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit cc9975d

Please sign in to comment.