devspace-sh / devspace

DevSpace - The Fastest Developer Tool for Kubernetes ⚡ Automate your deployment workflow with DevSpace and develop software directly inside Kubernetes.
https://devspace.sh
Apache License 2.0
4.37k stars 361 forks source link

Improper renaming of volume on StatefulSet during replace #2403

Closed ryancharris closed 2 years ago

ryancharris commented 2 years ago

What happened?
A Pod in one of my StatefulSets was unable to find its associated volume mount because the newly generated spec improperly renames the volume to data.

Error log

08:10:22 start_dev: replace pod: create deployment: Deployment.apps "scheduler-queuer-worker-devspace" 
is invalid: spec.template.spec.containers[0].volumeMounts[0].name: Not found: "worker-state"

StatefulSet YAML

          volumeMounts:
            - name: worker-state
              mountPath: /mnt/worker-state

  volumeClaimTemplates:
    - metadata:
        name: worker-state
      spec:
        accessModes: [ "ReadWriteOnce" ]
        resources:
          requests:
            storage: 50Mi

Replaced pod spec

  volumes:
  - name: data
    persistentVolumeClaim:
      claimName: worker-state-scheduler-queuer-worker-0
  - downwardAPI:
      defaultMode: 511
      items:
      - fieldRef:
          apiVersion: v1
          fieldPath: metadata.annotations['devspace.sh/restart-helper-worker']
        mode: 511
        path: devspace-restart-helper
    name: devspace-restart-worker

What did you expect to happen instead?
As there were no changes to the underlying charts (and this StatefulSet works in an environment created with devspace v5), I would have expected this to work out-of-the-box.

How can we reproduce the bug? (as minimally and precisely as possible) I am running this using a profile (i.e. devspace dev -p sync-scheduler), which defines the dev block.

My devspace.yaml:

version: v2beta1
name: scheduler

...

deployments:
  scheduler:
    helm:
      chart:
        name: ${GIT_PROJECTS_WORKDIR}/helm-charts/charts/scheduler
      values:
        namespace: ${DEVSPACE_NAMESPACE}
        tag: 'devspace-test'
      valuesFiles:
        - ${GIT_PROJECTS_WORKDIR}/helm-charts/releases/dbt-labs/dev/main.yaml
        - ${GIT_PROJECTS_WORKDIR}/helm-charts/releases/dbt-labs/dev/scheduler.yaml

profiles:
  # devspace6 dev -p sync-scheduler
  - name: sync-scheduler
    description: Enable scheduler file syncing
    merge:
      dev:
        scheduler-queuer-worker:
          labelSelector:
            app.kubernetes.io/name: scheduler-queuer-worker
          container: worker
          command: ["/bin/sh", "-c", "/go/bin/queuer-worker"]
          logs:
            enabled: true
            lastLines: 1
          sync:
            - path: ./queuer-worker-dev:/go/bin/queuer-worker-dev
              file: true
              startContainer: true
              waitInitialSync: true
              disableDownload: true
              onUpload:
                exec:
                  # Copy dev executable to entrypoint location
                  - name: copy uploaded executable
                    command: cp
                    args:
                      - /go/bin/queuer-worker-dev
                      - /go/bin/queuer-worker
                restartContainer: true

Local Environment:

Anything else we need to know?
Nope!

FabianKramm commented 2 years ago

@ryancharris thanks a lot for creating this issue! We'll try to fix this as soon as possible.

ryancharris commented 2 years ago

@FabianKramm I issued a PR here: https://github.com/loft-sh/devspace/pull/2405