diff --git a/cmd/actions/root.go b/cmd/actions/root.go index 75a21b8..88c79ef 100644 --- a/cmd/actions/root.go +++ b/cmd/actions/root.go @@ -15,7 +15,6 @@ func init() { rootCmd.PersistentFlags().StringVarP(&flagPod, "pod", "p", "", "pod name (default most recent one)") rootCmd.PersistentFlags().StringVarP(&flagContainer, "container", "c", "", "container name (default deployment name)") patchCmd.Flags().StringVarP(&flagImage, "image", "i", "", "image to be used for patching (default deployment image)") - patchCmd.Flags().StringVarP(&flagRepo, "repo", "r", "", "repository to be used for pushing patched image (default none)") patchCmd.Flags().StringArrayVarP(&flagMounts, "mount", "m", []string{}, "host path to be mounted (default none)") patchCmd.Flags().BoolVar(&flagRollback, "rollback", false, "rollback deployment to a previous state") delveCmd.Flags().StringVar(&flagSourcePath, "source", "", ".go file source path (default cwd)") @@ -23,6 +22,7 @@ func init() { delveCmd.Flags().Var(flagListen, "listen", "delve host:port to listen on") delveCmd.Flags().BoolVar(&flagVscode, "vscode", false, "launch a debug configuration in vscode") delveCmd.Flags().BoolVar(&flagJSONLog, "json-log", false, "log as json") + delveCmd.Flags().BoolVar(&flagContinue, "continue", false, "start delve server execution without wiating for client connection") rootCmd.AddCommand(versionCmd, patchCmd, shellCmd, delveCmd) } @@ -33,7 +33,6 @@ var ( flagNamespace string flagPod string flagContainer string - flagRepo string flagImage string flagMounts []string flagSourcePath string @@ -80,7 +79,7 @@ var ( if err != nil { return err } - return grapple.Patch(flagRepo, flagImage, flagTag, flagContainer, mounts) + return grapple.Patch(flagImage, flagTag, flagContainer, mounts) }, } shellCmd = &cobra.Command{ @@ -96,7 +95,7 @@ var ( Short: "start a headless delve debug server for .go input on a patched deployment", Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - return grapple.Delve(flagPod, flagContainer, flagSourcePath, flagArgs.items, flagListen.Host, flagListen.Port, flagVscode) + return grapple.Delve(flagPod, flagContainer, flagSourcePath, flagArgs.items, flagListen.Host, flagListen.Port, flagVscode, flagContinue) }, } ) diff --git a/delve/client.go b/delve/client.go index 999d8b2..c0b3ef4 100644 --- a/delve/client.go +++ b/delve/client.go @@ -37,11 +37,6 @@ func (kdc KubeDelveClient) ValidateState() error { if state.Exited { // Exited indicates whether the debugged process has exited. return fmt.Errorf("delve debugged process has exited") - } else if !state.Running { - // Running is true if the process is running and no other information can be collected. - // theres a case when you are in a breakpoint on a zombie process - // dlv will not handle that gracefully - return fmt.Errorf("delve debugged process is not running (zombie/breakpoint)") } else { // were good return nil diff --git a/delve/server.go b/delve/server.go index 404afb4..2a61118 100644 --- a/delve/server.go +++ b/delve/server.go @@ -32,8 +32,8 @@ func NewKubeDelveServer(l *logrus.Entry, namespace, host string, port int) *Kube } func (kds *KubeDelveServer) StartNoWait(ctx context.Context, pod, container string, - binDest string, binArgs []string) { - cmd := kds.kubeCmd.ExecPod(pod, container, kds.buildCommand(binDest, binArgs)) + binDest string, binArgs []string, doContinue bool) { + cmd := kds.kubeCmd.ExecPod(pod, container, kds.getRunCmd(binDest, binArgs, doContinue)) cmd.PostStart( func(p *os.Process) error { kds.process = p @@ -43,8 +43,8 @@ func (kds *KubeDelveServer) StartNoWait(ctx context.Context, pod, container stri } func (kds *KubeDelveServer) Start(ctx context.Context, pod, container string, - binDest string, binArgs []string) error { - cmd := kds.kubeCmd.ExecPod(pod, container, kds.buildCommand(binDest, binArgs)) + binDest string, binArgs []string, doContinue bool) error { + cmd := kds.kubeCmd.ExecPod(pod, container, kds.getRunCmd(binDest, binArgs, doContinue)) // execute command to run dlv on container out, err := cmd.PostStart( func(p *os.Process) error { @@ -54,11 +54,16 @@ func (kds *KubeDelveServer) Start(ctx context.Context, pod, container string, return errors.WithMessage(err, out) } -func (kds KubeDelveServer) buildCommand(binDest string, binArgs []string) []string { +// doContinue will start the execution without waiting for a client connection +func (kds KubeDelveServer) getRunCmd(binDest string, binArgs []string, doContinue bool) []string { cmd := []string{ - "dlv", "exec", binDest, "--headless", - fmt.Sprintf("--listen=:%v", kds.port), "--accept-multiclient", "--continue", + "dlv", "exec", binDest, "--headless", "--accept-multiclient", + fmt.Sprintf("--listen=:%v", kds.port), } + if doContinue { + cmd = append(cmd, "--continue") + } + // cmd = append(cmd, "--log") if len(binArgs) > 0 { cmd = append(cmd, "--") cmd = append(cmd, binArgs...) diff --git a/exec/cmd.go b/exec/cmd.go index b37aafd..32bcbc9 100644 --- a/exec/cmd.go +++ b/exec/cmd.go @@ -130,7 +130,7 @@ func (c *Cmd) run(cmd *goexec.Cmd) (string, error) { c.stdoutWriters = append(c.stdoutWriters, combinedBuf) c.stderrWriters = append(c.stderrWriters, combinedBuf) if c.l != nil { - c.l.Tracef("executing %q", cmd.String()) + c.l.Tracef("executing %q in %q", cmd.String(), cmd.Dir) c.stdoutWriters = append(c.stdoutWriters, c.l.WriterLevel(logrus.TraceLevel)) c.stderrWriters = append(c.stderrWriters, c.l.WriterLevel(logrus.WarnLevel)) } diff --git a/exec/go.go b/exec/go.go index 13a9f2f..5e6a6ca 100644 --- a/exec/go.go +++ b/exec/go.go @@ -8,6 +8,6 @@ func NewGoCommand() *GoCmd { return &GoCmd{*NewCommand("go")} } -func (c GoCmd) Build(workDir, output string, inputs []string, flags ...string) *Cmd { - return c.Args("build", "-o", output).Cwd(workDir).Args(flags...).Args(inputs...) +func (c GoCmd) Build(output string, inputs []string, flags ...string) *Cmd { + return c.Args("build", "-o", output).Args(flags...).Args(inputs...) } diff --git a/the-hook/deployment-patch.yaml b/the-hook/deployment-patch.yaml index af0f95b..4896b1b 100644 --- a/the-hook/deployment-patch.yaml +++ b/the-hook/deployment-patch.yaml @@ -10,8 +10,9 @@ spec: image: {{ .Image }} command: args: - livenessProbe: - readinessProbe: + livenessProbe: ~ + readinessProbe: ~ + startupProbe: ~ volumeMounts: - name: patch-configmap mountPath: {{ .ConfigMapMount }}