mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
Fix: Add confirmation prompt for vela adopt --apply with existing app name (#5376)
* Add confirmation prompt for vela adopt --apply with existing app name Signed-off-by: Karanjot Singh <drquark@duck.com> * Added changes according to the review Signed-off-by: Karanjot Singh <drquark@duck.com> * Fixed Userinput and used loadremoteApplication Signed-off-by: Karanjot Singh <drquark@duck.com> minor fixes Signed-off-by: Karanjot Singh <drquark@duck.com> used loadRemoteApplication Signed-off-by: Karanjot Singh <drquark@duck.com> Minor Fix Signed-off-by: Karanjot Singh <drquark@duck.com> Minor Fix Signed-off-by: Karanjot Singh <drquark@duck.com> Minor Fix Signed-off-by: Karanjot Singh <drquark@duck.com> Minor Fix Signed-off-by: Karanjot Singh <drquark@duck.com> Minor Fix Signed-off-by: Karanjot Singh <drquark@duck.com> Minor fix Signed-off-by: Karanjot Singh <drquark@duck.com> Minor fix Signed-off-by: Karanjot Singh <drquark@duck.com> * Used f.Client().Get method Signed-off-by: Karanjot Singh <drquark@duck.com> minor fix Signed-off-by: Karanjot Singh <drquark@duck.com> minor fix Signed-off-by: Karanjot Singh <drquark@duck.com> * Changed bool to False Signed-off-by: Karanjot Singh <drquark@duck.com> --------- Signed-off-by: Karanjot Singh <drquark@duck.com>
This commit is contained in:
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -99,6 +100,7 @@ type AdoptOptions struct {
|
||||
|
||||
Apply bool
|
||||
Recycle bool
|
||||
Yes bool
|
||||
|
||||
AdoptTemplateFile string
|
||||
AdoptTemplate string
|
||||
@@ -195,6 +197,20 @@ func (opt *AdoptOptions) Complete(f velacmd.Factory, cmd *cobra.Command, args []
|
||||
} else {
|
||||
opt.AdoptTemplate = defaultAdoptTemplate
|
||||
}
|
||||
if opt.AppName != "" {
|
||||
var ctx = context.Background()
|
||||
app := &v1beta1.Application{}
|
||||
err := f.Client().Get(ctx, apitypes.NamespacedName{Namespace: opt.AppNamespace, Name: opt.AppName}, app)
|
||||
if err == nil && app != nil {
|
||||
if !opt.Yes {
|
||||
userInput := NewUserInput()
|
||||
confirm := userInput.AskBool("Application '%s' already exists, apply will override the existing app with the adopted one, please confirm [Y/n]: "+opt.AppName, &UserInputOptions{AssumeYes: false})
|
||||
if !confirm {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
opt.AdoptTemplateCUEValue = cuecontext.New().CompileString(fmt.Sprintf("%s\n\n%s: %s", opt.AdoptTemplate, adoptCUETempVal, adoptCUETempFunc))
|
||||
return nil
|
||||
}
|
||||
@@ -457,6 +473,7 @@ func NewAdoptCommand(f velacmd.Factory, streams util.IOStreams) *cobra.Command {
|
||||
cmd.Flags().StringVarP(&o.HelmDriver, "driver", "d", o.HelmDriver, "The storage backend of helm adoption. Only take effect when --type=helm.")
|
||||
cmd.Flags().BoolVarP(&o.Apply, "apply", "", o.Apply, "If true, the application for adoption will be applied. Otherwise, it will only be printed.")
|
||||
cmd.Flags().BoolVarP(&o.Recycle, "recycle", "", o.Recycle, "If true, when the adoption application is successfully applied, the old storage (like Helm secret) will be recycled.")
|
||||
cmd.Flags().BoolVarP(&o.Yes, "yes", "y", o.Yes, "Skip confirmation prompt")
|
||||
return velacmd.NewCommandBuilder(f, cmd).
|
||||
WithNamespaceFlag().
|
||||
WithResponsiveWriter().
|
||||
|
||||
Reference in New Issue
Block a user