Skip to content

Declare the Pod volumes used by the prepare container - #502

Merged
brandond merged 1 commit into
rancher:masterfrom
spicysharkco:fix/prepare-volumes
Nov 27, 2026
Merged

brandond merged 1 commit into
rancher:masterfrom
spicysharkco:fix/prepare-volumes

Conversation

@spicysharkco

Copy link
Copy Markdown
Contributor

A Plan can give the prepare container a volume that the upgrade container does not use:

spec:
  prepare:
    image: rancher/k3s-upgrade
    volumes:
    - name: prepare-data
      source: /var/lib/prepare
      destination: /prepare
  upgrade:
    image: rancher/k3s-upgrade

Since #364 the prepare container mounts spec.prepare.volumes. The Job's Pod declares the volumes from spec.upgrade.volumes but not those from spec.prepare.volumes. The Pod spec then has a mount of prepare-data with no matching volume, which Pod validation rejects as Not found.

The fix also declares each prepare volume whose name the Pod does not already declare. A volume that spec.upgrade.volumes also lists, or one named like the Job's own host-root, is declared once.

The new It in pkg/upgrade/job/job_suite_test.go builds a Job with prepare volumes shared-data, host-root and prepare-data and upgrade volumes upgrade-data and shared-data. It checks the declared names and the host path of prepare-data. On master it fails:

  [FAILED] Expected
      <[]string | len:4, cap:4>: ["host-root", "pod-info", "upgrade-data", "shared-data"]
  to consist of
      <[]string | len:5, cap:5>: ["host-root", "pod-info", "upgrade-data", "shared-data", "prepare-data"]
  the missing elements were
      <[]string | len:1, cap:1>: ["prepare-data"]

go test -tags=test -count=1 ./pkg/upgrade/job/ -ginkgo.focus='Declaring the Pod volumes' fails 3 of 3 runs on master and passes 3 of 3 with the fix. go test -cover -tags=test ./pkg/... and golangci-lint run pass.

The prepare container mounts the volumes in spec.prepare.volumes, but
the Job's Pod declared only its own volumes and those in
spec.upgrade.volumes. A prepare volume that upgrade does not list left a
volume mount with no matching volume, which Pod validation rejects as
"Not found".

Declare the prepare volumes as well, skipping any name the Pod already
declares, so a volume that upgrade also lists is declared once.

@brandond brandond left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@brandond
brandond merged commit 2d838f0 into rancher:master Nov 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants