Skip to content

Commit

Permalink
kubernetesapply: improve cmd timeout handling (#5221)
Browse files Browse the repository at this point in the history
If the process is killed due to context timeout, it'll have a
non-zero exit code (typically 137).

In these instances, we'll let the user know the command took too
long and point them at the Tiltfile API for `update_settings` so
they can increase the timeout value if needed.

Additionally, if stdout is empty on failure (which, given that
the commands are only supposed to write YAML on success to it, it
generally will be), it won't be output, so you don't get a blank
`stdout:` in the logs.
  • Loading branch information
milas committed Nov 29, 2021
1 parent 7ec0bc0 commit f99cc73
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions internal/controllers/core/kubernetesapply/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,18 @@ func (r *Reconciler) runCmdDeploy(ctx context.Context, spec v1alpha1.KubernetesA
exitCode, err := r.execer.Run(ctx, toModelCmd(*spec.ApplyCmd), runIO)
if err != nil {
return nil, fmt.Errorf("apply command failed: %v", err)
} else if exitCode != 0 {
return nil, fmt.Errorf("apply command exited with status %d\nstdout:\n%s\n", exitCode, overflowEllipsis(stdoutBuf.String()))
}

if exitCode != 0 {
var stdoutLog string
if stdoutBuf.Len() != 0 {
stdoutLog = fmt.Sprintf("\nstdout:\n%s\n", overflowEllipsis(stdoutBuf.String()))
}
if ctx.Err() != nil {
// process returned a non-zero exit code (generally 137) because it was killed by us
return nil, fmt.Errorf("apply command timed out after %s - see https://docs.tilt.dev/api.html#api.update_settings for how to increase%s", timeout.String(), stdoutLog)
}
return nil, fmt.Errorf("apply command exited with status %d%s", exitCode, stdoutLog)
}

// don't pass the bytes.Buffer directly to the YAML parser or it'll consume it and we can't print it out on failure
Expand Down

0 comments on commit f99cc73

Please sign in to comment.