From 8206b79673417210b970265ec363662dc66d7804 Mon Sep 17 00:00:00 2001 From: Jeremy Schoemaker Date: Sat, 19 Sep 2026 17:32:48 -0500 Subject: [PATCH 1/2] Fix schedule create dropping annotations velero schedule create registers --annotations through BackupOptions.BindFlags, but the Schedule ObjectMeta it builds only sets Labels, so the flag was accepted and silently discarded. This matters beyond the Schedule object itself: BackupBuilder.FromSchedule falls back to schedule.Annotations when the template carries none, so every backup generated by the schedule lost the annotations too. velero schedule describe already prints these fields and the Schedule CRD already carries them, so the create path was the only gap. Same shape as #10526, which fixed the backup type being dropped on the same struct literal. Signed-off-by: Jeremy Schoemaker --- pkg/cmd/cli/schedule/create.go | 7 ++-- pkg/cmd/cli/schedule/create_test.go | 60 +++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 pkg/cmd/cli/schedule/create_test.go diff --git a/pkg/cmd/cli/schedule/create.go b/pkg/cmd/cli/schedule/create.go index cba121f5d..be0982887 100644 --- a/pkg/cmd/cli/schedule/create.go +++ b/pkg/cmd/cli/schedule/create.go @@ -136,9 +136,10 @@ func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error { schedule := &api.Schedule{ ObjectMeta: metav1.ObjectMeta{ - Namespace: f.Namespace(), - Name: o.BackupOptions.Name, - Labels: o.BackupOptions.Labels.Data(), + Namespace: f.Namespace(), + Name: o.BackupOptions.Name, + Labels: o.BackupOptions.Labels.Data(), + Annotations: o.BackupOptions.Annotations.Data(), }, Spec: api.ScheduleSpec{ Template: api.BackupSpec{ diff --git a/pkg/cmd/cli/schedule/create_test.go b/pkg/cmd/cli/schedule/create_test.go new file mode 100644 index 000000000..85b259ebc --- /dev/null +++ b/pkg/cmd/cli/schedule/create_test.go @@ -0,0 +1,60 @@ +/* +Copyright the Velero contributors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package schedule + +import ( + "testing" + + "github.com/spf13/cobra" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" + + velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" + factorymocks "github.com/vmware-tanzu/velero/pkg/client/mocks" + cmdtest "github.com/vmware-tanzu/velero/pkg/cmd/test" + velerotest "github.com/vmware-tanzu/velero/pkg/test" +) + +// TestCreateScheduleAppliesAnnotations verifies that --annotations reaches the created +// Schedule object. Backups generated from a Schedule inherit schedule.Annotations (see +// BackupBuilder.FromSchedule), so dropping them here silently strips the annotations from +// every backup the schedule produces. +func TestCreateScheduleAppliesAnnotations(t *testing.T) { + crClient := velerotest.NewFakeControllerRuntimeClient(t) + + f := &factorymocks.Factory{} + f.On("Namespace").Return(cmdtest.VeleroNameSpace) + f.On("KubebuilderClient").Return(crClient, nil) + + o := NewCreateOptions() + o.Schedule = "@daily" + o.BackupOptions.Name = "test-schedule" + require.NoError(t, o.BackupOptions.Annotations.Set("owner=team-a,purpose=nightly")) + require.NoError(t, o.BackupOptions.Labels.Set("env=prod")) + + require.NoError(t, o.Run(&cobra.Command{}, f)) + + created := new(velerov1api.Schedule) + require.NoError(t, crClient.Get(t.Context(), ctrlclient.ObjectKey{ + Namespace: cmdtest.VeleroNameSpace, + Name: "test-schedule", + }, created)) + + assert.Equal(t, map[string]string{"env": "prod"}, created.Labels) + assert.Equal(t, map[string]string{"owner": "team-a", "purpose": "nightly"}, created.Annotations) +} From e41ba0cafa2669e09a12c788a5559db1a82a1335 Mon Sep 17 00:00:00 2001 From: Jeremy Schoemaker Date: Sat, 19 Sep 2026 17:34:06 -0500 Subject: [PATCH 2/2] Add changelog for schedule create annotations fix Signed-off-by: Jeremy Schoemaker --- changelogs/unreleased/10549-shoemoney | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelogs/unreleased/10549-shoemoney diff --git a/changelogs/unreleased/10549-shoemoney b/changelogs/unreleased/10549-shoemoney new file mode 100644 index 000000000..f6e9d4aa2 --- /dev/null +++ b/changelogs/unreleased/10549-shoemoney @@ -0,0 +1 @@ +Fix velero schedule create silently dropping --annotations