tilt icon indicating copy to clipboard operation
tilt copied to clipboard

Declare resource as dependency for ALL other resources (/iterate through available resources?)

Open maiamcc opened this issue 4 years ago • 5 comments

I want to move some slow operations in ClusterAPI's Tiltfile into a local_resource so that they don't happen every time I touch the Tiltfile. These operations need to run before any k8s resources are deployed.

Currently, my new local_resource WILL run before any k8s resources, but that's not a guarantee we make, so not necessarily something I want to explicitly rely on. Maybe we'll eventually want to make this guarantee explicit, but I think even when local_resources are NOT involved, there's a case for being able to declare a universal dependency, i.e. "resource X must build before ALL other resources".

I could theoretically do this with existing Tiltfile primitives IF I knew the names of all available resources ahead of time (and then my implementation would break if a new resource were added). Another way to make "universal dependencies" ergonomic might be something like:

for name in all_k8s_resources():
    if name != "some_resource":
        k8s_resource(name, deps=["some_resource"]

maiamcc avatar Apr 30 '20 19:04 maiamcc

Update here: I thought to write function that would parse yaml and grab the resource name before sending it along to k8s_yaml, but uh, it turns out our logic to name resources is super convoluted and I don't want to replicate that in the tiltfile :(

maiamcc avatar May 05 '20 22:05 maiamcc

This came up in the Slack channel recently from Amit Ben Ami:

I want to run a custom script at the end of all my resources have spun up (I want to send metrics to see how long my services are taking to run). Is there a way I can use resource_deps that will include all services without hardcoding them (hardcoding will make me add to this list each time a new service is added, or maintain a specific schema/structure inside my tiltfiles so I can fetch them)

milas avatar Feb 01 '21 16:02 milas

We have a similar use case I also brought up on slack.

Many of our services spin up Kubernetes Jobs for Migrations, and in order for those names to be unique the jobs are named with truncated SHAs.

This means that each time we spin up Tilt and want to run:

k8s_resource('migration-job-123abc')
k8s_resource('my-api', resource_deps=['migration-job-123abc'])

That 123abc will be different if our tag changes, causing manual Tiltfile updates. Supporting a way for us to iterate over the k8s resources and passing them to resource_deps or supporting a syntax like resource_deps=['migration-job-*'] would be a huge value add in this case!

zackerydev avatar Feb 25 '21 16:02 zackerydev

From another Slack convo today:

Is there a way to influence the order of k8s_resources deployments besides resource_deps? I'd like to ensure some secrets get deployed before everything else (image pull secrets). I could add those secrets to the resource_deps of (almost) everything but I really don't want to do that.

milas avatar Mar 11 '22 13:03 milas

+1 I would also like to see a wild card option in resource deps, or the ability to target a tag and be able to wait for everything in that tag to be green.

maxsargentdev avatar May 25 '23 15:05 maxsargentdev