tilt-dev / tilt-dev/tilt

Proposal: exit_settings builtin and --on-exit CLI option for customizing exit behavior

Open
#5,765 4 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Go
Stars
10.1k
Forks
413
Avg merge
1d 10h
Merged PRs (30d)
6

Description

Describe the Feature You Want

We have a number of requests (#2427, #3059, #4294, #5210, #3831) related to being able to control what happens when tilt up or tilt ci exits. A brief summary:

  1. Enable tearing down of resources on exit (#2427, #5210). Either:
  • the equivalent of tilt down, where the Tiltfile is re-executed (so that if config.tilt_subcommand == 'down': statements could run), or
  • clean up the resources without re-executing the Tiltfile -- use the manifests computed from the last Tiltfile result to clean up or disable all resources
  1. Provide multiple ways of specifying the behavior: CLI option(s), Tiltfile builtins, user config file
  2. Provide custom behavior on exit rather than using tilt down and if config.tilt_subcommand == 'down': statements (#3831, #3059)
  3. There are a couple other CLI flags and features related to behavior on exit that have no Tiltfile equivalent that could be exposed: tilt down --delete-namespaces, tilt up/ci --output-snapshot-on-exit
Proposal

This issue proposes to address the above issues and requests with a new Tiltfile builtin exit_settings() and CLI option tilt up/ci --on-exit.

def exit_settings(
  down: bool = False,
  disable: bool = False,
  delete_namespaces: bool = False,
  callback: Function = None,
  snapshot: Union[bool,str] = False,
)
   """Customize behavior of `tilt up` or `tilt ci` when it exits (e.g., due to interrupt or term signal).
   
   Default behavior is to do nothing, leaving any existing k8s or docker-compose resources running.

   Args:
     down: If true, execute the equivalent of `tilt down` at exit. The `Tiltfile` will be re-executed so that any `if config.tilt_subcommand == 'down':` conditional statements can be run. Mutually exclusive with `disable`: If both `down` and `disable` are true, `down` wins.
     disable: If true, disable all resources at exit. The effect is similar to `down` except that the `Tiltfile` is not re-executed.
     delete_namespaces: If true and one of `down` or `disable` is specified, delete any k8s namespaces that were created.
     callback: a Starlark function to be executed at exit. Can be used to run custom logic and `local` commands. If `down` or `disable` are also specified, the callback function will be executed before resources are torn down.
     snapshot: If true, Tilt will output a snapshot file named `tilt-snapshot-XXXXXX.json` at exit. If a string, represents a snapshot filename to save. A literal `%s` can be used in the pathname and will be replaced with a value that ensures the filename will be unique.
   """
CLI option --on-exit

A common flag --on-exit will be added to tilt up and tilt ci that allows specifying down, disable, delete_namespaces, or snapshot options.

      --on-exit strings  Values: down, disable, delete_namespace, snapshot. Customize Tilt behavior on exit. See `exit_settings` Tiltfile builtin.

In addition to the values stated, --on-exit will allow a string of the form snapshot=snapshot-%s.json to customize the snapshot filename. Equivalent to --output-snapshot-on-exit string option.

Current Behavior

Tilt does not allow much in the way of customizing what happens when tilt up or tilt ci exits.

Why Do You Want This?

Address multiple issues and user requests related to on-exit behavior.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the tilt up and tilt ci command entry points, then trace the existing tilt down and --output-snapshot-on-exit behavior. Done means supporting the proposed exit_settings() builtin and --on-exit option, including the listed teardown, callback, namespace-deletion, and snapshot behaviors.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker-compose, go, kubernetes
Domain
cli, devops
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.