Skip to content

Commit

Permalink
Add Kubernetes host to the no proxy list (#1800)
Browse files Browse the repository at this point in the history
Add Kubernetes host to the no proxy list
  • Loading branch information
vinokurig authored Jan 18, 2024
1 parent c738dc7 commit 7c7bd4f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ metadata:
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/eclipse-che/che-operator
support: Eclipse Foundation
name: eclipse-che.v7.79.0-828.next
name: eclipse-che.v7.81.0-829.next
namespace: placeholder
spec:
apiservicedefinitions: {}
Expand Down Expand Up @@ -1240,7 +1240,7 @@ spec:
minKubeVersion: 1.19.0
provider:
name: Eclipse Foundation
version: 7.79.0-828.next
version: 7.81.0-829.next
webhookdefinitions:
- admissionReviewVersions:
- v1
Expand Down
16 changes: 14 additions & 2 deletions controllers/che/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package che

import (
"os"

"github.com/devfile/devworkspace-operator/pkg/infrastructure"
"github.com/eclipse-che/che-operator/pkg/common/chetypes"
"github.com/eclipse-che/che-operator/pkg/deploy"
Expand Down Expand Up @@ -50,9 +52,15 @@ func GetProxyConfiguration(deployContext *chetypes.DeployContext) (*chetypes.Pro
}
// Add cluster-wide trusted CA certs, if any
cheClusterProxyConf.TrustedCAMapName = clusterWideProxyConf.TrustedCAMapName
// Add kubernetes host to the no proxy list.
cheClusterProxyConf.NoProxy = deploy.MergeNonProxy(cheClusterProxyConf.NoProxy, os.Getenv("KUBERNETES_SERVICE_HOST"))
return cheClusterProxyConf, nil
} else {
clusterWideProxyConf.NoProxy = deploy.MergeNonProxy(clusterWideProxyConf.NoProxy, cheClusterProxyConf.NoProxy)
if clusterWideProxyConf.HttpProxy != "" {
// Add kubernetes host to the no proxy list.
clusterWideProxyConf.NoProxy = deploy.MergeNonProxy(clusterWideProxyConf.NoProxy, os.Getenv("KUBERNETES_SERVICE_HOST"))
clusterWideProxyConf.NoProxy = deploy.MergeNonProxy(clusterWideProxyConf.NoProxy, cheClusterProxyConf.NoProxy)
}
return clusterWideProxyConf, nil
}
}
Expand All @@ -62,6 +70,10 @@ func GetProxyConfiguration(deployContext *chetypes.DeployContext) (*chetypes.Pro
if err != nil {
return nil, err
}
cheClusterProxyConf.NoProxy = deploy.MergeNonProxy(cheClusterProxyConf.NoProxy, ".svc")
if cheClusterProxyConf.HttpProxy != "" {
// Add kubernetes host to the no proxy list.
cheClusterProxyConf.NoProxy = deploy.MergeNonProxy(cheClusterProxyConf.NoProxy, os.Getenv("KUBERNETES_SERVICE_HOST"))
cheClusterProxyConf.NoProxy = deploy.MergeNonProxy(cheClusterProxyConf.NoProxy, ".svc")
}
return cheClusterProxyConf, nil
}
13 changes: 0 additions & 13 deletions controllers/usernamespace/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,19 +332,6 @@ func TestCreatesDataInNamespace(t *testing.T) {

assert.False(t, res.Requeue, "The reconciliation request should have succeeded but it is requesting a requeue")

proxySettings := corev1.ConfigMap{}
assert.NoError(t, cl.Get(ctx, client.ObjectKey{Name: "che-proxy-settings", Namespace: namespace.GetName()}, &proxySettings))

assert.Equal(t, "env", proxySettings.GetAnnotations()[dwconstants.DevWorkspaceMountAsAnnotation],
"proxy settings should be annotated as mount as 'env'")

assert.Equal(t, "true", proxySettings.GetLabels()[dwconstants.DevWorkspaceMountLabel],
"proxy settings should be labeled as mounted")

assert.Equal(t, 2, len(proxySettings.Data), "Expecting 2 elements in the default proxy settings")

assert.Equal(t, ".svc", proxySettings.Data["NO_PROXY"], "Unexpected proxy settings")

idleSettings := corev1.ConfigMap{}
assert.NoError(t, cl.Get(ctx, client.ObjectKey{Name: "che-idle-settings", Namespace: namespace.GetName()}, &idleSettings))

Expand Down
6 changes: 0 additions & 6 deletions pkg/deploy/server/server_configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package server
import (
"encoding/json"
"fmt"
"os"
"strconv"
"strings"

Expand Down Expand Up @@ -89,11 +88,6 @@ func (s *CheServerReconciler) getCheConfigMapData(ctx *chetypes.DeployContext) (
proxyJavaOpts := ""
cheWorkspaceNoProxy := ctx.Proxy.NoProxy
if ctx.Proxy.HttpProxy != "" {
if ctx.Proxy.NoProxy == "" {
cheWorkspaceNoProxy = os.Getenv("KUBERNETES_SERVICE_HOST")
} else {
cheWorkspaceNoProxy = cheWorkspaceNoProxy + "," + os.Getenv("KUBERNETES_SERVICE_HOST")
}
proxyJavaOpts, err = deploy.GenerateProxyJavaOpts(ctx.Proxy, cheWorkspaceNoProxy)
if err != nil {
logrus.Errorf("Failed to generate java proxy options: %v", err)
Expand Down

0 comments on commit 7c7bd4f

Please sign in to comment.