Skip to content

Commit

Permalink
add DWOC field for persisting home directory
Browse files Browse the repository at this point in the history
Part of devfile#1097

Signed-off-by: Andrew Obuchowicz <aobuchow@redhat.com>
  • Loading branch information
AObuchow committed May 11, 2023
1 parent 39c517c commit 0ac9b46
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions apis/controller/v1alpha1/devworkspaceoperatorconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pkg/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions pkg/config/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 0ac9b46

Please sign in to comment.