Skip to content

Commit

Permalink
add uninstall oss
Browse files Browse the repository at this point in the history
  • Loading branch information
AdheipSingh committed Dec 20, 2024
1 parent e9ace0f commit 2a86d6c
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 138 deletions.
13 changes: 9 additions & 4 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"log"
"os"
"path/filepath"
"pb/pkg/common"
"pb/pkg/installer"

"github.com/olekukonko/tablewriter"
Expand Down Expand Up @@ -47,10 +48,10 @@ var ListOssCmd = &cobra.Command{

// Display the entries in a table format
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "Namespace", "Version", "Status"})
table.SetHeader([]string{"Name", "Namespace", "Version", "Kubernetes Context", "Status"})

for _, entry := range entries {
table.Append([]string{entry.Name, entry.Namespace, entry.Version, entry.Status})
table.Append([]string{entry.Name, entry.Namespace, entry.Version, entry.Context, entry.Status})
}

table.Render()
Expand All @@ -64,11 +65,15 @@ func readInstallerFile() ([]installer.InstallerEntry, error) {
if err != nil {
return nil, fmt.Errorf("failed to get user home directory: %w", err)
}
filePath := filepath.Join(homeDir, ".parseable", "installer.yaml")
filePath := filepath.Join(homeDir, ".parseable", "pb", "installer.yaml")

// Check if the file exists
if _, err := os.Stat(filePath); os.IsNotExist(err) {
return nil, fmt.Errorf("installer file not found at %s", filePath)
fmt.Println(common.Yellow + "\n────────────────────────────────────────────────────────────────────────────")
fmt.Println(common.Yellow + "⚠️ No Parseable clusters found!")
fmt.Println(common.Yellow + "To get started, run: `pb install oss`")
fmt.Println(common.Yellow + "────────────────────────────────────────────────────────────────────────────\n")
return nil, nil

Check failure on line 76 in cmd/list.go

View workflow job for this annotation

GitHub Actions / Build and Test the Go code

fmt.Println arg list ends with redundant newline
}

// Read and parse the file
Expand Down
13 changes: 7 additions & 6 deletions cmd/uninstaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
package cmd

import (
"fmt"
"pb/pkg/common"
"pb/pkg/installer"

"github.com/spf13/cobra"
)

Expand All @@ -27,12 +31,9 @@ var UnInstallOssCmd = &cobra.Command{
// Add verbose flag
cmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging")

// Print the banner
//printBanner()

// if err := installer.Uninstaller(verbose); err != nil {
// fmt.Println(common.Red + err.Error())
// }
if err := installer.Uninstaller(verbose); err != nil {
fmt.Println(common.Red + err.Error())
}

return nil
},
Expand Down
14 changes: 4 additions & 10 deletions pkg/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func waterFall(verbose bool) {
log.Fatalf("Failed to prompt for plan selection: %v", err)
}

if _, err := promptK8sContext(); err != nil {
context, err := promptK8sContext()
if err != nil {
log.Fatalf("Failed to prompt for kubernetes context: %v", err)
}

Expand Down Expand Up @@ -117,6 +118,7 @@ func waterFall(verbose bool) {
Name: pbInfo.Name,
Namespace: pbInfo.Namespace,
Version: config.Version,
Context: context,
Status: "success",
}); err != nil {
log.Fatalf("Failed to update parseable installer file, err: %v", err)
Expand Down Expand Up @@ -866,22 +868,14 @@ func openBrowser(url string) {
cmd.Start()
}

// InstallerEntry represents an entry in the installer.yaml file
type InstallerEntry struct {
Name string `yaml:"name"`
Namespace string `yaml:"namespace"`
Version string `yaml:"version"`
Status string `yaml:"status"` // todo ideally should be a heartbeat
}

// updateInstallerFile updates or creates the installer.yaml file with deployment info
func updateInstallerFile(entry InstallerEntry) error {
// Define the file path
homeDir, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("failed to get user home directory: %w", err)
}
filePath := filepath.Join(homeDir, ".parseable", "installer.yaml")
filePath := filepath.Join(homeDir, ".parseable", "pb", "installer.yaml")

// Create the directory if it doesn't exist
if err := os.MkdirAll(filepath.Dir(filePath), 0755); err != nil {
Expand Down
9 changes: 9 additions & 0 deletions pkg/installer/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,12 @@ type Blob struct {
Container string // Container name in the Azure Blob store.
URL string // URL of the Azure Blob store.
}

// InstallerEntry represents an entry in the installer.yaml file
type InstallerEntry struct {
Name string `yaml:"name"`
Namespace string `yaml:"namespace"`
Version string `yaml:"version"`
Context string `yaml:"context"`
Status string `yaml:"status"` // todo ideally should be a heartbeat
}
Loading

0 comments on commit 2a86d6c

Please sign in to comment.