diff --git a/cmd/shell.go b/cmd/shell.go index 16037921..d5cbc9a1 100644 --- a/cmd/shell.go +++ b/cmd/shell.go @@ -52,7 +52,23 @@ 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) }, } @@ -60,6 +76,10 @@ var ( command []string podName string podContainerName string + ephemeral bool + ephemeralMode string + cpuOverride string + memoryOverride string ) func shellRequestWithContextFlags() (*pkg.ShellRequest, error) { @@ -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 \n" + "qovery shell --organization --project --environment --service \n" + - "qovery shell --organization --project --environment --service --pod --container --command " + "qovery shell --ephemeral --mode clone --organization --project --environment --service \n" + + "qovery shell --ephemeral --mode clone --memory 2Gi --organization --project --environment --service \n" + + "qovery shell --ephemeral --mode debug --organization --project --environment --service " rootCmd.AddCommand(shellCmd) } diff --git a/pkg/shell.go b/pkg/shell.go index 239938bf..63f3af39 100644 --- a/pkg/shell.go +++ b/pkg/shell.go @@ -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) {