diff --git a/cmd/proxy.go b/cmd/proxy.go new file mode 100644 index 0000000..20b6f99 --- /dev/null +++ b/cmd/proxy.go @@ -0,0 +1,37 @@ +package cmd + +import ( + "fmt" + "os" + "os/exec" + + "github.com/spf13/cobra" +) + +// ProxyCmd proxies Parseable deployment +var ProxyCmd = &cobra.Command{ + Use: "proxy", + Short: "Proxy Parseable deployment", + Example: "pb proxy", + RunE: func(cmd *cobra.Command, args []string) error { + // Define the kubectl command to forward ports + cmdArgs := []string{"port-forward", "svc/parseable", "8000:80", "-n", "parseable"} + + // Run the kubectl port-forward command + kubectlCmd := exec.Command("kubectl", cmdArgs...) + kubectlCmd.Stdout = os.Stdout // Forward kubectl's stdout to the terminal + kubectlCmd.Stderr = os.Stderr // Forward kubectl's stderr to the terminal + + // Start the kubectl port-forward process + if err := kubectlCmd.Start(); err != nil { + return fmt.Errorf("failed to start kubectl port-forward: %w", err) + } + + // Wait for the command to complete (this will block until the user terminates it) + if err := kubectlCmd.Wait(); err != nil { + return fmt.Errorf("kubectl port-forward process ended with error: %w", err) + } + + return nil + }, +} diff --git a/main.go b/main.go index dc0c557..fe06a21 100644 --- a/main.go +++ b/main.go @@ -165,16 +165,16 @@ var install = &cobra.Command{ Short: "Install parseable on kubernetes cluster", Long: "\ninstall command is used to install parseable oss/enterprise on k8s cluster..", 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) - // }() - // }, + 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 stream = &cobra.Command{ @@ -249,6 +249,7 @@ func main() { cli.AddCommand(analyze) cli.AddCommand(generate) cli.AddCommand(install) + cli.AddCommand(pb.ProxyCmd) cli.AddCommand(pb.AutocompleteCmd) // Set as command