Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component option propagation (NodeJS SDK) #2713

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Unreleased
- Fix option propagation in component resources (NodeJS SDK) (https://github.com/pulumi/pulumi-kubernetes/pull/2713)
- Fix option propagation in component resources (Go SDK) (https://github.com/pulumi/pulumi-kubernetes/pull/2709)

## 4.6.1 (December 14, 2023)
Expand Down
14 changes: 4 additions & 10 deletions provider/pkg/gen/nodejs-templates/helm/v3/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class Chart extends yaml.CollectionComponentResource {
if (config.resourcePrefix !== undefined) {
releaseName = `${config.resourcePrefix}-${releaseName}`
}
const aliasOpts: pulumi.ComponentResourceOptions = {...opts, aliases: [{type: "kubernetes:helm.sh/v2:Chart"}]}
const aliasOpts: pulumi.ComponentResourceOptions = {...opts, aliases: [{type: "kubernetes:helm.sh/v2:Chart"}, ...(opts?.aliases ?? [])]}
super(Chart.__pulumiType, releaseName, config, aliasOpts);

const allConfig = pulumi.output(config);
Expand Down Expand Up @@ -242,14 +242,8 @@ export class Chart extends yaml.CollectionComponentResource {
transformations.push(yaml.skipAwait);
}

// Rather than using the default provider for the following invoke call, use the version specified
// in package.json.
let invokeOpts: pulumi.InvokeOptions = {
async: true,
version: opts?.version ?? getVersion(),
provider: opts?.provider,
parent: opts?.parent
};
const childOpts = yaml.getChildOpts(this, opts);
const invokeOpts = yaml.getInvokeOpts(childOpts);

const promise = pulumi.runtime.invoke("kubernetes:helm:template", {jsonOpts}, invokeOpts);
return pulumi.output(promise).apply<{ [key: string]: pulumi.CustomResource }>(p => yaml.parse(
Expand All @@ -258,7 +252,7 @@ export class Chart extends yaml.CollectionComponentResource {
objs: p.result,
transformations,
},
{parent: this}
childOpts
));
}
}
Expand Down
11 changes: 5 additions & 6 deletions provider/pkg/gen/nodejs-templates/kustomize/kustomize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,10 @@ export class Directory extends yaml.CollectionComponentResource {
}
super("kubernetes:kustomize:Directory", name, config, opts);

const directory = config.directory

// Rather than using the default provider for the following invoke call, use the version specified
// in package.json.
let invokeOpts: pulumi.InvokeOptions = { async: true, version: getVersion(), provider: opts?.provider };
const directory = config.directory;

const childOpts = yaml.getChildOpts(this, opts);
const invokeOpts = yaml.getInvokeOpts(childOpts);

const promise = pulumi.runtime.invoke("kubernetes:kustomize:directory", {directory}, invokeOpts);
this.resources = pulumi.output(promise).apply<{[key: string]: pulumi.CustomResource}>(p => yaml.parse(
Expand All @@ -107,7 +106,7 @@ export class Directory extends yaml.CollectionComponentResource {
objs: p.result,
transformations: config.transformations || [],
},
{ parent: this, dependsOn: opts?.dependsOn }
childOpts
));
}
}
Expand Down
31 changes: 25 additions & 6 deletions provider/pkg/gen/nodejs-templates/yaml/yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ export class ConfigGroup extends CollectionComponentResource {
*/
constructor(name: string, config: ConfigGroupOpts, opts?: pulumi.ComponentResourceOptions) {
super("kubernetes:yaml:ConfigGroup", name, config, opts);
this.resources = parse(config, {...opts, parent: this});
const childOpts = getChildOpts(this, opts);
this.resources = parse(config, childOpts);
}
}

Expand Down Expand Up @@ -291,13 +292,14 @@ export class ConfigFile extends CollectionComponentResource {
transformations.push(skipAwait);
}

this.resources = pulumi.output(text.then(t => {
const childOpts = getChildOpts(this, opts);
this.resources = pulumi.output(text.then(t => {
try {
const parsed = parseYamlDocument({
objs: yamlLoadAll(t, opts),
objs: yamlLoadAll(t, childOpts),
transformations,
resourcePrefix: config && config.resourcePrefix || undefined
}, {...opts, parent: this});
}, childOpts);
// If the provider is not fully initialized, the engine skips invoking on the provider and returns an
// empty result. This may change based on how https://github.com/pulumi/pulumi/issues/10209 is addressed.
parsed.apply(p => {
Expand Down Expand Up @@ -383,9 +385,26 @@ export interface ConfigOpts {
resourcePrefix?: string;
}

/** @ignore */ function yamlLoadAll(text: string, opts?: pulumi.ComponentResourceOptions): Promise<any[]> {
let invokeOpts: pulumi.InvokeOptions = { async: true, version: getVersion(), provider: opts?.provider };
/** @ignore */ export function getChildOpts(parent: pulumi.Resource, opts?: pulumi.ComponentResourceOptions): pulumi.CustomResourceOptions {
return {
parent: parent,
...opts?.version && {version: opts.version},
EronWright marked this conversation as resolved.
Show resolved Hide resolved
...opts?.pluginDownloadURL && {pluginDownloadURL: opts.pluginDownloadURL}
};
}

/** @ignore */ export function getInvokeOpts(opts?: pulumi.CustomResourceOptions): pulumi.InvokeOptions {
return {
parent: opts?.parent,
provider: opts?.provider,
version: opts?.version ?? getVersion(),
pluginDownloadURL: opts?.pluginDownloadURL,
async: true
};
}

/** @ignore */ function yamlLoadAll(text: string, opts?: pulumi.CustomResourceOptions): Promise<any[]> {
const invokeOpts = getInvokeOpts(opts);
return pulumi.runtime.invoke("kubernetes:yaml:decode", {text}, invokeOpts)
.then(p => p.result);
}
Expand Down
14 changes: 4 additions & 10 deletions sdk/nodejs/helm/v3/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class Chart extends yaml.CollectionComponentResource {
if (config.resourcePrefix !== undefined) {
releaseName = `${config.resourcePrefix}-${releaseName}`
}
const aliasOpts: pulumi.ComponentResourceOptions = {...opts, aliases: [{type: "kubernetes:helm.sh/v2:Chart"}]}
const aliasOpts: pulumi.ComponentResourceOptions = {...opts, aliases: [{type: "kubernetes:helm.sh/v2:Chart"}, ...(opts?.aliases ?? [])]}
super(Chart.__pulumiType, releaseName, config, aliasOpts);

const allConfig = pulumi.output(config);
Expand Down Expand Up @@ -242,14 +242,8 @@ export class Chart extends yaml.CollectionComponentResource {
transformations.push(yaml.skipAwait);
}

// Rather than using the default provider for the following invoke call, use the version specified
// in package.json.
let invokeOpts: pulumi.InvokeOptions = {
async: true,
version: opts?.version ?? getVersion(),
provider: opts?.provider,
parent: opts?.parent
};
const childOpts = yaml.getChildOpts(this, opts);
const invokeOpts = yaml.getInvokeOpts(childOpts);

const promise = pulumi.runtime.invoke("kubernetes:helm:template", {jsonOpts}, invokeOpts);
return pulumi.output(promise).apply<{ [key: string]: pulumi.CustomResource }>(p => yaml.parse(
Expand All @@ -258,7 +252,7 @@ export class Chart extends yaml.CollectionComponentResource {
objs: p.result,
transformations,
},
{parent: this}
childOpts
));
}
}
Expand Down
11 changes: 5 additions & 6 deletions sdk/nodejs/kustomize/kustomize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,10 @@ export class Directory extends yaml.CollectionComponentResource {
}
super("kubernetes:kustomize:Directory", name, config, opts);

const directory = config.directory

// Rather than using the default provider for the following invoke call, use the version specified
// in package.json.
let invokeOpts: pulumi.InvokeOptions = { async: true, version: getVersion(), provider: opts?.provider };
const directory = config.directory;

const childOpts = yaml.getChildOpts(this, opts);
const invokeOpts = yaml.getInvokeOpts(childOpts);

const promise = pulumi.runtime.invoke("kubernetes:kustomize:directory", {directory}, invokeOpts);
this.resources = pulumi.output(promise).apply<{[key: string]: pulumi.CustomResource}>(p => yaml.parse(
Expand All @@ -107,7 +106,7 @@ export class Directory extends yaml.CollectionComponentResource {
objs: p.result,
transformations: config.transformations || [],
},
{ parent: this, dependsOn: opts?.dependsOn }
childOpts
));
}
}
Expand Down
31 changes: 25 additions & 6 deletions sdk/nodejs/yaml/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3037,7 +3037,8 @@ export class ConfigGroup extends CollectionComponentResource {
*/
constructor(name: string, config: ConfigGroupOpts, opts?: pulumi.ComponentResourceOptions) {
super("kubernetes:yaml:ConfigGroup", name, config, opts);
this.resources = parse(config, {...opts, parent: this});
const childOpts = getChildOpts(this, opts);
this.resources = parse(config, childOpts);
}
}

Expand Down Expand Up @@ -3126,13 +3127,14 @@ export class ConfigFile extends CollectionComponentResource {
transformations.push(skipAwait);
}

this.resources = pulumi.output(text.then(t => {
const childOpts = getChildOpts(this, opts);
this.resources = pulumi.output(text.then(t => {
try {
const parsed = parseYamlDocument({
objs: yamlLoadAll(t, opts),
objs: yamlLoadAll(t, childOpts),
transformations,
resourcePrefix: config && config.resourcePrefix || undefined
}, {...opts, parent: this});
}, childOpts);
// If the provider is not fully initialized, the engine skips invoking on the provider and returns an
// empty result. This may change based on how https://github.com/pulumi/pulumi/issues/10209 is addressed.
parsed.apply(p => {
Expand Down Expand Up @@ -3218,9 +3220,26 @@ export interface ConfigOpts {
resourcePrefix?: string;
}

/** @ignore */ function yamlLoadAll(text: string, opts?: pulumi.ComponentResourceOptions): Promise<any[]> {
let invokeOpts: pulumi.InvokeOptions = { async: true, version: getVersion(), provider: opts?.provider };
/** @ignore */ export function getChildOpts(parent: pulumi.Resource, opts?: pulumi.ComponentResourceOptions): pulumi.CustomResourceOptions {
return {
parent: parent,
...opts?.version && {version: opts.version},
...opts?.pluginDownloadURL && {pluginDownloadURL: opts.pluginDownloadURL}
};
}

/** @ignore */ export function getInvokeOpts(opts?: pulumi.CustomResourceOptions): pulumi.InvokeOptions {
return {
parent: opts?.parent,
provider: opts?.provider,
version: opts?.version ?? getVersion(),
pluginDownloadURL: opts?.pluginDownloadURL,
async: true
};
}

/** @ignore */ function yamlLoadAll(text: string, opts?: pulumi.CustomResourceOptions): Promise<any[]> {
const invokeOpts = getInvokeOpts(opts);
return pulumi.runtime.invoke("kubernetes:yaml:decode", {text}, invokeOpts)
.then(p => p.result);
}
Expand Down
Loading
Loading