Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/audit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
audit:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

Expand Down
11 changes: 9 additions & 2 deletions cmd/component/action/port_forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ func init() {
settings := config.GetSettings()

var (
resourcePath string
podName string
resourcePath string
podName string
overrideClusterServer string
)

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

portForwardManager.WithPortMappings(portMappings)

if overrideClusterServer != "" {
portForwardManager.WithOverrideClusterServer(overrideClusterServer)
}

environmentResource, err := environment.NewFromWizard(&settings.Profile.Context, resourcePath)
if err != nil {
return err
}

_ = portForwardManager.
WithEnvironmentResource(environmentResource).
WithWorkspace().
PrepareKubernetesClient()

if podName != "" {
Expand Down Expand Up @@ -88,6 +94,7 @@ func init() {

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

mainCmd.AddCommand(command)
}
9 changes: 7 additions & 2 deletions cmd/component/action/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

var errInvalidPodName = errors.New("invalid pod name")

type SSHOptions struct {

Check failure on line 20 in cmd/component/action/ssh.go

View workflow job for this annotation

GitHub Actions / audit

exported type SSHOptions should have comment or be unexported
Namespace string
PodName string
Container string
Expand All @@ -26,18 +26,22 @@

NoTTY bool
NoBanner bool

OverrideClusterServer string
}

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

Check failure on line 33 in cmd/component/action/ssh.go

View workflow job for this annotation

GitHub Actions / audit

exported method SSHOptions.UpdateFlagSet should have comment or be unexported
flags.StringVar(&o.PodName, "pod", o.PodName, "Pod name in namespace/pod-name format")
flags.StringVar(&o.Container, "container", o.Container, "Container name")
flags.StringVar(&o.Shell, "shell", o.Shell, "Shell to use")

flags.BoolVar(&o.NoTTY, "no-tty", o.NoTTY, "Do not allocate a TTY")
flags.BoolVar(&o.NoBanner, "no-banner", o.NoBanner, "Do not show environment banner before ssh")

flags.StringVar(&o.OverrideClusterServer, "override-kubeconfig-cluster-server", o.OverrideClusterServer, "Override kubeconfig cluster server with :port, host:port or scheme://host:port")
}

func (o *SSHOptions) MakeExecOptions(kubeConfig *environment.KubeConfigItem) *k8sExec.Options {

Check failure on line 44 in cmd/component/action/ssh.go

View workflow job for this annotation

GitHub Actions / audit

exported method SSHOptions.MakeExecOptions should have comment or be unexported
motd := "/opt/bunnyshell/motd.txt"

return &k8sExec.Options{
Expand All @@ -63,7 +67,8 @@
settings := config.GetSettings()

sshOptions := SSHOptions{
Shell: "/bin/sh",
Shell: "/bin/sh",
OverrideClusterServer: "",
}

command := &cobra.Command{
Expand All @@ -78,7 +83,7 @@
return err
}

kubeConfigOptions := environment.NewKubeConfigOptions(componentItem.GetEnvironment())
kubeConfigOptions := environment.NewKubeConfigOptions(componentItem.GetEnvironment(), sshOptions.OverrideClusterServer)
kubeConfig, err := environment.KubeConfig(kubeConfigOptions)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions cmd/component_debug/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ type SSHOptions struct {

NoTTY bool
NoBanner bool

OverrideClusterServer string
}

func (o *SSHOptions) UpdateFlagSet(flags *pflag.FlagSet) {
Expand Down
70 changes: 38 additions & 32 deletions cmd/component_debug/up.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package component_debug

import (
"fmt"
"fmt"

"bunnyshell.com/cli/pkg/config"
"bunnyshell.com/cli/pkg/k8s/bridge"
"bunnyshell.com/cli/pkg/lib"
"bunnyshell.com/cli/pkg/debug_component/action"
upAction "bunnyshell.com/cli/pkg/debug_component/action/up"
"bunnyshell.com/cli/pkg/k8s/bridge"
"bunnyshell.com/cli/pkg/lib"
"github.com/spf13/cobra"
)

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

sshOptions := SSHOptions{
Shell: "/bin/sh",
}
Shell: "/bin/sh",
OverrideClusterServer: "",
}

resourceLoader := bridge.NewResourceLoader()
upOptions := upAction.NewOptions(resourceLoader)
Expand Down Expand Up @@ -53,14 +54,15 @@ func init() {
return err
}

selectedContainerName, err := upAction.GetSelectedContainerName()
if err != nil {
return err
}
selectedContainerName, err := upAction.GetSelectedContainerName()
if err != nil {
return err
}

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

return upAction.Close()
},
Expand All @@ -81,31 +83,35 @@ func init() {
}

func startSSH(componentId string, containerName string, sshOptions SSHOptions, cmd *cobra.Command, args []string) error {
proxyArgs := []string{
"components", "ssh",
"--id", componentId,
}
proxyArgs := []string{
"components", "ssh",
"--id", componentId,
}

proxyArgs = append(proxyArgs, "--container", containerName)
proxyArgs = append(proxyArgs, "--container", containerName)

if sshOptions.Shell != "" {
proxyArgs = append(proxyArgs, "--shell", sshOptions.Shell)
}

if sshOptions.Shell != "" {
proxyArgs = append(proxyArgs, "--shell", sshOptions.Shell)
}
if sshOptions.NoBanner {
proxyArgs = append(proxyArgs, "--no-banner")
}

if sshOptions.NoBanner {
proxyArgs = append(proxyArgs, "--no-banner")
}
if sshOptions.NoTTY {
proxyArgs = append(proxyArgs, "--no-tty")
}

if sshOptions.NoTTY {
proxyArgs = append(proxyArgs, "--no-tty")
}
if sshOptions.OverrideClusterServer != "" {
proxyArgs = append(proxyArgs, "--override-kubeconfig-cluster-server", sshOptions.OverrideClusterServer)
}

root := cmd.Root()
root.SetArgs(append(proxyArgs, args...))
root := cmd.Root()
root.SetArgs(append(proxyArgs, args...))

if err := root.Execute(); err != nil {
return err
}
if err := root.Execute(); err != nil {
return err
}

return nil
return nil
}
8 changes: 8 additions & 0 deletions cmd/template/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ func getSource(validateSource ValidateSource, validateOptions template.ValidateO
source.SetValidateComponents(true)
}

if !validateOptions.AllowExtraFields {
source.SetValidateAllowExtraFields(false)
}

action := sdk.ValidateSourceGitAsTemplateValidateActionSource(source)

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

if !validateOptions.AllowExtraFields {
source.SetValidateAllowExtraFields(false)
}

action := sdk.ValidateSourceStringAsTemplateValidateActionSource(source)

return &action, nil
Expand Down
7 changes: 5 additions & 2 deletions cmd/utils/port_forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ func init() {
settings := config.GetSettings()

var (
resourcePath string
podName string
resourcePath string
podName string
overrideClusterServer string
)

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

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

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

mainCmd.AddCommand(command)
}
4 changes: 4 additions & 0 deletions cmd/utils/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func init() {
proxyArgs = append(proxyArgs, "--no-tty")
}

if sshOptions.OverrideClusterServer != "" {
proxyArgs = append(proxyArgs, "--override-kubeconfig-cluster-server", sshOptions.OverrideClusterServer)
}

root := cmd.Root()
root.SetArgs(append(proxyArgs, args...))

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ toolchain go1.23.2
replace github.com/imdario/mergo => github.com/imdario/mergo v0.3.16

require (
bunnyshell.com/dev v0.7.1
bunnyshell.com/sdk v0.20.1
bunnyshell.com/dev v0.7.2
bunnyshell.com/sdk v0.20.3
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/MakeNowJust/heredoc v1.0.0
github.com/avast/retry-go/v4 v4.6.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bunnyshell.com/dev v0.7.1 h1:mNLF0h2bbrTi9LNr2e2zFUC2fGg8TUh/9SM5rTXkzDI=
bunnyshell.com/dev v0.7.1/go.mod h1:+Xk46UXX9AW0nHrFMdO/IwpUPfALrck1/qI+LIXsDmE=
bunnyshell.com/sdk v0.20.1 h1:YxmYrW8UXGNNtLe+l6pXFKyndgwyEyQtdX0f5rHV1fE=
bunnyshell.com/sdk v0.20.1/go.mod h1:RfgfUzZ4WHZGCkToUfu2/hoQS6XsQc8IdPTVAlpS138=
bunnyshell.com/dev v0.7.2 h1:fa0ZvnIAXLVJINCJqo7uenjHmjPrlHmY18Zc8ypo/6E=
bunnyshell.com/dev v0.7.2/go.mod h1:+Xk46UXX9AW0nHrFMdO/IwpUPfALrck1/qI+LIXsDmE=
bunnyshell.com/sdk v0.20.3 h1:Kd2s/fhkMrn6Jqp9UmnXfNu12Oiwg+hgNSNBOIBYPH8=
bunnyshell.com/sdk v0.20.3/go.mod h1:RfgfUzZ4WHZGCkToUfu2/hoQS6XsQc8IdPTVAlpS138=
github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
Expand Down
Loading
Loading