Просмотр исходного кода

deprecate kubectl and helm cmd (#4547)

Co-authored-by: sunguroku <trevor@porter.run>
sunguroku 2 лет назад
Родитель
Сommit
752dbbb5a0
4 измененных файлов с 30 добавлено и 29 удалено
  1. 0 2
      cli/cmd/commands/all.go
  2. 15 3
      cli/cmd/commands/helm.go
  3. 15 3
      cli/cmd/commands/kubectl.go
  4. 0 21
      cli/cmd/commands/portforward.go

+ 0 - 2
cli/cmd/commands/all.go

@@ -28,7 +28,6 @@ func RegisterCommands() (*cobra.Command, error) {
 	rootCmd.AddCommand(registerCommand_Auth(cliConf))
 	rootCmd.AddCommand(registerCommand_Cluster(cliConf))
 	rootCmd.AddCommand(registerCommand_Config(cliConf))
-	rootCmd.AddCommand(registerCommand_Connect(cliConf))
 	rootCmd.AddCommand(registerCommand_Create(cliConf))
 	rootCmd.AddCommand(registerCommand_Delete(cliConf))
 	rootCmd.AddCommand(registerCommand_Deploy(cliConf))
@@ -40,7 +39,6 @@ func RegisterCommands() (*cobra.Command, error) {
 	rootCmd.AddCommand(registerCommand_List(cliConf))
 	rootCmd.AddCommand(registerCommand_Logs(cliConf))
 	rootCmd.AddCommand(registerCommand_Open(cliConf))
-	rootCmd.AddCommand(registerCommand_PortForward(cliConf))
 	rootCmd.AddCommand(registerCommand_Project(cliConf))
 	rootCmd.AddCommand(registerCommand_Registry(cliConf))
 	rootCmd.AddCommand(registerCommand_Run(cliConf))

+ 15 - 3
cli/cmd/commands/helm.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"os"
 	"os/exec"
+	"strings"
 
 	api "github.com/porter-dev/porter/api/client"
 	"github.com/porter-dev/porter/api/types"
@@ -13,9 +14,15 @@ import (
 )
 
 func registerCommand_Helm(cliConf config.CLIConfig) *cobra.Command {
+	depMsg := `This command is no longer available. Please consult documentation of the respective cloud provider to get access to the kubeconfig of the cluster. 
+	Note that any change made directly on the kubernetes cluster under the hood can degrade the performance and reliability of the cluster, and Porter will 
+	automatically reconcile any changes that pose a threat to the uptime of the cluster to its original state. Porter is not responsible for the issues that 
+	arise due to the change implemented directly on the Kubernetes cluster via kubectl.`
+
 	helmCmd := &cobra.Command{
-		Use:   "helm",
-		Short: "Use helm to interact with a Porter cluster",
+		Use:        "helm",
+		Short:      "Use helm to interact with a Porter cluster",
+		Deprecated: depMsg,
 		Run: func(cmd *cobra.Command, args []string) {
 			err := checkLoginAndRunWithConfig(cmd, cliConf, args, runHelm)
 			if err != nil {
@@ -28,6 +35,12 @@ func registerCommand_Helm(cliConf config.CLIConfig) *cobra.Command {
 }
 
 func runHelm(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error {
+	// this will never error because it just ran
+	user, _ := client.AuthCheck(ctx)
+	if !strings.HasSuffix(user.Email, "@porter.run") {
+		return fmt.Errorf("Forbidden")
+	}
+
 	_, err := exec.LookPath("helm")
 	if err != nil {
 		return fmt.Errorf("error finding helm: %w", err)
@@ -51,7 +64,6 @@ func runHelm(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client
 	execCommand.Stderr = os.Stderr
 
 	err = execCommand.Run()
-
 	if err != nil {
 		return fmt.Errorf("error running helm: %w", err)
 	}

+ 15 - 3
cli/cmd/commands/kubectl.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"os"
 	"os/exec"
+	"strings"
 
 	api "github.com/porter-dev/porter/api/client"
 	"github.com/porter-dev/porter/api/types"
@@ -13,9 +14,15 @@ import (
 )
 
 func registerCommand_Kubectl(cliConf config.CLIConfig) *cobra.Command {
+	depMsg := `This command is no longer available. Please consult documentation of the respective cloud provider to get access to the kubeconfig of the cluster. 
+	Note that any change made directly on the kubernetes cluster under the hood can degrade the performance and reliability of the cluster, and Porter will 
+	automatically reconcile any changes that pose a threat to the uptime of the cluster to its original state. Porter is not responsible for the issues that 
+	arise due to the change implemented directly on the Kubernetes cluster via kubectl.`
+
 	kubectlCmd := &cobra.Command{
-		Use:   "kubectl",
-		Short: "Use kubectl to interact with a Porter cluster",
+		Use:        "kubectl",
+		Short:      "Use kubectl to interact with a Porter cluster",
+		Deprecated: depMsg,
 		Run: func(cmd *cobra.Command, args []string) {
 			err := checkLoginAndRunWithConfig(cmd, cliConf, args, runKubectl)
 			if err != nil {
@@ -29,6 +36,12 @@ func registerCommand_Kubectl(cliConf config.CLIConfig) *cobra.Command {
 }
 
 func runKubectl(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error {
+	// this will never error because it just ran
+	user, _ := client.AuthCheck(ctx)
+	if !strings.HasSuffix(user.Email, "@porter.run") {
+		return fmt.Errorf("Forbidden")
+	}
+
 	_, err := exec.LookPath("kubectl")
 	if err != nil {
 		return fmt.Errorf("error finding kubectl: %w", err)
@@ -90,7 +103,6 @@ func downloadTempKubeconfig(ctx context.Context, client api.Client, cliConf conf
 	}
 
 	_, err = tmpFile.Write(resp.Kubeconfig)
-
 	if err != nil {
 		return "", fmt.Errorf("error writing kubeconfig to temp file: %w", err)
 	}

+ 0 - 21
cli/cmd/commands/portforward.go

@@ -1,21 +0,0 @@
-package commands
-
-import (
-	"fmt"
-
-	"github.com/fatih/color"
-	"github.com/porter-dev/porter/cli/cmd/config"
-	"github.com/spf13/cobra"
-)
-
-func registerCommand_PortForward(_ config.CLIConfig) *cobra.Command {
-	portForwardCmd := &cobra.Command{
-		Use: "port-forward [release] [LOCAL_PORT:]REMOTE_PORT [...[LOCAL_PORT_N:]REMOTE_PORT_N]",
-		Deprecated: fmt.Sprintf("please use the %s command instead.",
-			color.New(color.FgYellow, color.Bold).Sprintf("porter kubectl -- port-forward"),
-		),
-		DisableFlagParsing: true,
-	}
-
-	return portForwardCmd
-}