Skip to content

Commit

Permalink
fix: Set CHE_INFRA_KUBERNETES_ENABLE__UNSUPPORTED__K8S: true when dev…
Browse files Browse the repository at this point in the history
…workspace is enabled on k8s (#1155)

Signed-off-by: Anatolii Bazko <abazko@redhat.com>
  • Loading branch information
tolusha committed Oct 21, 2021
1 parent 5ef57db commit a889b56
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 19 deletions.
13 changes: 11 additions & 2 deletions controllers/che/checluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import (

chev1alpha1 "github.com/che-incubator/kubernetes-image-puller-operator/api/v1alpha1"
"github.com/golang/mock/gomock"
crdv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"

devworkspace "github.com/eclipse-che/che-operator/pkg/deploy/dev-workspace"
identity_provider "github.com/eclipse-che/che-operator/pkg/deploy/identity-provider"
"github.com/google/go-cmp/cmp"

Expand Down Expand Up @@ -181,13 +183,20 @@ func TestNativeUserModeEnabled(t *testing.T) {
scheme.AddKnownTypes(routev1.GroupVersion, route)
scheme.AddKnownTypes(oauth.SchemeGroupVersion, oAuthClient)
scheme.AddKnownTypes(configv1.SchemeGroupVersion, &configv1.Proxy{})
initCR := InitCheWithSimpleCR().DeepCopy()
testCase.initObjects = append(testCase.initObjects, initCR)
scheme.AddKnownTypes(crdv1.SchemeGroupVersion, &crdv1.CustomResourceDefinition{})

initCR := InitCheWithSimpleCR().DeepCopy()
initCR.Spec.DevWorkspace.Enable = testCase.devworkspaceEnabled
initCR.Spec.Auth.NativeUserMode = testCase.initialNativeUserValue
testCase.initObjects = append(testCase.initObjects, initCR)

util.IsOpenShift = testCase.isOpenshift

// reread templates (workaround after setting IsOpenShift value)
devworkspace.DevWorkspaceTemplates = devworkspace.DevWorkspaceTemplatesPath()
devworkspace.DevWorkspaceIssuerFile = devworkspace.DevWorkspaceTemplates + "/devworkspace-controller-selfsigned-issuer.Issuer.yaml"
devworkspace.DevWorkspaceCertificateFile = devworkspace.DevWorkspaceTemplates + "/devworkspace-controller-serving-cert.Certificate.yaml"

cli := fake.NewFakeClientWithScheme(scheme, testCase.initObjects...)
nonCachedClient := fake.NewFakeClientWithScheme(scheme, testCase.initObjects...)
clientSet := fakeclientset.NewSimpleClientset()
Expand Down
5 changes: 0 additions & 5 deletions pkg/deploy/dev-workspace/dev_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ func ReconcileDevWorkspace(deployContext *deploy.DeployContext) (done bool, err
logrus.Warnf("To enable DevWorkspace engine, deploy Eclipse Che from tech-preview channel.")
}

if !util.IsOpenShift && util.GetCheServerCustomCheProperty(deployContext.CheCluster, "CHE_INFRA_KUBERNETES_ENABLE__UNSUPPORTED__K8S") != "true" {
logrus.Warn(`DevWorkspace Che operator can't be enabled on a Kubernetes cluster without explicitly enabled k8s API on che-server. To enable DevWorkspace Che operator set 'spec.server.customCheProperties[CHE_INFRA_KUBERNETES_ENABLE__UNSUPPORTED__K8S]' to 'true'.`)
return true, nil
}

isCreated, err := createDwNamespace(deployContext)
if err != nil {
return false, err
Expand Down
8 changes: 6 additions & 2 deletions pkg/deploy/dev-workspace/dev_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,15 @@ func TestReconcileDevWorkspace(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
deployContext := deploy.GetTestDeployContext(testCase.cheCluster, []runtime.Object{})
deployContext.ClusterAPI.Scheme.AddKnownTypes(crdv1.SchemeGroupVersion, &crdv1.CustomResourceDefinition{})
deployContext.ClusterAPI.Scheme.AddKnownTypes(operatorsv1alpha1.SchemeGroupVersion, &operatorsv1alpha1.Subscription{})

util.IsOpenShift = testCase.IsOpenShift
util.IsOpenShift4 = testCase.IsOpenShift4

// reread templates (workaround after setting IsOpenShift value)
DevWorkspaceTemplates = DevWorkspaceTemplatesPath()
DevWorkspaceIssuerFile = DevWorkspaceTemplates + "/devworkspace-controller-selfsigned-issuer.Issuer.yaml"
DevWorkspaceCertificateFile = DevWorkspaceTemplates + "/devworkspace-controller-serving-cert.Certificate.yaml"

err := os.Setenv("ALLOW_DEVWORKSPACE_ENGINE", "true")
assert.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions pkg/deploy/dev-workspace/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var (
syncDwDeployment,
}

DevWorkspaceTemplates = devWorkspaceTemplatesPath()
DevWorkspaceTemplates = DevWorkspaceTemplatesPath()

OpenshiftDevWorkspaceTemplatesPath = "/tmp/devworkspace-operator/templates/deployment/openshift/objects"
KubernetesDevWorkspaceTemplatesPath = "/tmp/devworkspace-operator/templates/deployment/kubernetes/objects"
Expand Down Expand Up @@ -247,7 +247,7 @@ func syncObject(deployContext *deploy.DeployContext, obj2sync client.Object, nam
return true, nil
}

func devWorkspaceTemplatesPath() string {
func DevWorkspaceTemplatesPath() string {
if util.IsOpenShift {
return OpenshiftDevWorkspaceTemplatesPath
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/deploy/server/server_configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ func (s *Server) getCheConfigMapData() (cheEnv map[string]string, err error) {
"CHE_INFRA_KUBERNETES_INGRESS_PATH__TRANSFORM": "%s(.*)",
}

if s.deployContext.CheCluster.Spec.DevWorkspace.Enable {
k8sCheEnv["CHE_INFRA_KUBERNETES_ENABLE__UNSUPPORTED__K8S"] = "true"
}

// Add TLS key and server certificate to properties since user workspaces is created in another
// than Che server namespace, from where the Che TLS secret is not accessable
if s.deployContext.CheCluster.Spec.K8s.TlsSecretName != "" {
Expand Down
3 changes: 3 additions & 0 deletions pkg/deploy/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package deploy
import (
orgv1 "github.com/eclipse-che/che-operator/api/v1"
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
crdv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
fakeDiscovery "k8s.io/client-go/discovery/fake"
Expand Down Expand Up @@ -41,6 +42,8 @@ func GetTestDeployContext(cheCluster *orgv1.CheCluster, initObjs []runtime.Objec
scheme := scheme.Scheme
orgv1.SchemeBuilder.AddToScheme(scheme)
scheme.AddKnownTypes(operatorsv1alpha1.SchemeGroupVersion, &operatorsv1alpha1.Subscription{})
scheme.AddKnownTypes(crdv1.SchemeGroupVersion, &crdv1.CustomResourceDefinition{})
scheme.AddKnownTypes(operatorsv1alpha1.SchemeGroupVersion, &operatorsv1alpha1.Subscription{})

initObjs = append(initObjs, cheCluster)
cli := fake.NewFakeClientWithScheme(scheme, initObjs...)
Expand Down
8 changes: 0 additions & 8 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,14 +510,6 @@ func GetWorkspaceNamespaceDefault(cr *orgv1.CheCluster) string {
return GetValue(cr.Spec.Server.WorkspaceNamespaceDefault, workspaceNamespaceDefault)
}

// GetCheServerCustomCheProperty - returns value of che-server's custom property.
func GetCheServerCustomCheProperty(cr *orgv1.CheCluster, key string) string {
if cr.Spec.Server.CustomCheProperties != nil {
return cr.Spec.Server.CustomCheProperties[key]
}
return ""
}

// IsDeleteOAuthInitialUser - returns true when initial Openshfit oAuth user must be deleted.
func IsDeleteOAuthInitialUser(cr *orgv1.CheCluster) bool {
return cr.Spec.Auth.InitialOpenShiftOAuthUser != nil && !*cr.Spec.Auth.InitialOpenShiftOAuthUser && cr.Status.OpenShiftOAuthUserCredentialsSecret != ""
Expand Down

0 comments on commit a889b56

Please sign in to comment.