Skip to content

Scope schedule and repo CLI list calls to the Velero namespace - #10482

Merged
sseago merged 2 commits into
velero-io:mainfrom
MaxFreedomPollard:scope-schedule-repo-cli-to-velero-namespace
Sep 9, 2026
Merged

sseago merged 2 commits into
velero-io:mainfrom
MaxFreedomPollard:scope-schedule-repo-cli-to-velero-namespace

Conversation

@MaxFreedomPollard

Copy link
Copy Markdown
Contributor

Please add a summary of your change

velero schedule get, velero schedule describe, velero schedule pause, velero schedule unpause and velero repo get list across every namespace in the cluster instead of the Velero namespace. Each of them builds a ctrlclient.ListOptions that carries a LabelSelector and no Namespace: pkg/cmd/cli/schedule/get.go:61, pkg/cmd/cli/schedule/describe.go:59, pkg/cmd/cli/schedule/pause.go:115 and pkg/cmd/cli/repo/get.go:61.

The named-object branch a few lines above each of those already scopes to f.Namespace() (schedule/get.go:51, schedule/describe.go:49, schedule/pause.go:98, repo/get.go:51), and schedule delete scopes its list at pkg/cmd/cli/schedule/delete.go:101, as do backup get, restore get, backup describe, restore describe and snapshot-location get. So velero schedule get foo and velero schedule get disagree about which namespace they are reading from.

On the three read commands the effect is that another installation's Schedules and BackupRepositories appear in the output. runPause also writes. velero schedule pause --all -n velero collects Schedules from every namespace and then sets Spec.Paused on each one (pause.go:141 and pause.go:143), so it pauses the schedules belonging to every other Velero installation in the cluster and prints Schedule <name> paused successfully for them. velero schedule unpause --all unpauses them through the same function.

The fix is Namespace: f.Namespace() on those four List calls.

Neither pkg/cmd/cli/schedule nor pkg/cmd/cli/repo had a test file, so the regression tests are new. Each seeds a fake controller-runtime client with one object in velero-test and one in another-velero, points the factory at velero-test, and asserts the object in another-velero is not listed, not described and not paused. All five fail on main:

$ go test -count=1 ./pkg/cmd/cli/schedule/... ./pkg/cmd/cli/repo/...
--- FAIL: TestNewGetCommandListsOnlyTheVeleroNamespace (0.00s)
    get_test.go:76: "NAME     STATUS ...\ntheirs   New ...\nours     New ..." should not contain "theirs"
--- FAIL: TestNewDescribeCommandDescribesOnlyTheVeleroNamespace (0.04s)
    describe_test.go:49: "Name:  theirs\nNamespace:  another-velero\n..." should not contain "theirs"
--- FAIL: TestRunPauseOnlyTouchesTheVeleroNamespace/--all (0.00s)
    pause_test.go:84: Should be false
--- FAIL: TestRunPauseOnlyTouchesTheVeleroNamespace/--selector (0.00s)
    pause_test.go:84: Should be false
--- FAIL: TestRunUnpauseOnlyTouchesTheVeleroNamespace (0.00s)
    pause_test.go:111: Should be true
FAIL    github.com/vmware-tanzu/velero/pkg/cmd/cli/schedule
FAIL    github.com/vmware-tanzu/velero/pkg/cmd/cli/repo

and pass with the change:

$ go test -count=1 ./pkg/cmd/cli/schedule/... ./pkg/cmd/cli/repo/...
ok      github.com/vmware-tanzu/velero/pkg/cmd/cli/schedule      0.865s
ok      github.com/vmware-tanzu/velero/pkg/cmd/cli/repo 1.485s

go test ./pkg/cmd/... passes, and golangci-lint run --config .golangci.yaml ./pkg/cmd/cli/schedule/... ./pkg/cmd/cli/repo/... on v2.12.0 reports nothing.

Does your change fix a particular issue?

No issue filed for this one.

Please indicate you've done the following:

velero schedule get, velero schedule describe, velero schedule
pause/unpause and velero repo get built a ctrlclient.ListOptions with a
LabelSelector but no Namespace, so the list ran across every namespace in
the cluster. Their single-name paths in the same functions already scope
to f.Namespace(), and every sibling command (backup get, restore get,
backup describe, restore describe, snapshot-location get, schedule
delete) passes Namespace too, so the omission was an oversight rather
than intent.

The read commands print another installation's Schedules and
BackupRepositories. runPause is worse: velero schedule pause --all and
velero schedule unpause --all fetch Schedules from every namespace and
then write Spec.Paused on each, so pausing one installation's schedules
pauses every other installation's schedules as well.

Add Namespace: f.Namespace() to the four List calls:

  pkg/cmd/cli/schedule/get.go:61
  pkg/cmd/cli/schedule/describe.go:59
  pkg/cmd/cli/schedule/pause.go:114
  pkg/cmd/cli/repo/get.go:61

Neither pkg/cmd/cli/schedule nor pkg/cmd/cli/repo had any tests, so the
regression tests are new files. Each seeds a fake client with one object
in the Velero namespace and one in another-velero, and asserts the second
is neither listed, described, nor paused.

Signed-off-by: Max Freedom Pollard <[email protected]>
@MaxFreedomPollard
MaxFreedomPollard requested a review from a team as a code owner September 6, 2026 06:04
@netlify

netlify Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

👷 Deploy request for velero pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 57c58f3

Signed-off-by: Max Freedom Pollard <[email protected]>
@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sseago
sseago merged commit 4c007c0 into velero-io:main Sep 9, 2026
69 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants