what exact effects does it have to make a resource...
# general
g
what exact effects does it have to make a resource A be the
parent
vs
dependsOn
of another resource B? I’m currently just arguing whether I should make the k8s namespace of my app the parent or dependsOn of the resources inside the namespace.
i
“Parent” is useful for component resources (subclasses of
pulumi.ComponentResource
) that themselves are made up of resources - it’s not legal for a non-component resource (like a k8s namespace) to be the parent of any other resource.
dependsOn
tells Pulumi that resource A can’t begin a CRUD operation until resource B completes its own CRUD operation, which is basically what you want for k8s namespaces. However, if you use the output property of the name of the namespace as an input property to another resource’s
metadata.namespace
, you shouldn’t need to do
dependsOn
at all - Pulumi should figure out that there’s a dependency on the resource you’re constructing and the k8s namespace
i just wrote an example for k8s, let me find it real quick
not sure how exemplary this is, but
args.namespace
here is a
Namespace
resource that I just crated - I’m passing the name of the namespace to a ConfigMap’s
metadata.namespace
here and Pulumi sets up a dependency between the two automatically
g
I see, makes sense. That being said I tried making a namespace the
parent
of the other resources and it actually worked (like pulumi up created the appropriate resources etc.). Doesn’t that contradict what you said or is this a bug?
i
very possible I’m wrong about that detail - we’ve gone back and forth a couple times on whether or not a custom (non-component) resource can be a
parent
and I’m not sure where we ended up 😆 . @microscopic-florist-22719 would know
Either way, though, I’d recommend against non-component
parents
g
👍
m
Standard resources can be used as parents of other resources, but we do consider that something of an anti-pattern. Or in other words, what Sean said 🙂