Skip to content

Commit

Permalink
deprecate kubectl and helm cmd (#4547)
Browse files Browse the repository at this point in the history
Co-authored-by: sunguroku <[email protected]>
  • Loading branch information
sunguroku and sunguroku authored Apr 16, 2024
1 parent f33f431 commit 752dbbb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
2 changes: 0 additions & 2 deletions cli/cmd/commands/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down
18 changes: 15 additions & 3 deletions cli/cmd/commands/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down
18 changes: 15 additions & 3 deletions cli/cmd/commands/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
21 changes: 0 additions & 21 deletions cli/cmd/commands/portforward.go

This file was deleted.

0 comments on commit 752dbbb

Please sign in to comment.