bumpy-agent-19616
02/02/2022, 11:06 AMNamespace.ts
-----------------
export interface NamespaceArgs {
name: string;
metadata: {
labels: {
[key: string]: string;
};
};
}
export class Namespace extends pulumi.ComponentResource {
constructor(
name: string,
args: NamespaceArgs,
opts?: pulumi.CustomResourceOptions,
) {
super(Constants.COMPONENT_TYPE, name, {}, opts);
new k8s.core.v1.Namespace(
args.name,
{
metadata: args.metadata,
},
{
...opts,
parent: this,
},
);
}
}
Secret.ts
-----------------
export interface SecretArgs {
name: string;
type: string;
data: string;
metadata: MetadataArgs;
}
export class Secret extends pulumi.ComponentResource {
constructor(
name: string,
secretArgs: SecretArgs,
opts?: pulumi.CustomResourceOptions,
) {
super(Constants.COMPONENT_TYPE, name, {}, opts);
const secretOpts = new SecretOpts();
new k8s.core.v1.Secret(
`${secretArgs.metadata.name}-${secretArgs.metadata.namespace}-${Constants.DEPLOYMENT}`,
{
data: secretOpts.setData(secretArgs.type, secretArgs.data),
metadata: secretOpts.setMetadata(secretArgs.metadata),
type: secretOpts.setType(secretArgs.type),
},
{
...opts,
parent: this,
},
);
}
}
IngressNginx.ts
-----------------
export interface IngressNginxArgs {
helmVersion: HelmVersion.V2 | HelmVersion.V3;
chartArgs: ChartArgs;
namespaceArgs: NamespaceArgs;
secretArgs: SecretArgs;
provider: k8s.Provider;
}
export class IngressNginx extends pulumi.ComponentResource {
constructor(
name: string,
ingressNginxArgs: IngressNginxArgs,
opts?: pulumi.CustomResourceOptions,
) {
super(Constants.COMPONENT_TYPE, name, {}, opts);
const defaultResourceOpts: pulumi.ComponentResourceOptions = {
parent: this,
provider: ingressNginxArgs.provider,
};
const namespace = new Namespace(
ingressNginxArgs.namespaceArgs.name,
ingressNginxArgs.namespaceArgs,
{
...defaultResourceOpts,
},
);
const secret = new Secret(
ingressNginxArgs.secretArgs.name,
ingressNginxArgs.secretArgs,
{
...defaultResourceOpts,
dependsOn: [namespace],
},
);
const ingressNginxResourceOpts: pulumi.ComponentResourceOptions = {
...defaultResourceOpts,
dependsOn: [namespace, secret],
};
if (ingressNginxArgs.helmVersion == HelmVersion.V2) {
new k8s.helm.v2.Chart(
name,
new IngressNginxChartOpts(ingressNginxArgs.chartArgs).setChartOpts(),
ingressNginxResourceOpts,
);
} else {
new k8s.helm.v3.Chart(
name,
new IngressNginxChartOpts(ingressNginxArgs.chartArgs).setChartOpts(),
ingressNginxResourceOpts,
);
}
}
}
prehistoric-activity-61023
02/02/2022, 11:19 AMdependsOn
was introduced for dependencies that cannot be implicitly detecteddependsOn
explicitly set, you might have found a bugbumpy-agent-19616
02/02/2022, 1:15 PMpulumi destroy
prehistoric-activity-61023
02/02/2022, 1:17 PMbumpy-agent-19616
02/02/2022, 1:17 PMprehistoric-activity-61023
02/02/2022, 1:18 PMbumpy-agent-19616
02/02/2022, 1:19 PMprehistoric-activity-61023
02/02/2022, 1:19 PMbumpy-agent-19616
02/02/2022, 1:20 PMprehistoric-activity-61023
02/02/2022, 1:20 PMbumpy-agent-19616
02/02/2022, 1:21 PMprehistoric-activity-61023
02/02/2022, 1:21 PMbumpy-agent-19616
02/02/2022, 1:24 PMprehistoric-activity-61023
02/02/2022, 1:25 PMparent
field)
there’s nothing wrong here in my opinion :)bumpy-agent-19616
02/02/2022, 1:26 PMprehistoric-activity-61023
02/02/2022, 1:27 PMbumpy-agent-19616
02/02/2022, 1:28 PMprehistoric-activity-61023
02/02/2022, 1:32 PMdependsOn
explicitly if you use another resource outputs while creating a new one (pulumi will detect that automatically); not sure if that’s applicable to your case, I’d have to check the code once again
WARNING - pseudo code
----
resource_a = gcp.BucketOrWhatever(...)
resource_b = gcp.LoadBalancerToBucket(
=> target=resource_a.name
)
due to the fact you referenced resource_a.name
while creating resource_b
, pulumi knows it must create a resource_a
first. DependsOn
is useful if such dependencies are not visible in code.
2) The fact you marked a resource with dependsOn
does not affect parent-child relationship. If you want to affect the tree structure for visibility, you have to explicitly set parent
field.bored-oyster-3147
02/02/2022, 1:54 PMpulumi preview
shows you the parent/child relationship - which is purely organizational and has no bearing on the ordering of resource provisioning. The parent/child relationship is one:many, and is used to create logical groups of your resources - such as when you create a ComponentResource
and assign all resources beneath it as parent: this,
you are creating a logical group.
This is different from the dependency tree, which is many:one and is determined either implicitly by Outputs
being passed around, or explicitly with the dependsOn
property - if you would like to see what this tree looks like you can use the pulumi stack graph
command.bumpy-agent-19616
02/02/2022, 3:20 PMpulumi preview
doesn't affect the parent-child relationship during pulumi update
and I verified it as well. Thanks a lot @prehistoric-activity-61023 & @bored-oyster-3147 for providing more information and clarity on this.