From c1d6ff9c1d49c5ebb0802ebfd8398440fb8f2c6b Mon Sep 17 00:00:00 2001 From: Mustafa Senoglu Date: Tue, 15 Sep 2026 11:14:29 +0300 Subject: [PATCH] install: clarify --wait flag behavior, default false Keep the existing opt-in behavior (consistent with velero backup create and velero restore create, where waiting is disabled by default and enabled with --wait), and clarify it in the command help text. Add tests pinning the --wait default (false) and flag parsing. Signed-off-by: Mustafa Senoglu --- changelogs/unreleased/10507-mmustafasenoglu | 1 + pkg/cmd/cli/install/install.go | 1 + pkg/cmd/cli/install/install_test.go | 62 +++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 changelogs/unreleased/10507-mmustafasenoglu diff --git a/changelogs/unreleased/10507-mmustafasenoglu b/changelogs/unreleased/10507-mmustafasenoglu new file mode 100644 index 000000000..0ecda4c07 --- /dev/null +++ b/changelogs/unreleased/10507-mmustafasenoglu @@ -0,0 +1 @@ +Add --wait flag to velero install to wait for Velero deployment to be ready diff --git a/pkg/cmd/cli/install/install.go b/pkg/cmd/cli/install/install.go index 67c9517da..6143f7b53 100644 --- a/pkg/cmd/cli/install/install.go +++ b/pkg/cmd/cli/install/install.go @@ -372,6 +372,7 @@ All namespaced resources will be placed in the 'velero' namespace by default. The '--namespace' flag can be used to specify a different namespace to install into. +By default, the command returns immediately after creating resources. Use '--wait' to wait for the Velero Deployment to be ready before proceeding. Use '-o yaml' or '-o json' with '--dry-run' to output all generated resources as text instead of sending the resources to the server. diff --git a/pkg/cmd/cli/install/install_test.go b/pkg/cmd/cli/install/install_test.go index 1e0e7a4cf..a6d874277 100644 --- a/pkg/cmd/cli/install/install_test.go +++ b/pkg/cmd/cli/install/install_test.go @@ -263,3 +263,65 @@ func TestNewCommandRunClosureOrder(t *testing.T) { // looks up the ConfigMap in targetNS (succeeds), Run returns early via DryRun. require.NoError(t, c.Execute()) } + +// TestWaitDefaultsToFalse verifies that --wait defaults to false, +// consistent with velero backup create and velero restore create. +func TestWaitDefaultsToFalse(t *testing.T) { + o := NewInstallOptions() + assert.False(t, o.Wait, "--wait should default to false") +} + +func TestWaitFlag(t *testing.T) { + tests := []struct { + name string + args []string + expectedWait bool + }{ + { + name: "default: wait is false", + args: []string{}, + expectedWait: false, + }, + { + name: "--wait enables wait", + args: []string{"--wait"}, + expectedWait: true, + }, + { + name: "--wait=false disables wait", + args: []string{"--wait=false"}, + expectedWait: false, + }, + { + name: "--wait=true enables wait", + args: []string{"--wait=true"}, + expectedWait: true, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + o := NewInstallOptions() + o.NoDefaultBackupLocation = true + o.UseVolumeSnapshots = false + o.NoSecret = true + + flags := pflag.NewFlagSet("test", pflag.ContinueOnError) + o.BindFlags(flags) + err := flags.Parse(tc.args) + require.NoError(t, err) + + c := makeValidateCmd() + c.SetContext(context.Background()) + + f := &factorymocks.Factory{} + f.On("Namespace").Return("velero") + f.On("KubebuilderClient").Return(velerotest.NewFakeControllerRuntimeClient(t), nil) + + require.NoError(t, o.Complete([]string{}, f)) + err = o.Validate(c, []string{}, f) + require.NoError(t, err) + assert.Equal(t, tc.expectedWait, o.Wait) + }) + } +}