-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c835c1d
commit 1f22051
Showing
8 changed files
with
253 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,82 @@ | ||
// Copyright (c) 2024 Parseable, Inc | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"pb/pkg/common" | ||
"pb/pkg/installer" | ||
"pb/pkg/helm" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var UnInstallOssCmd = &cobra.Command{ | ||
// UninstallOssCmd removes Parseable OSS servers | ||
var UninstallOssCmd = &cobra.Command{ | ||
Use: "oss", | ||
Short: "Uninstall Parseable OSS", | ||
Short: "Uninstall Parseable OSS servers", | ||
Example: "pb uninstall oss", | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
// Add verbose flag | ||
cmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging") | ||
Run: func(cmd *cobra.Command, _ []string) { | ||
_, err := common.PromptK8sContext() | ||
if err != nil { | ||
log.Fatalf("Failed to prompt for Kubernetes context: %v", err) | ||
} | ||
|
||
// Read the installer data from the ConfigMap | ||
entries, err := common.ReadInstallerConfigMap() | ||
if err != nil { | ||
log.Fatalf("Failed to fetch OSS servers: %v", err) | ||
} | ||
|
||
// Check if there are no entries | ||
if len(entries) == 0 { | ||
fmt.Println(common.Yellow + "\nNo Parseable OSS servers found to uninstall.\n") | ||
return | ||
} | ||
|
||
// Prompt user to select a cluster | ||
selectedCluster, err := common.PromptClusterSelection(entries) | ||
if err != nil { | ||
log.Fatalf("Failed to select a cluster: %v", err) | ||
} | ||
|
||
if err := installer.Uninstaller(verbose); err != nil { | ||
fmt.Println(common.Red + err.Error()) | ||
// Confirm uninstallation | ||
fmt.Printf("\nYou have selected to uninstall the cluster '%s' in namespace '%s'.\n", selectedCluster.Name, selectedCluster.Namespace) | ||
if !common.PromptConfirmation(fmt.Sprintf("Do you want to proceed with uninstalling '%s'?", selectedCluster.Name)) { | ||
fmt.Println(common.Yellow + "Uninstall operation canceled.") | ||
return | ||
} | ||
|
||
return nil | ||
// Perform uninstallation | ||
if err := uninstallCluster(selectedCluster); err != nil { | ||
log.Fatalf("Failed to uninstall cluster: %v", err) | ||
} | ||
|
||
fmt.Println(common.Green + "Uninstallation completed successfully." + common.Reset) | ||
}, | ||
} | ||
|
||
func uninstallCluster(entry common.InstallerEntry) error { | ||
helmApp := helm.Helm{ | ||
ReleaseName: entry.Name, | ||
Namespace: entry.Namespace, | ||
RepoName: "parseable", | ||
RepoURL: "https://charts.parseable.com", | ||
ChartName: "parseable", | ||
Version: entry.Version, | ||
} | ||
|
||
fmt.Println(common.Yellow + "Starting uninstallation process..." + common.Reset) | ||
|
||
spinner := common.CreateDeploymentSpinner(entry.Namespace, fmt.Sprintf("Uninstalling Parseable OSS '%s'...", entry.Name)) | ||
spinner.Start() | ||
|
||
_, err := helm.Uninstall(helmApp, false) | ||
spinner.Stop() | ||
|
||
if err != nil { | ||
return fmt.Errorf("failed to uninstall Parseable OSS: %v", err) | ||
} | ||
|
||
fmt.Printf(common.Green+"Successfully uninstalled '%s' from namespace '%s'.\n"+common.Reset, entry.Name, entry.Namespace) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.