Skip to content

Commit 752dbbb

Browse files
sungurokusunguroku
and
sunguroku
authored
deprecate kubectl and helm cmd (#4547)
Co-authored-by: sunguroku <trevor@porter.run>
1 parent f33f431 commit 752dbbb

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

cli/cmd/commands/all.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func RegisterCommands() (*cobra.Command, error) {
2828
rootCmd.AddCommand(registerCommand_Auth(cliConf))
2929
rootCmd.AddCommand(registerCommand_Cluster(cliConf))
3030
rootCmd.AddCommand(registerCommand_Config(cliConf))
31-
rootCmd.AddCommand(registerCommand_Connect(cliConf))
3231
rootCmd.AddCommand(registerCommand_Create(cliConf))
3332
rootCmd.AddCommand(registerCommand_Delete(cliConf))
3433
rootCmd.AddCommand(registerCommand_Deploy(cliConf))
@@ -40,7 +39,6 @@ func RegisterCommands() (*cobra.Command, error) {
4039
rootCmd.AddCommand(registerCommand_List(cliConf))
4140
rootCmd.AddCommand(registerCommand_Logs(cliConf))
4241
rootCmd.AddCommand(registerCommand_Open(cliConf))
43-
rootCmd.AddCommand(registerCommand_PortForward(cliConf))
4442
rootCmd.AddCommand(registerCommand_Project(cliConf))
4543
rootCmd.AddCommand(registerCommand_Registry(cliConf))
4644
rootCmd.AddCommand(registerCommand_Run(cliConf))

cli/cmd/commands/helm.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"os/exec"
8+
"strings"
89

910
api "github.com/porter-dev/porter/api/client"
1011
"github.com/porter-dev/porter/api/types"
@@ -13,9 +14,15 @@ import (
1314
)
1415

1516
func registerCommand_Helm(cliConf config.CLIConfig) *cobra.Command {
17+
depMsg := `This command is no longer available. Please consult documentation of the respective cloud provider to get access to the kubeconfig of the cluster.
18+
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
19+
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
20+
arise due to the change implemented directly on the Kubernetes cluster via kubectl.`
21+
1622
helmCmd := &cobra.Command{
17-
Use: "helm",
18-
Short: "Use helm to interact with a Porter cluster",
23+
Use: "helm",
24+
Short: "Use helm to interact with a Porter cluster",
25+
Deprecated: depMsg,
1926
Run: func(cmd *cobra.Command, args []string) {
2027
err := checkLoginAndRunWithConfig(cmd, cliConf, args, runHelm)
2128
if err != nil {
@@ -28,6 +35,12 @@ func registerCommand_Helm(cliConf config.CLIConfig) *cobra.Command {
2835
}
2936

3037
func runHelm(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error {
38+
// this will never error because it just ran
39+
user, _ := client.AuthCheck(ctx)
40+
if !strings.HasSuffix(user.Email, "@porter.run") {
41+
return fmt.Errorf("Forbidden")
42+
}
43+
3144
_, err := exec.LookPath("helm")
3245
if err != nil {
3346
return fmt.Errorf("error finding helm: %w", err)
@@ -51,7 +64,6 @@ func runHelm(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client
5164
execCommand.Stderr = os.Stderr
5265

5366
err = execCommand.Run()
54-
5567
if err != nil {
5668
return fmt.Errorf("error running helm: %w", err)
5769
}

cli/cmd/commands/kubectl.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"os/exec"
8+
"strings"
89

910
api "github.com/porter-dev/porter/api/client"
1011
"github.com/porter-dev/porter/api/types"
@@ -13,9 +14,15 @@ import (
1314
)
1415

1516
func registerCommand_Kubectl(cliConf config.CLIConfig) *cobra.Command {
17+
depMsg := `This command is no longer available. Please consult documentation of the respective cloud provider to get access to the kubeconfig of the cluster.
18+
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
19+
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
20+
arise due to the change implemented directly on the Kubernetes cluster via kubectl.`
21+
1622
kubectlCmd := &cobra.Command{
17-
Use: "kubectl",
18-
Short: "Use kubectl to interact with a Porter cluster",
23+
Use: "kubectl",
24+
Short: "Use kubectl to interact with a Porter cluster",
25+
Deprecated: depMsg,
1926
Run: func(cmd *cobra.Command, args []string) {
2027
err := checkLoginAndRunWithConfig(cmd, cliConf, args, runKubectl)
2128
if err != nil {
@@ -29,6 +36,12 @@ func registerCommand_Kubectl(cliConf config.CLIConfig) *cobra.Command {
2936
}
3037

3138
func runKubectl(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error {
39+
// this will never error because it just ran
40+
user, _ := client.AuthCheck(ctx)
41+
if !strings.HasSuffix(user.Email, "@porter.run") {
42+
return fmt.Errorf("Forbidden")
43+
}
44+
3245
_, err := exec.LookPath("kubectl")
3346
if err != nil {
3447
return fmt.Errorf("error finding kubectl: %w", err)
@@ -90,7 +103,6 @@ func downloadTempKubeconfig(ctx context.Context, client api.Client, cliConf conf
90103
}
91104

92105
_, err = tmpFile.Write(resp.Kubeconfig)
93-
94106
if err != nil {
95107
return "", fmt.Errorf("error writing kubeconfig to temp file: %w", err)
96108
}

cli/cmd/commands/portforward.go

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)