Add confirm flag to velero plugin add

Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
This commit is contained in:
Tiger Kaovilai
2024-03-26 05:32:04 +07:00
parent f1f7f04233
commit 3c243653c4
9 changed files with 80 additions and 39 deletions

View File

@@ -32,6 +32,7 @@ import (
"github.com/vmware-tanzu/velero/pkg/builder"
"github.com/vmware-tanzu/velero/pkg/client"
"github.com/vmware-tanzu/velero/pkg/cmd"
"github.com/vmware-tanzu/velero/pkg/cmd/util/confirm"
"github.com/vmware-tanzu/velero/pkg/cmd/util/flag"
)
@@ -45,12 +46,17 @@ func NewAddCommand(f client.Factory) *cobra.Command {
imagePullPolicies = []string{string(corev1api.PullAlways), string(corev1api.PullIfNotPresent), string(corev1api.PullNever)}
imagePullPolicyFlag = flag.NewEnum(string(corev1api.PullIfNotPresent), imagePullPolicies...)
)
o := confirm.NewConfirmOptionsWithDescription("Confirm add?, may cause the Velero server pod restart which will fail all ongoing jobs")
c := &cobra.Command{
Use: "add IMAGE",
Short: "Add a plugin",
Args: cobra.ExactArgs(1),
Run: func(c *cobra.Command, args []string) {
if !o.Confirm && !confirm.GetConfirmation("velero plugin add may cause the Velero server pod restart, so it is a dangerous operation",
"once Velero server restarts, all the ongoing jobs will fail.") {
// Don't do anything unless we get confirmation
return
}
kubeClient, err := f.KubeClient()
if err != nil {
cmd.CheckError(err)
@@ -122,6 +128,7 @@ func NewAddCommand(f client.Factory) *cobra.Command {
}
c.Flags().Var(imagePullPolicyFlag, "image-pull-policy", fmt.Sprintf("The imagePullPolicy for the plugin container. Valid values are %s.", strings.Join(imagePullPolicies, ", ")))
o.BindFlags(c.Flags())
return c
}