devfile / devworkspace-operator

Apache License 2.0
59 stars 50 forks source link

Home persistence should be disabled if ephemeral storage strategy is used #1203

Closed AObuchow closed 7 months ago

AObuchow commented 7 months ago

Description

If a devworkspace uses the ephemeral storage strategy, and the DWOC's field workspace.persistUserHome: true is set, then the devworkspace's deployment spec will be invalid because it will contain a volume named persistentHome, which is an invalid volume name in kubernetes (see https://github.com/devfile/devworkspace-operator/issues/1200). Even if the persistent home volume name was valid, the persistent home volume should not be injected into the devworkspace: an ephemeral storage workspace cannot have it's home directory persisted.

When we check if home persistence is enabled, we should also ensure persist storage is being used as well.

How To Reproduce

  1. Set workspace.persistUserHome: true in the DWOC
  2. Apply a devworkspace with ephemeral storage, eg:
kind: DevWorkspace
apiVersion: workspace.devfile.io/v1alpha2
metadata:
  name: plain-devworkspace-ephemeral
spec:
  started: true
  routingClass: 'basic'
  template:
    attributes:
        controller.devfile.io/storage-type: ephemeral
    components:
      - name: web-terminal
        container:
          image: quay.io/wto/web-terminal-tooling:next
          memoryRequest: 256Mi
          memoryLimit: 512Mi
          mountSources: true
          command:
           - "tail"
           - "-f"
           - "/dev/null"
  1. Check the workspace status (i.e. kubectl get dw -n $NAMESPACE) and see that the workspace has failed:
NAME                           DEVWORKSPACE ID             PHASE    INFO  
plain-devworkspace-ephemeral   workspace79f813e0f75a42f4   Failed   Error creating DevWorkspace deployment: Deployment.apps "workspace79f813e0f75a42f4" is invalid: [spec.template.spec.volumes[0].name: Invalid value: "persistentHome": a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end  
with an alphanumeric character (e.g. 'my-name',  or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?'), spec.template.spec.containers[0].volumeMounts[0].name: Not found: "persistentHome"]

Expected behavior

The workspace deployment succeeds and no persistent home volume is added to the workspace deployment's volumes or volumeMounts.

Additional context

Related upstream issue