Proposal: exit_settings builtin and --on-exit CLI option for customizing exit behavior
Nobody has claimed this yet.
- 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:
- Enable tearing down of resources on exit (#2427, #5210). Either:
- the equivalent of
tilt down, where theTiltfileis re-executed (so thatif config.tilt_subcommand == 'down':statements could run), or - clean up the resources without re-executing the
Tiltfile-- use the manifests computed from the lastTiltfileresult to clean up or disable all resources
- Provide multiple ways of specifying the behavior: CLI option(s), Tiltfile builtins, user config file
- Provide custom behavior on exit rather than using
tilt downandif config.tilt_subcommand == 'down':statements (#3831, #3059) - There are a couple other CLI flags and features related to behavior on exit that have no
Tiltfileequivalent 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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