Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ spec:
image: "quay.io/eclipse/che-machine-exec:nightly"
# ^ it'll be replaced with new image below after https://github.com/eclipse/che/issues/16942 is fixed
# image: "quay.io/che-incubator/command-line-terminal:4.5.0"
command: ["/go/bin/che-machine-exec", "--authenticated-user-id", "$(CHE_WORKSPACE_CREATOR)"]
command: ["/go/bin/che-machine-exec",
"--authenticated-user-id", "$(CHE_WORKSPACE_CREATOR)",
"--idle-timeout", "$(CHE_WORKSPACE_IDLE_TIMEOUT)"]
ports:
- exposedPort: 4444
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ spec:
image: "quay.io/eclipse/che-machine-exec:nightly"
# ^ it'll be replaced with new image below after https://github.com/eclipse/che/issues/16942 is fixed
# image: "quay.io/che-incubator/command-line-terminal:nightly"
command: ["/go/bin/che-machine-exec", "--authenticated-user-id", "$(CHE_WORKSPACE_CREATOR)"]
command: ["/go/bin/che-machine-exec",
"--authenticated-user-id", "$(CHE_WORKSPACE_CREATOR)",
"--idle-timeout", "$(CHE_WORKSPACE_IDLE_TIMEOUT)"]
ports:
- exposedPort: 4444
env:
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ func (wc *ControllerConfig) Validate() error {
return nil
}

func (wc *ControllerConfig) GetWorkspaceIdleTimeout() string {
return wc.GetPropertyOrDefault(workspaceIdleTimeout, defaultWorkspaceIdleTimeout)
}

func updateConfigMap(client client.Client, meta metav1.Object, obj runtime.Object) {
if meta.GetNamespace() != ConfigMapReference.Namespace ||
meta.GetName() != ConfigMapReference.Name {
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/property.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ const (

webhooksEnabled = "che.webhooks.enabled"
defaultWebhooksEnabled = "false"

workspaceIdleTimeout = "che.workspace.idle_timeout"
defaultWorkspaceIdleTimeout = "15m"
)
4 changes: 4 additions & 0 deletions pkg/controller/workspace/env/common_env_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,9 @@ func CommonEnvironmentVariables(workspaceName, workspaceId, namespace, creator s
Name: "CHE_WORKSPACE_CREATOR",
Value: creator,
},
{
Name: "CHE_WORKSPACE_IDLE_TIMEOUT",
Value: config.ControllerCfg.GetWorkspaceIdleTimeout(),
},
}
}
11 changes: 9 additions & 2 deletions pkg/webhook/workspace/handler/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,24 @@ import (
"fmt"
"net/http"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"

"github.com/che-incubator/che-workspace-operator/pkg/apis/workspace/v1alpha1"
"github.com/che-incubator/che-workspace-operator/pkg/config"
"github.com/google/go-cmp/cmp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

var V1alpha1WorkspaceKind = metav1.GroupVersionKind{Kind: "Workspace", Group: "workspace.che.eclipse.org", Version: "v1alpha1"}

// StopStartDiffOption is comparing options that should be used to check if there is no other changes except changing started
var StopStartDiffOption = []cmp.Option{
// field managed by cluster and should be ignored while comparing
cmpopts.IgnoreFields(metav1.ObjectMeta{}, "ManagedFields"),
cmpopts.IgnoreFields(v1alpha1.WorkspaceSpec{}, "Started"),
}

func (h *WebhookHandler) MutateWorkspaceOnCreate(_ context.Context, req admission.Request) admission.Response {
wksp := &v1alpha1.Workspace{}

Expand Down Expand Up @@ -72,7 +79,7 @@ func (h *WebhookHandler) MutateWorkspaceOnUpdate(_ context.Context, req admissio
}

func (h *WebhookHandler) handleImmutableWorkspace(oldWksp, newWksp *v1alpha1.Workspace) admission.Response {
if cmp.Equal(oldWksp, newWksp, cmpopts.IgnoreFields(v1alpha1.WorkspaceSpec{}, "Started")) {
if cmp.Equal(oldWksp, newWksp, StopStartDiffOption[:]...) {
return admission.Allowed("immutable workspace is started/stopped")
}
return admission.Denied(fmt.Sprintf("workspace '%s' is immutable. To make modifications it must be deleted and recreated", oldWksp.Name))
Expand Down