From 18a5816b48ec683e0b3484719885a8604f3ee3bb Mon Sep 17 00:00:00 2001 From: Cole Snodgrass Date: Mon, 10 Jun 2024 17:20:19 -0700 Subject: [PATCH] add persist flag to uninstall command --- internal/cmd/local/local/cmd.go | 15 ++++++++++----- internal/cmd/local/local_uninstall.go | 6 +++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/internal/cmd/local/local/cmd.go b/internal/cmd/local/local/cmd.go index c64ab3f..98f17a6 100644 --- a/internal/cmd/local/local/cmd.go +++ b/internal/cmd/local/local/cmd.go @@ -278,20 +278,20 @@ func (c *Command) Install(ctx context.Context, user, pass string) error { // Create minio PV and PVC if _, err := c.k8s.TestClientSet().CoreV1().PersistentVolumes().Create(ctx, pv(airbyteNamespace, "airbyte-minio-pv"), metav1.CreateOptions{}); err != nil { - pterm.Error.Printfln("Failed to create airbyte persistent volume: %s", err.Error()) + pterm.Error.Printfln("Failed to create persistent volume: %s", err.Error()) } if _, err := c.k8s.TestClientSet().CoreV1().PersistentVolumeClaims(airbyteNamespace).Create(ctx, pvc("airbyte-minio-pv-claim-airbyte-minio-0", "airbyte-minio-pv"), metav1.CreateOptions{}); err != nil { - pterm.Error.Printfln("Failed to create airbyte persistent volume claim: %s", err.Error()) + pterm.Error.Printfln("Failed to create persistent volume claim: %s", err.Error()) } // Create database PV and PVC if _, err := c.k8s.TestClientSet().CoreV1().PersistentVolumes().Create(ctx, pv(airbyteNamespace, "airbyte-volume-db"), metav1.CreateOptions{}); err != nil { - pterm.Error.Printfln("Failed to create airbyte persistent volume: %s", err.Error()) + pterm.Error.Printfln("Failed to create persistent volume: %s", err.Error()) } if _, err := c.k8s.TestClientSet().CoreV1().PersistentVolumeClaims(airbyteNamespace).Create(ctx, pvc("airbyte-volume-db-airbyte-db-0", "airbyte-volume-db"), metav1.CreateOptions{}); err != nil { - pterm.Error.Printfln("Failed to create airbyte persistent volume claim: %s", err.Error()) + pterm.Error.Printfln("Failed to create persistent volume claim: %s", err.Error()) } var telUser string @@ -478,7 +478,12 @@ func (c *Command) handleBasicAuthSecret(ctx context.Context, user, pass string) } // Uninstall handles the uninstallation of Airbyte. -func (c *Command) Uninstall(ctx context.Context) error { +func (c *Command) Uninstall(ctx context.Context, persist bool) error { + // if not removing persisted data, then this is a no-op + if !persist { + return nil + } + { c.spinner.UpdateText(fmt.Sprintf("Verifying %s Helm Chart installation status", airbyteChartName)) diff --git a/internal/cmd/local/local_uninstall.go b/internal/cmd/local/local_uninstall.go index 7cfc648..a5ff0a4 100644 --- a/internal/cmd/local/local_uninstall.go +++ b/internal/cmd/local/local_uninstall.go @@ -12,6 +12,8 @@ import ( func NewCmdUninstall(provider k8s.Provider) *cobra.Command { spinner := &pterm.DefaultSpinner + var flagPersist bool + cmd := &cobra.Command{ Use: "uninstall", Short: "Uninstall Airbyte locally", @@ -54,7 +56,7 @@ func NewCmdUninstall(provider k8s.Provider) *cobra.Command { pterm.Warning.Printfln("Failed to initialize 'local' command\nUninstallation attempt will continue") pterm.Debug.Printfln("Initialization of 'local' failed with %s", err.Error()) } else { - if err := lc.Uninstall(cmd.Context()); err != nil { + if err := lc.Uninstall(cmd.Context(), flagPersist); err != nil { pterm.Warning.Printfln("could not complete uninstall: %s", err.Error()) pterm.Warning.Println("will still attempt to uninstall the cluster") } @@ -74,5 +76,7 @@ func NewCmdUninstall(provider k8s.Provider) *cobra.Command { }, } + cmd.Flags().BoolVar(&flagPersist, "persist", false, "remove persisted data") + return cmd }