From 79006712efa8bdba96db9e271385c7e1e94ab4ee Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Thu, 21 Oct 2021 12:38:15 +0300 Subject: [PATCH] fix: Set CHE_INFRA_KUBERNETES_ENABLE__UNSUPPORTED__K8S: true when devworkspace is enabled on k8s Signed-off-by: Anatolii Bazko --- controllers/che/checluster_controller_test.go | 13 +++++++++++-- pkg/deploy/dev-workspace/dev_workspace.go | 5 ----- pkg/deploy/dev-workspace/dev_workspace_test.go | 8 ++++++-- pkg/deploy/dev-workspace/sync.go | 4 ++-- pkg/deploy/server/server_configmap.go | 4 ++++ pkg/deploy/test_util.go | 3 +++ pkg/util/util.go | 8 -------- 7 files changed, 26 insertions(+), 19 deletions(-) diff --git a/controllers/che/checluster_controller_test.go b/controllers/che/checluster_controller_test.go index 2b74516442..0607608ad3 100644 --- a/controllers/che/checluster_controller_test.go +++ b/controllers/che/checluster_controller_test.go @@ -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" @@ -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() diff --git a/pkg/deploy/dev-workspace/dev_workspace.go b/pkg/deploy/dev-workspace/dev_workspace.go index 459b4df5a9..160aafa636 100644 --- a/pkg/deploy/dev-workspace/dev_workspace.go +++ b/pkg/deploy/dev-workspace/dev_workspace.go @@ -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 diff --git a/pkg/deploy/dev-workspace/dev_workspace_test.go b/pkg/deploy/dev-workspace/dev_workspace_test.go index 640702f3fe..33c728351d 100644 --- a/pkg/deploy/dev-workspace/dev_workspace_test.go +++ b/pkg/deploy/dev-workspace/dev_workspace_test.go @@ -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) diff --git a/pkg/deploy/dev-workspace/sync.go b/pkg/deploy/dev-workspace/sync.go index cb2faa9475..b18ac2b99c 100644 --- a/pkg/deploy/dev-workspace/sync.go +++ b/pkg/deploy/dev-workspace/sync.go @@ -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" @@ -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 } diff --git a/pkg/deploy/server/server_configmap.go b/pkg/deploy/server/server_configmap.go index 5af09dde4c..6b2be53ea6 100644 --- a/pkg/deploy/server/server_configmap.go +++ b/pkg/deploy/server/server_configmap.go @@ -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 != "" { diff --git a/pkg/deploy/test_util.go b/pkg/deploy/test_util.go index e676ffd01f..7fc0aa06da 100644 --- a/pkg/deploy/test_util.go +++ b/pkg/deploy/test_util.go @@ -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" @@ -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...) diff --git a/pkg/util/util.go b/pkg/util/util.go index 6843b8c613..f3723ff7cf 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -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 != ""