Skip to content

Commit 2220909

Browse files
Merge pull request #69 from mihaichitic/ND-7573
- add overwrite-kubeconfig-cluster-server flag for kube related commands - show urlHandle for environments - add allow-extra-fields for template validation - successive remote-dev up won't recreate Pod
2 parents 412ec50 + b46c72a commit 2220909

File tree

31 files changed

+386
-139
lines changed

31 files changed

+386
-139
lines changed

.github/workflows/audit.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
audit:
10-
runs-on: ubuntu-20.04
10+
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v4
1313

cmd/component/action/port_forward.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ func init() {
1818
settings := config.GetSettings()
1919

2020
var (
21-
resourcePath string
22-
podName string
21+
resourcePath string
22+
podName string
23+
overrideClusterServer string
2324
)
2425

2526
command := &cobra.Command{
@@ -54,13 +55,18 @@ func init() {
5455

5556
portForwardManager.WithPortMappings(portMappings)
5657

58+
if overrideClusterServer != "" {
59+
portForwardManager.WithOverrideClusterServer(overrideClusterServer)
60+
}
61+
5762
environmentResource, err := environment.NewFromWizard(&settings.Profile.Context, resourcePath)
5863
if err != nil {
5964
return err
6065
}
6166

6267
_ = portForwardManager.
6368
WithEnvironmentResource(environmentResource).
69+
WithWorkspace().
6470
PrepareKubernetesClient()
6571

6672
if podName != "" {
@@ -88,6 +94,7 @@ func init() {
8894

8995
flags.StringVarP(&resourcePath, "resource", "s", "", "The cluster resource to use (namespace/kind/name format).")
9096
flags.StringVar(&podName, "pod", "", "The resource pod to forward ports to.")
97+
flags.StringVar(&overrideClusterServer, "override-kubeconfig-cluster-server", "", "Override kubeconfig cluster server with :port, host:port or scheme://host:port")
9198

9299
mainCmd.AddCommand(command)
93100
}

cmd/component/action/ssh.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type SSHOptions struct {
2626

2727
NoTTY bool
2828
NoBanner bool
29+
30+
OverrideClusterServer string
2931
}
3032

3133
func (o *SSHOptions) UpdateFlagSet(flags *pflag.FlagSet) {
@@ -35,6 +37,8 @@ func (o *SSHOptions) UpdateFlagSet(flags *pflag.FlagSet) {
3537

3638
flags.BoolVar(&o.NoTTY, "no-tty", o.NoTTY, "Do not allocate a TTY")
3739
flags.BoolVar(&o.NoBanner, "no-banner", o.NoBanner, "Do not show environment banner before ssh")
40+
41+
flags.StringVar(&o.OverrideClusterServer, "override-kubeconfig-cluster-server", o.OverrideClusterServer, "Override kubeconfig cluster server with :port, host:port or scheme://host:port")
3842
}
3943

4044
func (o *SSHOptions) MakeExecOptions(kubeConfig *environment.KubeConfigItem) *k8sExec.Options {
@@ -63,7 +67,8 @@ func init() {
6367
settings := config.GetSettings()
6468

6569
sshOptions := SSHOptions{
66-
Shell: "/bin/sh",
70+
Shell: "/bin/sh",
71+
OverrideClusterServer: "",
6772
}
6873

6974
command := &cobra.Command{
@@ -78,7 +83,7 @@ func init() {
7883
return err
7984
}
8085

81-
kubeConfigOptions := environment.NewKubeConfigOptions(componentItem.GetEnvironment())
86+
kubeConfigOptions := environment.NewKubeConfigOptions(componentItem.GetEnvironment(), sshOptions.OverrideClusterServer)
8287
kubeConfig, err := environment.KubeConfig(kubeConfigOptions)
8388
if err != nil {
8489
return err

cmd/component_debug/ssh.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ type SSHOptions struct {
99

1010
NoTTY bool
1111
NoBanner bool
12+
13+
OverrideClusterServer string
1214
}
1315

1416
func (o *SSHOptions) UpdateFlagSet(flags *pflag.FlagSet) {

cmd/component_debug/up.go

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package component_debug
22

33
import (
4-
"fmt"
4+
"fmt"
55

66
"bunnyshell.com/cli/pkg/config"
7-
"bunnyshell.com/cli/pkg/k8s/bridge"
8-
"bunnyshell.com/cli/pkg/lib"
97
"bunnyshell.com/cli/pkg/debug_component/action"
108
upAction "bunnyshell.com/cli/pkg/debug_component/action/up"
9+
"bunnyshell.com/cli/pkg/k8s/bridge"
10+
"bunnyshell.com/cli/pkg/lib"
1111
"github.com/spf13/cobra"
1212
)
1313

@@ -16,8 +16,9 @@ func init() {
1616
settings := config.GetSettings()
1717

1818
sshOptions := SSHOptions{
19-
Shell: "/bin/sh",
20-
}
19+
Shell: "/bin/sh",
20+
OverrideClusterServer: "",
21+
}
2122

2223
resourceLoader := bridge.NewResourceLoader()
2324
upOptions := upAction.NewOptions(resourceLoader)
@@ -53,14 +54,15 @@ func init() {
5354
return err
5455
}
5556

56-
selectedContainerName, err := upAction.GetSelectedContainerName()
57-
if err != nil {
58-
return err
59-
}
57+
selectedContainerName, err := upAction.GetSelectedContainerName()
58+
if err != nil {
59+
return err
60+
}
6061

61-
if err = startSSH(*resourceLoader.Component.Id, selectedContainerName, sshOptions, cmd, args); err != nil {
62-
return fmt.Errorf("debug SSH exited with: %s", err)
63-
}
62+
sshOptions.OverrideClusterServer = upParameters.OverrideClusterServer
63+
if err = startSSH(*resourceLoader.Component.Id, selectedContainerName, sshOptions, cmd, args); err != nil {
64+
return fmt.Errorf("debug SSH exited with: %s", err)
65+
}
6466

6567
return upAction.Close()
6668
},
@@ -81,31 +83,35 @@ func init() {
8183
}
8284

8385
func startSSH(componentId string, containerName string, sshOptions SSHOptions, cmd *cobra.Command, args []string) error {
84-
proxyArgs := []string{
85-
"components", "ssh",
86-
"--id", componentId,
87-
}
86+
proxyArgs := []string{
87+
"components", "ssh",
88+
"--id", componentId,
89+
}
8890

89-
proxyArgs = append(proxyArgs, "--container", containerName)
91+
proxyArgs = append(proxyArgs, "--container", containerName)
92+
93+
if sshOptions.Shell != "" {
94+
proxyArgs = append(proxyArgs, "--shell", sshOptions.Shell)
95+
}
9096

91-
if sshOptions.Shell != "" {
92-
proxyArgs = append(proxyArgs, "--shell", sshOptions.Shell)
93-
}
97+
if sshOptions.NoBanner {
98+
proxyArgs = append(proxyArgs, "--no-banner")
99+
}
94100

95-
if sshOptions.NoBanner {
96-
proxyArgs = append(proxyArgs, "--no-banner")
97-
}
101+
if sshOptions.NoTTY {
102+
proxyArgs = append(proxyArgs, "--no-tty")
103+
}
98104

99-
if sshOptions.NoTTY {
100-
proxyArgs = append(proxyArgs, "--no-tty")
101-
}
105+
if sshOptions.OverrideClusterServer != "" {
106+
proxyArgs = append(proxyArgs, "--override-kubeconfig-cluster-server", sshOptions.OverrideClusterServer)
107+
}
102108

103-
root := cmd.Root()
104-
root.SetArgs(append(proxyArgs, args...))
109+
root := cmd.Root()
110+
root.SetArgs(append(proxyArgs, args...))
105111

106-
if err := root.Execute(); err != nil {
107-
return err
108-
}
112+
if err := root.Execute(); err != nil {
113+
return err
114+
}
109115

110-
return nil
116+
return nil
111117
}

cmd/template/validate.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ func getSource(validateSource ValidateSource, validateOptions template.ValidateO
150150
source.SetValidateComponents(true)
151151
}
152152

153+
if !validateOptions.AllowExtraFields {
154+
source.SetValidateAllowExtraFields(false)
155+
}
156+
153157
action := sdk.ValidateSourceGitAsTemplateValidateActionSource(source)
154158

155159
return &action, nil
@@ -172,6 +176,10 @@ func getSource(validateSource ValidateSource, validateOptions template.ValidateO
172176
source.SetValidateForOrganizationId(validateOptions.Organization)
173177
}
174178

179+
if !validateOptions.AllowExtraFields {
180+
source.SetValidateAllowExtraFields(false)
181+
}
182+
175183
action := sdk.ValidateSourceStringAsTemplateValidateActionSource(source)
176184

177185
return &action, nil

cmd/utils/port_forward.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ func init() {
1313
settings := config.GetSettings()
1414

1515
var (
16-
resourcePath string
17-
podName string
16+
resourcePath string
17+
podName string
18+
overrideClusterServer string
1819
)
1920

2021
command := &cobra.Command{
@@ -33,6 +34,7 @@ func init() {
3334
"--id", settings.Profile.Context.ServiceComponent,
3435
"--resource", resourcePath,
3536
"--pod", podName,
37+
"--override-kubeconfig-cluster-server", overrideClusterServer,
3638
}, portMappings...))
3739

3840
if err := root.Execute(); err != nil {
@@ -49,6 +51,7 @@ func init() {
4951

5052
flags.StringVarP(&resourcePath, "resource", "s", "", "The cluster resource to use (namespace/kind/name format).")
5153
flags.StringVar(&podName, "pod", "", "The resource pod to forward ports to.")
54+
flags.StringVar(&overrideClusterServer, "override-kubeconfig-cluster-server", "", "Override kubeconfig cluster server with :port, host:port or scheme://host:port")
5255

5356
mainCmd.AddCommand(command)
5457
}

cmd/utils/ssh.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func init() {
5050
proxyArgs = append(proxyArgs, "--no-tty")
5151
}
5252

53+
if sshOptions.OverrideClusterServer != "" {
54+
proxyArgs = append(proxyArgs, "--override-kubeconfig-cluster-server", sshOptions.OverrideClusterServer)
55+
}
56+
5357
root := cmd.Root()
5458
root.SetArgs(append(proxyArgs, args...))
5559

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ toolchain go1.23.2
77
replace github.com/imdario/mergo => github.com/imdario/mergo v0.3.16
88

99
require (
10-
bunnyshell.com/dev v0.7.1
11-
bunnyshell.com/sdk v0.20.1
10+
bunnyshell.com/dev v0.7.2
11+
bunnyshell.com/sdk v0.20.3
1212
github.com/AlecAivazis/survey/v2 v2.3.7
1313
github.com/MakeNowJust/heredoc v1.0.0
1414
github.com/avast/retry-go/v4 v4.6.0

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
bunnyshell.com/dev v0.7.1 h1:mNLF0h2bbrTi9LNr2e2zFUC2fGg8TUh/9SM5rTXkzDI=
2-
bunnyshell.com/dev v0.7.1/go.mod h1:+Xk46UXX9AW0nHrFMdO/IwpUPfALrck1/qI+LIXsDmE=
3-
bunnyshell.com/sdk v0.20.1 h1:YxmYrW8UXGNNtLe+l6pXFKyndgwyEyQtdX0f5rHV1fE=
4-
bunnyshell.com/sdk v0.20.1/go.mod h1:RfgfUzZ4WHZGCkToUfu2/hoQS6XsQc8IdPTVAlpS138=
1+
bunnyshell.com/dev v0.7.2 h1:fa0ZvnIAXLVJINCJqo7uenjHmjPrlHmY18Zc8ypo/6E=
2+
bunnyshell.com/dev v0.7.2/go.mod h1:+Xk46UXX9AW0nHrFMdO/IwpUPfALrck1/qI+LIXsDmE=
3+
bunnyshell.com/sdk v0.20.3 h1:Kd2s/fhkMrn6Jqp9UmnXfNu12Oiwg+hgNSNBOIBYPH8=
4+
bunnyshell.com/sdk v0.20.3/go.mod h1:RfgfUzZ4WHZGCkToUfu2/hoQS6XsQc8IdPTVAlpS138=
55
github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=
66
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
77
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=

0 commit comments

Comments
 (0)