Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Auto enable dev workspace engine after olm channel migration #1160

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions controllers/che/checluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@ func (r *CheClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}
}

if util.IsOpenShift && !checluster.Spec.DevWorkspace.Enable && util.GetCheOperatorNamespace() == deploy.DefaultNamespaceForAllNamespacesMode && devworkspace.IsDevWorkspaceOperatorCSVExists(deployContext) {
checluster.Spec.DevWorkspace.Enable = true
if err := deploy.UpdateCheCRSpec(deployContext, "enable", strconv.FormatBool(true)); err != nil {
return reconcile.Result{Requeue: true, RequeueAfter: time.Second * 1}, err
}
}

if util.IsOpenShift && checluster.Spec.DevWorkspace.Enable && checluster.Spec.Auth.NativeUserMode == nil {
newNativeUserModeValue := util.NewBoolPointer(true)
checluster.Spec.Auth.NativeUserMode = newNativeUserModeValue
Expand Down
2 changes: 1 addition & 1 deletion controllers/checlusterbackup/backup_data_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func backupDatabases(bctx *BackupContext, destDir string) (bool, error) {
return false, err
}

// Get and seve all dumps from the Postgres container
// Get and save all dumps from the Postgres container
for _, dbName := range databasesToBackup {
execReason := fmt.Sprintf("getting database %s dump", dbName)
dbDump, err := k8sClient.DoExecIntoPod(bctx.namespace, postgresPodName, getMoveDatabaseDumpScript(dbName), execReason)
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func main() {
os.Exit(1)
}

period := signal.GetTerminationGracePeriodSeconds(mgr.GetAPIReader(), watchNamespace)
period := signal.GetTerminationGracePeriodSeconds(mgr.GetAPIReader(), util.GetCheOperatorNamespace())
sigHandler := signal.SetupSignalHandler(period)

// we install the devworkspace CheCluster reconciler even if dw is not supported so that it
Expand Down
2 changes: 2 additions & 0 deletions pkg/deploy/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ const (
// CheServiceAccountName - service account name for che-server.
CheServiceAccountName = "che"

DefaultNamespaceForAllNamespacesMode = "openshift-operators"

// limits
DefaultDashboardMemoryLimit = "256Mi"
DefaultDashboardMemoryRequest = "32Mi"
Expand Down
6 changes: 3 additions & 3 deletions pkg/deploy/dev-workspace/dev_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func ReconcileDevWorkspace(deployContext *deploy.DeployContext) (done bool, err
return true, nil
}

if isDevWorkspaceOperatorCSVExists(deployContext) {
if IsDevWorkspaceOperatorCSVExists(deployContext) {
// Do nothing if DevWorkspace has been already deployed via OLM
return true, nil
}
Expand Down Expand Up @@ -165,14 +165,14 @@ func isDevWorkspaceDeploymentExists(deployContext *deploy.DeployContext) (bool,
}, &appsv1.Deployment{})
}

func isDevWorkspaceOperatorCSVExists(deployContext *deploy.DeployContext) bool {
func IsDevWorkspaceOperatorCSVExists(deployContext *deploy.DeployContext) bool {
// If clusterserviceversions resource doesn't exist in cluster DWO as well will not be present
if !util.HasK8SResourceObject(deployContext.ClusterAPI.DiscoveryClient, ClusterServiceVersionResourceName) {
return false
}

csvList := &operatorsv1alpha1.ClusterServiceVersionList{}
err := deployContext.ClusterAPI.Client.List(context.TODO(), csvList, &client.ListOptions{})
err := deployContext.ClusterAPI.Client.List(context.TODO(), csvList, &client.ListOptions{Namespace: deploy.DefaultNamespaceForAllNamespacesMode})
if err != nil {
return false
}
Expand Down
40 changes: 40 additions & 0 deletions pkg/util/namespace_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Copyright (c) 2012-2021 Red Hat, Inc.
// This program and the accompanying materials are made
// available under the terms of the Eclipse Public License 2.0
// which is available at https://www.eclipse.org/legal/epl-2.0/
//
// SPDX-License-Identifier: EPL-2.0
//
// Contributors:
// Red Hat, Inc. - initial API and implementation
//
package util

import (
"io/ioutil"

"github.com/sirupsen/logrus"
)

const (
namespaceFile = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
)

var operator_namespace string

func readNamespace() string {
nsBytes, err := ioutil.ReadFile(namespaceFile)
if err != nil {
logrus.Fatal("Failed to get operator namespace", err)
}
return string(nsBytes)
}

// GetCheOperatorNamespace returns namespace for current Eclipse Che operator.
func GetCheOperatorNamespace() string {
if operator_namespace == "" && !IsTestMode() {
operator_namespace = readNamespace()
}
return operator_namespace
}