Skip to content

Commit

Permalink
move installer cmds with cluster prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
AdheipSingh committed Dec 22, 2024
1 parent c1efcd6 commit a836af2
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 181 deletions.
119 changes: 117 additions & 2 deletions cmd/uninstaller.go → cmd/cluster.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,136 @@
// 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 (
"context"
"fmt"
"log"

"os"
"pb/pkg/common"
"pb/pkg/helm"
"pb/pkg/installer"

"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)

var verbose bool

var InstallOssCmd = &cobra.Command{
Use: "install oss",
Short: "Deploy Parseable OSS",
Example: "pb cluster install oss",
Run: func(cmd *cobra.Command, _ []string) {
// Add verbose flag
cmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging")
installer.Installer(verbose)
},
}

// ListOssCmd lists the Parseable OSS servers
var ListOssCmd = &cobra.Command{
Use: "list oss",
Short: "List available Parseable OSS servers",
Example: "pb list oss",
Run: func(_ *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 list OSS servers: %v", err)
}

// Check if there are no entries
if len(entries) == 0 {
fmt.Println("No OSS servers found.")
return
}

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

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

table.Render()
},
}

// ShowValuesCmd lists the Parseable OSS servers
var ShowValuesCmd = &cobra.Command{
Use: "show values oss",
Short: "Show values available in Parseable OSS servers",
Example: "pb show values",
Run: func(_ *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 list OSS servers: %v", err)
}

// Check if there are no entries
if len(entries) == 0 {
fmt.Println("No OSS servers found.")
return
}

// Prompt user to select a cluster
selectedCluster, err := common.PromptClusterSelection(entries)
if err != nil {
log.Fatalf("Failed to select a cluster: %v", err)
}

values, err := helm.GetReleaseValues(selectedCluster.Name, selectedCluster.Namespace)
if err != nil {
log.Fatalf("Failed to get values for release: %v", err)
}

// Marshal values to YAML for nice formatting
yamlOutput, err := yaml.Marshal(values)
if err != nil {
log.Fatalf("Failed to marshal values to YAML: %v", err)
}

// Print the YAML output
fmt.Println(string(yamlOutput))

// Print instructions for fetching secret values
fmt.Printf("\nTo get secret values of the Parseable cluster, run the following command:\n")
fmt.Printf("kubectl get secret -n %s parseable-env-secret -o jsonpath='{.data}' | jq -r 'to_entries[] | \"\\(.key): \\(.value | @base64d)\"'\n", selectedCluster.Namespace)
},
}

// UninstallOssCmd removes Parseable OSS servers
var UninstallOssCmd = &cobra.Command{
Use: "oss",
Use: "uninstall oss",
Short: "Uninstall Parseable OSS servers",
Example: "pb uninstall oss",
Run: func(_ *cobra.Command, _ []string) {
Expand Down
35 changes: 0 additions & 35 deletions cmd/installer.go

This file was deleted.

62 changes: 0 additions & 62 deletions cmd/list.go

This file was deleted.

76 changes: 0 additions & 76 deletions cmd/show.go

This file was deleted.

28 changes: 22 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,23 @@ var install = &cobra.Command{
},
}

var cluster = &cobra.Command{
Use: "cluster",
Short: "Cluster operations for parseable.",
Long: "\nCluster operations for parseable cluster on kubernetes.",
PersistentPreRunE: combinedPreRun,
PersistentPostRun: func(cmd *cobra.Command, args []string) {
if os.Getenv("PB_ANALYTICS") == "disable" {
return
}
wg.Add(1)
go func() {
defer wg.Done()
analytics.PostRunAnalytics(cmd, "install", args)
}()
},
}

var list = &cobra.Command{
Use: "list",
Short: "List parseable on kubernetes cluster",
Expand Down Expand Up @@ -280,7 +297,10 @@ func main() {
schema.AddCommand(pb.GenerateSchemaCmd)
schema.AddCommand(pb.CreateSchemaCmd)

install.AddCommand(pb.InstallOssCmd)
cluster.AddCommand(pb.InstallOssCmd)
cluster.AddCommand(pb.ListOssCmd)
cluster.AddCommand(pb.ShowValuesCmd)
cluster.AddCommand(pb.UninstallOssCmd)

list.AddCommand(pb.ListOssCmd)

Expand All @@ -294,13 +314,9 @@ func main() {
cli.AddCommand(user)
cli.AddCommand(role)
cli.AddCommand(pb.TailCmd)
cli.AddCommand(cluster)

cli.AddCommand(pb.AutocompleteCmd)
cli.AddCommand(install)
cli.AddCommand(uninstall)
cli.AddCommand(schema)
cli.AddCommand(list)
cli.AddCommand(show)

// Set as command
pb.VersionCmd.Run = func(_ *cobra.Command, _ []string) {
Expand Down

0 comments on commit a836af2

Please sign in to comment.