From bd74906edc1c536d3208e615d9bf8bb9d9dcccae Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Wed, 21 Dec 2022 09:24:19 +0200 Subject: [PATCH] feat: Support ephemeral pvc strategy (#1580) * feat: Support ephemeral pvc strategy Signed-off-by: Anatolii Bazko --- api/v2/checluster_types.go | 9 ++++--- .../che-operator.clusterserviceversion.yaml | 4 +-- .../org.eclipse.che_checlusters.yaml | 8 +++--- .../bases/org.eclipse.che_checlusters.yaml | 7 ++++-- deploy/deployment/kubernetes/combined.yaml | 3 ++- ....eclipse.che.CustomResourceDefinition.yaml | 3 ++- deploy/deployment/openshift/combined.yaml | 3 ++- ....eclipse.che.CustomResourceDefinition.yaml | 3 ++- ....eclipse.che.CustomResourceDefinition.yaml | 3 ++- pkg/common/constants/constants.go | 1 + .../dev_workspace_config.go | 9 ++++--- .../dev_workspace_config_test.go | 25 +++++++++++++++++++ 12 files changed, 58 insertions(+), 20 deletions(-) diff --git a/api/v2/checluster_types.go b/api/v2/checluster_types.go index aff875432..2ac64391d 100644 --- a/api/v2/checluster_types.go +++ b/api/v2/checluster_types.go @@ -394,12 +394,13 @@ type WorkspaceStorage struct { // +optional PerWorkspaceStrategyPvcConfig *PVC `json:"perWorkspaceStrategyPvcConfig,omitempty"` // Persistent volume claim strategy for the Che server. - // The supported strategies are: `per-user` (all workspaces PVCs in one volume) - // and 'per-workspace' (each workspace is given its own individual PVC). - // For details, see https://github.com/eclipse/che/issues/21185. + // The supported strategies are: `per-user` (all workspaces PVCs in one volume), + // `per-workspace` (each workspace is given its own individual PVC) + // and `ephemeral` (non-persistent storage where local changes will be lost when + // the workspace is stopped.) // +optional // +kubebuilder:default:="per-user" - // +kubebuilder:validation:Enum=common;per-user;per-workspace + // +kubebuilder:validation:Enum=common;per-user;per-workspace;ephemeral PvcStrategy string `json:"pvcStrategy,omitempty"` } diff --git a/bundle/next/eclipse-che/manifests/che-operator.clusterserviceversion.yaml b/bundle/next/eclipse-che/manifests/che-operator.clusterserviceversion.yaml index 2dc229cca..89fff2d7b 100644 --- a/bundle/next/eclipse-che/manifests/che-operator.clusterserviceversion.yaml +++ b/bundle/next/eclipse-che/manifests/che-operator.clusterserviceversion.yaml @@ -77,7 +77,7 @@ metadata: operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 repository: https://github.com/eclipse-che/che-operator support: Eclipse Foundation - name: eclipse-che.v7.58.0-737.next + name: eclipse-che.v7.59.0-739.next namespace: placeholder spec: apiservicedefinitions: {} @@ -1233,7 +1233,7 @@ spec: minKubeVersion: 1.19.0 provider: name: Eclipse Foundation - version: 7.58.0-737.next + version: 7.59.0-739.next webhookdefinitions: - admissionReviewVersions: - v1 diff --git a/bundle/next/eclipse-che/manifests/org.eclipse.che_checlusters.yaml b/bundle/next/eclipse-che/manifests/org.eclipse.che_checlusters.yaml index f69f0539b..558ac3af4 100644 --- a/bundle/next/eclipse-che/manifests/org.eclipse.che_checlusters.yaml +++ b/bundle/next/eclipse-che/manifests/org.eclipse.che_checlusters.yaml @@ -7040,13 +7040,15 @@ spec: default: per-user description: 'Persistent volume claim strategy for the Che server. The supported strategies are: `per-user` (all - workspaces PVCs in one volume) and ''per-workspace'' (each - workspace is given its own individual PVC). For details, - see https://github.com/eclipse/che/issues/21185.' + workspaces PVCs in one volume), `per-workspace` (each + workspace is given its own individual PVC) and `ephemeral` + (non-persistent storage where local changes will be lost + when the workspace is stopped.)' enum: - common - per-user - per-workspace + - ephemeral type: string type: object tolerations: diff --git a/config/crd/bases/org.eclipse.che_checlusters.yaml b/config/crd/bases/org.eclipse.che_checlusters.yaml index 5d669843a..a4671fa6f 100644 --- a/config/crd/bases/org.eclipse.che_checlusters.yaml +++ b/config/crd/bases/org.eclipse.che_checlusters.yaml @@ -6849,12 +6849,15 @@ spec: default: per-user description: 'Persistent volume claim strategy for the Che server. The supported strategies are: `per-user` (all workspaces - PVCs in one volume) and ''per-workspace'' (each workspace - is given its own individual PVC). For details, see https://github.com/eclipse/che/issues/21185.' + PVCs in one volume), `per-workspace` (each workspace is + given its own individual PVC) and `ephemeral` (non-persistent + storage where local changes will be lost when the workspace + is stopped.)' enum: - common - per-user - per-workspace + - ephemeral type: string type: object tolerations: diff --git a/deploy/deployment/kubernetes/combined.yaml b/deploy/deployment/kubernetes/combined.yaml index 2c811f431..002e36b18 100644 --- a/deploy/deployment/kubernetes/combined.yaml +++ b/deploy/deployment/kubernetes/combined.yaml @@ -4632,11 +4632,12 @@ spec: type: object pvcStrategy: default: per-user - description: 'Persistent volume claim strategy for the Che server. The supported strategies are: `per-user` (all workspaces PVCs in one volume) and ''per-workspace'' (each workspace is given its own individual PVC). For details, see https://github.com/eclipse/che/issues/21185.' + description: 'Persistent volume claim strategy for the Che server. The supported strategies are: `per-user` (all workspaces PVCs in one volume), `per-workspace` (each workspace is given its own individual PVC) and `ephemeral` (non-persistent storage where local changes will be lost when the workspace is stopped.)' enum: - common - per-user - per-workspace + - ephemeral type: string type: object tolerations: diff --git a/deploy/deployment/kubernetes/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml b/deploy/deployment/kubernetes/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml index 048346e7a..2c505f667 100644 --- a/deploy/deployment/kubernetes/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml +++ b/deploy/deployment/kubernetes/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml @@ -4627,11 +4627,12 @@ spec: type: object pvcStrategy: default: per-user - description: 'Persistent volume claim strategy for the Che server. The supported strategies are: `per-user` (all workspaces PVCs in one volume) and ''per-workspace'' (each workspace is given its own individual PVC). For details, see https://github.com/eclipse/che/issues/21185.' + description: 'Persistent volume claim strategy for the Che server. The supported strategies are: `per-user` (all workspaces PVCs in one volume), `per-workspace` (each workspace is given its own individual PVC) and `ephemeral` (non-persistent storage where local changes will be lost when the workspace is stopped.)' enum: - common - per-user - per-workspace + - ephemeral type: string type: object tolerations: diff --git a/deploy/deployment/openshift/combined.yaml b/deploy/deployment/openshift/combined.yaml index 1e3f68351..c89dba731 100644 --- a/deploy/deployment/openshift/combined.yaml +++ b/deploy/deployment/openshift/combined.yaml @@ -4632,11 +4632,12 @@ spec: type: object pvcStrategy: default: per-user - description: 'Persistent volume claim strategy for the Che server. The supported strategies are: `per-user` (all workspaces PVCs in one volume) and ''per-workspace'' (each workspace is given its own individual PVC). For details, see https://github.com/eclipse/che/issues/21185.' + description: 'Persistent volume claim strategy for the Che server. The supported strategies are: `per-user` (all workspaces PVCs in one volume), `per-workspace` (each workspace is given its own individual PVC) and `ephemeral` (non-persistent storage where local changes will be lost when the workspace is stopped.)' enum: - common - per-user - per-workspace + - ephemeral type: string type: object tolerations: diff --git a/deploy/deployment/openshift/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml b/deploy/deployment/openshift/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml index c70036810..30af091e2 100644 --- a/deploy/deployment/openshift/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml +++ b/deploy/deployment/openshift/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml @@ -4627,11 +4627,12 @@ spec: type: object pvcStrategy: default: per-user - description: 'Persistent volume claim strategy for the Che server. The supported strategies are: `per-user` (all workspaces PVCs in one volume) and ''per-workspace'' (each workspace is given its own individual PVC). For details, see https://github.com/eclipse/che/issues/21185.' + description: 'Persistent volume claim strategy for the Che server. The supported strategies are: `per-user` (all workspaces PVCs in one volume), `per-workspace` (each workspace is given its own individual PVC) and `ephemeral` (non-persistent storage where local changes will be lost when the workspace is stopped.)' enum: - common - per-user - per-workspace + - ephemeral type: string type: object tolerations: diff --git a/helmcharts/next/crds/checlusters.org.eclipse.che.CustomResourceDefinition.yaml b/helmcharts/next/crds/checlusters.org.eclipse.che.CustomResourceDefinition.yaml index 048346e7a..2c505f667 100644 --- a/helmcharts/next/crds/checlusters.org.eclipse.che.CustomResourceDefinition.yaml +++ b/helmcharts/next/crds/checlusters.org.eclipse.che.CustomResourceDefinition.yaml @@ -4627,11 +4627,12 @@ spec: type: object pvcStrategy: default: per-user - description: 'Persistent volume claim strategy for the Che server. The supported strategies are: `per-user` (all workspaces PVCs in one volume) and ''per-workspace'' (each workspace is given its own individual PVC). For details, see https://github.com/eclipse/che/issues/21185.' + description: 'Persistent volume claim strategy for the Che server. The supported strategies are: `per-user` (all workspaces PVCs in one volume), `per-workspace` (each workspace is given its own individual PVC) and `ephemeral` (non-persistent storage where local changes will be lost when the workspace is stopped.)' enum: - common - per-user - per-workspace + - ephemeral type: string type: object tolerations: diff --git a/pkg/common/constants/constants.go b/pkg/common/constants/constants.go index 73fb2a0c4..87e3d372c 100644 --- a/pkg/common/constants/constants.go +++ b/pkg/common/constants/constants.go @@ -99,6 +99,7 @@ const ( PerUserPVCStorageStrategy = "per-user" DefaultPvcStorageStrategy = "per-user" PerWorkspacePVCStorageStrategy = "per-workspace" + EphemeralPVCStorageStrategy = "ephemeral" CommonPVCStorageStrategy = "common" DefaultAutoProvision = true DefaultWorkspaceJavaOpts = "-XX:MaxRAM=150m -XX:MaxRAMFraction=2 -XX:+UseParallelGC " + diff --git a/pkg/deploy/dev-workspace-config/dev_workspace_config.go b/pkg/deploy/dev-workspace-config/dev_workspace_config.go index c1244cb13..277c9f25a 100644 --- a/pkg/deploy/dev-workspace-config/dev_workspace_config.go +++ b/pkg/deploy/dev-workspace-config/dev_workspace_config.go @@ -90,10 +90,11 @@ func updateWorkspaceConfig(devEnvironments *chev2.CheClusterDevEnvironments, ope func updateWorkspaceStorageConfig(devEnvironments *chev2.CheClusterDevEnvironments, workspaceConfig *controllerv1alpha1.WorkspaceConfig) error { pvcStrategy := utils.GetValue(devEnvironments.Storage.PvcStrategy, constants.DefaultPvcStorageStrategy) isPerWorkspacePVCStorageStrategy := pvcStrategy == constants.PerWorkspacePVCStorageStrategy - pvc := map[bool]*chev2.PVC{ - true: devEnvironments.Storage.PerWorkspaceStrategyPvcConfig, - false: devEnvironments.Storage.PerUserStrategyPvcConfig, - }[isPerWorkspacePVCStorageStrategy] + pvc := map[string]*chev2.PVC{ + constants.PerUserPVCStorageStrategy: devEnvironments.Storage.PerUserStrategyPvcConfig, + constants.CommonPVCStorageStrategy: devEnvironments.Storage.PerUserStrategyPvcConfig, + constants.PerWorkspacePVCStorageStrategy: devEnvironments.Storage.PerWorkspaceStrategyPvcConfig, + }[pvcStrategy] if pvc != nil { if pvc.StorageClass != "" { diff --git a/pkg/deploy/dev-workspace-config/dev_workspace_config_test.go b/pkg/deploy/dev-workspace-config/dev_workspace_config_test.go index eb37b096d..895fc374a 100644 --- a/pkg/deploy/dev-workspace-config/dev_workspace_config_test.go +++ b/pkg/deploy/dev-workspace-config/dev_workspace_config_test.go @@ -90,6 +90,31 @@ func TestReconcileDevWorkspaceConfigPerUserStorage(t *testing.T) { }, expectedOperatorConfig: &controllerv1alpha1.OperatorConfiguration{Workspace: &controllerv1alpha1.WorkspaceConfig{}}, }, + { + name: "Create DevWorkspaceOperatorConfig with ephemeral strategy", + cheCluster: &chev2.CheCluster{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "eclipse-che", + Name: "eclipse-che", + }, + Spec: chev2.CheClusterSpec{ + DevEnvironments: chev2.CheClusterDevEnvironments{ + Storage: chev2.WorkspaceStorage{ + PvcStrategy: constants.EphemeralPVCStorageStrategy, + PerUserStrategyPvcConfig: &chev2.PVC{ + StorageClass: "test-storage", + ClaimSize: "10Gi", + }, + PerWorkspaceStrategyPvcConfig: &chev2.PVC{ + StorageClass: "test-storage", + ClaimSize: "10Gi", + }, + }, + }, + }, + }, + expectedOperatorConfig: &controllerv1alpha1.OperatorConfiguration{Workspace: &controllerv1alpha1.WorkspaceConfig{}}, + }, { name: "Create DevWorkspaceOperatorConfig with StorageClassName only", cheCluster: &chev2.CheCluster{