From 0ac9b46574c0d634a89dc6c27812e54d99f5c0e5 Mon Sep 17 00:00:00 2001 From: Andrew Obuchowicz Date: Mon, 1 May 2023 13:45:31 -0400 Subject: [PATCH] add DWOC field for persisting home directory Part of #1097 Signed-off-by: Andrew Obuchowicz --- .../v1alpha1/devworkspaceoperatorconfig_types.go | 9 +++++++++ pkg/config/defaults.go | 5 ++++- pkg/config/sync.go | 13 +++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/apis/controller/v1alpha1/devworkspaceoperatorconfig_types.go b/apis/controller/v1alpha1/devworkspaceoperatorconfig_types.go index 692687bb4..714358917 100644 --- a/apis/controller/v1alpha1/devworkspaceoperatorconfig_types.go +++ b/apis/controller/v1alpha1/devworkspaceoperatorconfig_types.go @@ -131,6 +131,12 @@ type ServiceAccountToken struct { ExpirationSeconds int64 `json:"expirationSeconds,omitempty"` } +type PersistentHomeConfig struct { + // Determines whether the `/home/user/` directory in workspaces should persist between workspace + // shutdown and startup. Disabled by default. + Enabled *bool `json:"enabled,omitempty"` +} + type WorkspaceConfig struct { // ImagePullPolicy defines the imagePullPolicy used for containers in a DevWorkspace // For additional information, see Kubernetes documentation for imagePullPolicy. If @@ -164,6 +170,9 @@ type WorkspaceConfig struct { // DefaultStorageSize defines an optional struct with fields to specify the sizes of Persistent Volume Claims for storage // classes used by DevWorkspaces. DefaultStorageSize *StorageSizes `json:"defaultStorageSize,omitempty"` + // PersistUserHome defines configuration options for persisting the `/home/user/` + // directory in workspaces. + PersistUserHome *PersistentHomeConfig `json:"persistUserHome,omitempty"` // IdleTimeout determines how long a workspace should sit idle before being // automatically scaled down. Proper functionality of this configuration property // requires support in the workspace being started. If not specified, the default diff --git a/pkg/config/defaults.go b/pkg/config/defaults.go index 05d13e92d..ecf8e192d 100644 --- a/pkg/config/defaults.go +++ b/pkg/config/defaults.go @@ -43,9 +43,12 @@ var defaultConfig = &v1alpha1.OperatorConfiguration{ Common: &commonStorageSize, PerWorkspace: &perWorkspaceStorageSize, }, + PersistUserHome: &v1alpha1.PersistentHomeConfig{ + Enabled: pointer.Bool(false), + }, IdleTimeout: "15m", ProgressTimeout: "5m", - CleanupOnStop: pointer.BoolPtr(false), + CleanupOnStop: pointer.Bool(false), PodSecurityContext: nil, ContainerSecurityContext: &corev1.SecurityContext{}, DefaultTemplate: nil, diff --git a/pkg/config/sync.go b/pkg/config/sync.go index 7b66ef60d..6ac6d60af 100644 --- a/pkg/config/sync.go +++ b/pkg/config/sync.go @@ -327,6 +327,14 @@ func mergeConfig(from, to *controller.OperatorConfiguration) { to.Workspace.DefaultStorageSize.PerWorkspace = &perWorkspaceSizeCopy } } + if from.Workspace.PersistUserHome != nil { + if to.Workspace.PersistUserHome == nil { + to.Workspace.PersistUserHome = &controller.PersistentHomeConfig{} + } + if from.Workspace.PersistUserHome.Enabled != nil { + to.Workspace.PersistUserHome.Enabled = from.Workspace.PersistUserHome.Enabled + } + } if from.Workspace.DefaultTemplate != nil { templateSpecContentCopy := from.Workspace.DefaultTemplate.DeepCopy() to.Workspace.DefaultTemplate = templateSpecContentCopy @@ -450,6 +458,11 @@ func GetCurrentConfigString(currConfig *controller.OperatorConfiguration) string config = append(config, fmt.Sprintf("workspace.defaultStorageSize.perWorkspace=%s", workspace.DefaultStorageSize.PerWorkspace.String())) } } + if workspace.PersistUserHome != nil { + if workspace.PersistUserHome.Enabled != nil && *workspace.PersistUserHome.Enabled != *defaultConfig.Workspace.PersistUserHome.Enabled { + config = append(config, fmt.Sprintf("workspace.persistUserHomeDierctory.enabled=%t", *workspace.PersistUserHome.Enabled)) + } + } if !reflect.DeepEqual(workspace.PodSecurityContext, defaultConfig.Workspace.PodSecurityContext) { config = append(config, "workspace.podSecurityContext is set") }