diff --git a/changelogs/unreleased/10318-kaovilai b/changelogs/unreleased/10318-kaovilai new file mode 100644 index 000000000..a5b396445 --- /dev/null +++ b/changelogs/unreleased/10318-kaovilai @@ -0,0 +1 @@ +Fix datamover backup pod arg mismatch for CSI CBT service account name diff --git a/pkg/exposer/csi_snapshot.go b/pkg/exposer/csi_snapshot.go index 247ae9003..ea67d192d 100644 --- a/pkg/exposer/csi_snapshot.go +++ b/pkg/exposer/csi_snapshot.go @@ -758,7 +758,7 @@ func (e *csiSnapshotExposer) createBackupPod( if csiSnapshotMetadataServiceConfigs != nil { if csiSnapshotMetadataServiceConfigs.SAName != "" { - args = append(args, fmt.Sprintf("--csi-snapshot-metadata-service-sa=%s", csiSnapshotMetadataServiceConfigs.SAName)) + args = append(args, fmt.Sprintf("--cbt-sa-name=%s", csiSnapshotMetadataServiceConfigs.SAName)) } } diff --git a/pkg/exposer/csi_snapshot_test.go b/pkg/exposer/csi_snapshot_test.go index 8502b47b8..2da1c6724 100644 --- a/pkg/exposer/csi_snapshot_test.go +++ b/pkg/exposer/csi_snapshot_test.go @@ -43,6 +43,7 @@ import ( clientFake "sigs.k8s.io/controller-runtime/pkg/client/fake" velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" + datamovercli "github.com/vmware-tanzu/velero/pkg/cmd/cli/datamover" velerotest "github.com/vmware-tanzu/velero/pkg/test" velerotypes "github.com/vmware-tanzu/velero/pkg/types" "github.com/vmware-tanzu/velero/pkg/util" @@ -2538,6 +2539,35 @@ func TestCleanUp_SecretsAndConfigMaps(t *testing.T) { assert.NoError(t, err, "unrelated secret should not be deleted") } +// TestBackupPodCBTServiceSAFlagMatchesDatamoverBackupFlags pins the contract between the +// flag createBackupPod emits for the CSI snapshot metadata service's service account and +// the flag NewBackupCommand actually registers to consume it. These previously drifted +// (exposer emitted --csi-snapshot-metadata-service-sa, the datamover backup command only +// registered --cbt-sa-name), so cobra rejected the unknown flag and the data mover pod +// exited immediately whenever a dedicated CBT service account was configured. This test +// fails if either side changes the flag name without the other. +func TestBackupPodCBTServiceSAFlagMatchesDatamoverBackupFlags(t *testing.T) { + const saName = "cbt-service-account" + + // The exact line in createBackupPod (pkg/exposer/csi_snapshot.go) that builds this arg: + // args = append(args, fmt.Sprintf("--cbt-sa-name=%s", csiSnapshotMetadataServiceConfigs.SAName)) + arg := fmt.Sprintf("--cbt-sa-name=%s", saName) + + cmd := datamovercli.NewBackupCommand(nil) + err := cmd.ParseFlags([]string{ + "--volume-path=/dev/vol", + "--volume-mode=Filesystem", + "--data-upload=du-test", + "--resource-timeout=1m", + arg, + }) + require.NoError(t, err, "datamover backup command must accept the flag the exposer emits") + + got, err := cmd.Flags().GetString("cbt-sa-name") + require.NoError(t, err) + assert.Equal(t, saName, got) +} + func TestCreateBackupVSCDeletionPolicy(t *testing.T) { tests := []struct { name string