Skip to content

Commit

Permalink
Only mount che rest api when it is neccessary
Browse files Browse the repository at this point in the history
  • Loading branch information
JPinkney authored and amisevsk committed Apr 3, 2020
1 parent d81b1d9 commit bfe2779
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
6 changes: 6 additions & 0 deletions pkg/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,9 @@ const (
// Policy on webhook failure
MutateWebhookFailurePolicy = v1beta1.Fail
)

// constants for workspace controller
const (
// The ide of theia editor in devfile
TheiaEditorID = "eclipse/che-theia"
)
24 changes: 19 additions & 5 deletions pkg/controller/workspace/workspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ package workspace
import (
"context"
"fmt"
origLog "log"
"os"
"strings"

"github.com/che-incubator/che-workspace-operator/internal/cluster"
"github.com/che-incubator/che-workspace-operator/pkg/apis/workspace/v1alpha1"
workspacev1alpha1 "github.com/che-incubator/che-workspace-operator/pkg/apis/workspace/v1alpha1"
"github.com/che-incubator/che-workspace-operator/pkg/config"
"github.com/che-incubator/che-workspace-operator/pkg/controller/workspace/prerequisites"
Expand All @@ -26,16 +31,13 @@ import (
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
origLog "log"
"os"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
"strings"
)

var log = logf.Log.WithName("controller_workspace")
Expand Down Expand Up @@ -204,8 +206,11 @@ func (r *ReconcileWorkspace) Reconcile(request reconcile.Request) (reconcileResu
componentDescriptions := componentsStatus.ComponentDescriptions
reconcileStatus.Conditions = append(reconcileStatus.Conditions, workspacev1alpha1.WorkspaceComponentsReady)

cheRestApisComponent := getCheRestApisComponent(workspace.Name, workspace.Status.WorkspaceId, workspace.Namespace)
componentDescriptions = append(componentDescriptions, cheRestApisComponent)
// Only add che rest apis if theia editor is present in the devfile
if hasTheiaEditor(workspace.Spec.Devfile.Components) {
cheRestApisComponent := getCheRestApisComponent(workspace.Name, workspace.Status.WorkspaceId, workspace.Namespace)
componentDescriptions = append(componentDescriptions, cheRestApisComponent)
}

// Step two: Create routing, and wait for routing to be ready
routingStatus := provision.SyncRoutingToCluster(workspace, componentDescriptions, clusterAPI)
Expand Down Expand Up @@ -285,3 +290,12 @@ func getWorkspaceId(instance *workspacev1alpha1.Workspace) (string, error) {
}
return "workspace" + strings.Join(strings.Split(uid.String(), "-")[0:3], ""), nil
}

func hasTheiaEditor(components []workspacev1alpha1.ComponentSpec) bool {
for _, comp := range components {
if strings.Contains(comp.Id, config.TheiaEditorID) && comp.Type == v1alpha1.CheEditor {
return true
}
}
return false
}

0 comments on commit bfe2779

Please sign in to comment.