This is an automated email from the ASF dual-hosted git repository. pcongiusti pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 177b1c1edaca74f3152027c8137a9898a7ee9f10 Author: pkalsi97 <[email protected]> AuthorDate: Tue Nov 4 14:56:53 2025 +0530 cli(reset): add force flag, namespace confirmation prompt, update e2e tests --- e2e/advanced/reset_test.go | 6 +++--- pkg/cmd/reset.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/e2e/advanced/reset_test.go b/e2e/advanced/reset_test.go index c2976c570..bc6564760 100644 --- a/e2e/advanced/reset_test.go +++ b/e2e/advanced/reset_test.go @@ -46,7 +46,7 @@ func TestKamelReset(t *testing.T) { g.Eventually(Kit(t, ctx, ns, IntegrationKit(t, ctx, ns, name)())).Should(Not(BeNil())) g.Eventually(Integration(t, ctx, ns, name)).Should(Not(BeNil())) - g.Expect(Kamel(t, ctx, "reset", "-n", ns).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "reset", "-n", ns, "-f").Execute()).To(Succeed()) g.Expect(Integration(t, ctx, ns, name)()).To(BeNil()) g.Expect(Kits(t, ctx, ns)()).To(HaveLen(0)) }) @@ -59,7 +59,7 @@ func TestKamelReset(t *testing.T) { g.Eventually(Kit(t, ctx, ns, IntegrationKit(t, ctx, ns, name)())).Should(Not(BeNil())) g.Eventually(Integration(t, ctx, ns, name)).Should(Not(BeNil())) - g.Expect(Kamel(t, ctx, "reset", "-n", ns, "--skip-integrations").Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "reset", "-n", ns, "--skip-integrations", "-f").Execute()).To(Succeed()) g.Expect(Integration(t, ctx, ns, name)()).To(Not(BeNil())) g.Expect(Kits(t, ctx, ns)()).To(HaveLen(0)) }) @@ -73,7 +73,7 @@ func TestKamelReset(t *testing.T) { g.Eventually(Kit(t, ctx, ns, kitName)).Should(Not(BeNil())) g.Eventually(Integration(t, ctx, ns, name)).Should(Not(BeNil())) - g.Expect(Kamel(t, ctx, "reset", "-n", ns, "--skip-kits").Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "reset", "-n", ns, "--skip-kits", "-f").Execute()).To(Succeed()) g.Expect(Integration(t, ctx, ns, name)()).To(BeNil()) g.Expect(Kit(t, ctx, ns, kitName)()).To(Not(BeNil())) }) diff --git a/pkg/cmd/reset.go b/pkg/cmd/reset.go index 251e711eb..a1cdb9aac 100644 --- a/pkg/cmd/reset.go +++ b/pkg/cmd/reset.go @@ -19,6 +19,7 @@ package cmd import ( "fmt" + "os" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" "github.com/apache/camel-k/v2/pkg/client" @@ -43,6 +44,7 @@ func newCmdReset(rootCmdOptions *RootCmdOptions) (*cobra.Command, *resetCmdOptio cmd.Flags().Bool("skip-kits", false, "Do not delete the integration kits") cmd.Flags().Bool("skip-integrations", false, "Do not delete the integrations") cmd.Flags().Bool("skip-bindings", false, "Do not delete the bindings/pipes") + cmd.Flags().BoolVarP(&options.Force, "force", "f", false, "Force reset without confirmation") return &cmd, &options } @@ -53,9 +55,25 @@ type resetCmdOptions struct { SkipKits bool `mapstructure:"skip-kits"` SkipIntegrations bool `mapstructure:"skip-integrations"` SkipBindings bool `mapstructure:"skip-bindings"` + Force bool `mapstructure:"force"` } func (o *resetCmdOptions) reset(cmd *cobra.Command, _ []string) { + if !o.Force { + fmt.Printf("Reset will delete Camel K resources in namespace '%s'.\n", o.Namespace) + fmt.Fprint(cmd.OutOrStdout(), "Type the namespace to confirm: ") + + var input string + if _, err := fmt.Fscan(os.Stdin, &input); err != nil { + fmt.Fprint(cmd.ErrOrStderr(), err) + return + } + if input != o.Namespace { + fmt.Fprintln(cmd.OutOrStdout(), "confirmation failed. aborting.") + return + } + } + c, err := o.GetCmdClient() if err != nil { fmt.Fprint(cmd.ErrOrStderr(), err)
