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
30 changes: 28 additions & 2 deletions cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,34 @@ var shellCmd = &cobra.Command{
return
}

pkg.ExecShell(shellRequest, "/shell/exec")
endpoint := "/shell/exec"
if ephemeral {
if ephemeralMode != "clone" && ephemeralMode != "debug" {
utils.PrintlnError(errors.New("--mode must be 'clone' or 'debug'"))
return
}
if ephemeralMode == "debug" && (cpuOverride != "" || memoryOverride != "") {
utils.PrintlnInfo("--cpu/--memory only apply to --mode clone; ignoring them in debug mode.")
}
shellRequest.EphemeralMode = ephemeralMode
shellRequest.CpuOverride = cpuOverride
shellRequest.MemoryOverride = memoryOverride
endpoint = "/shell/ephemeral"
} else if cmd.Flags().Changed("mode") {
utils.PrintlnInfo("--mode has no effect without --ephemeral; ignoring it.")
}
pkg.ExecShell(shellRequest, endpoint)
},
}

var (
command []string
podName string
podContainerName string
ephemeral bool
ephemeralMode string
cpuOverride string
memoryOverride string
)

func shellRequestWithContextFlags() (*pkg.ShellRequest, error) {
Expand Down Expand Up @@ -348,10 +368,16 @@ func init() {
shellCmd.Flags().StringVarP(&serviceName, "service", "", "", "Service Name")
shellCmd.Flags().StringVarP(&podName, "pod", "p", "", "pod name where to exec into")
shellCmd.Flags().StringVar(&podContainerName, "container", "", "container name inside the pod")
shellCmd.Flags().BoolVar(&ephemeral, "ephemeral", false, "spawn an ephemeral shell instead of connecting to an existing pod")
shellCmd.Flags().StringVar(&ephemeralMode, "mode", "clone", "ephemeral mode: 'clone' (new isolated pod, Heroku-style) or 'debug' (ephemeral container injected into existing pod, kubectl-debug style)")
shellCmd.Flags().StringVar(&cpuOverride, "cpu", "", "override CPU request+limit for the ephemeral pod (e.g. '500m', '2')")
shellCmd.Flags().StringVar(&memoryOverride, "memory", "", "override memory request+limit for the ephemeral pod (e.g. '512Mi', '2Gi')")
shellCmd.Example = "qovery shell\n" +
"qovery shell <qovery_console_service_url>\n" +
"qovery shell --organization <organization_name> --project <project_name> --environment <environment_name> --service <service_name>\n" +
"qovery shell --organization <organization_name> --project <project_name> --environment <environment_name> --service <service_name> --pod <pod_name> --container <container_name> --command <command>"
"qovery shell --ephemeral --mode clone --organization <organization_name> --project <project_name> --environment <environment_name> --service <service_name>\n" +
"qovery shell --ephemeral --mode clone --memory 2Gi --organization <organization_name> --project <project_name> --environment <environment_name> --service <service_name>\n" +
"qovery shell --ephemeral --mode debug --organization <organization_name> --project <project_name> --environment <environment_name> --service <service_name>"

rootCmd.AddCommand(shellCmd)
}
3 changes: 3 additions & 0 deletions pkg/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type ShellRequest struct {
Command []string `url:"command"`
TtyWidth uint16 `url:"tty_width"`
TtyHeight uint16 `url:"tty_height"`
EphemeralMode string `url:"mode,omitempty"`
CpuOverride string `url:"cpu_override,omitempty"`
MemoryOverride string `url:"memory_override,omitempty"`
}

func (s *ShellRequest) SetTtySize(width uint16, height uint16) {
Expand Down
Loading