Hi there, I’m trying to understand how `dependsOn`...
# general
f
Hi there, I’m trying to understand how
dependsOn
works and if it’s the solution to my problem. From what I understand here https://www.pulumi.com/docs/intro/concepts/programming-model/#dependson it should properly wait for a previous resource to be available for the one I’m referencing it in. In my usecase I provision postgresql with an helm chart and my migration service needs to wait in order to connect to it. Unfortunately, having inputs from the chart nor having it explicitly define in the
dependsOn
does not make my service wait for all the services in the chart available and of course it fails since the database service is not available yet. How am I supposed to properly define dependencies when pulumi fails to understand a specific case then ?
b
did you add
dependsOn
to the chart or inside the
transformations
f
@busy-umbrella-36067 sorry no, I use
dependsOn
in a following
ComponentResource
of mine which depends on the database helm chart to be fully up&running
b
ah, so your component starts creating even though you have it set to depend on the chart
f
correct
it starts randomly, and does not care at all about the chart status
b
I would look around accessing individual resources of a helm chart
I believe they had some sort of way to do that, instead of referencing the whole chart.
f
The chart is in another
ComponentResource
to be precise. I tried to depends on this “container” and also directly on the chart inside itself, both failed.
b
The other thing I can think of is a
Job
which loops until your DB is reachable.
you could depend on the job and it should be guaranteed to work
f
I think I can do that, but that’s tedious, I had hope pulumi should be “smart” to understand the
ComponentResource
and
Chart
dependencies. I’ll try that
Never tried a
Job
, will have a look, but that’s kind of “dirty” workaround I guess
Thanks for the inputs @busy-umbrella-36067 i’ll try those few shots
b
Agreed, its not ideal (I would call it jank) Thats why I would research on how to access one of the 10+ resources the chart creates instead of the whole chart before I go with the
Job
f
@busy-umbrella-36067 there’s a
chart.getResource()
method, trying right now
👍 1
g
b
Nice, this might also be helpful if you wanna just depend on your component resource https://www.pulumi.com/docs/intro/concepts/programming-model/#registering-component-outputs You could register the resource you get from
chart.getResource()
as an output and that way all you would need to
dependsOn
is your first component
The call to registerOutputs also tells Pulumi that the resource is done registering children and should be considered fully constructed, so—although it's not enforced—the best practice is to call it in all components even if no outputs need to be registered.
f
@busy-umbrella-36067 right ! I forgot about that. I can confirm using
getResource()
works and my component holds until the database services are up. Will try the cleaner way with
registerOutputs()
right away
@busy-umbrella-36067 @gorgeous-egg-16927 while using
getResource()
and directly depending on the resource(s) needed in
dependsOn
works, registering the same resource(s) in
registerOutputs()
and only using the top
ComponentResource
as a dependency unfortunately does not work as expected. I’ll stick to direct references the resources I need to wait for, for now. Thanks for your help !
👍 1
b
what if you use the output as an input
and ditch
dependsOn
altogether
I’m assuming its something like a hostname, so that might not actually work. Never mind
f
not sure that would help and I actually does not really have a direct input from the chart, so that would make things more messy. But that could maybe trigger a dependency in some other cases.
I’ll track the issue and i’ll refactor once it will be solved, for now I can live with this (small) workaround.
thanks again !