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

Specify provider version for invokes #982

Merged
merged 4 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## HEAD (Unreleased)

### Bug fixes

- Specify provider version for invokes. (https://github.com/pulumi/pulumi-kubernetes/pull/982).

## 1.5.0 (February 4, 2020)

### Improvements
Expand Down
17 changes: 14 additions & 3 deletions pkg/gen/nodejs-templates/helm/v2/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import * as pulumi from "@pulumi/pulumi";
import { execSync } from "child_process";
import * as fs from "fs";
import * as jsyaml from "js-yaml";
import * as nodepath from "path";
import * as shell from "shell-quote";
import * as tmp from "tmp";
import * as path from "../../path";
import { getVersion } from "../../version";
import * as yaml from "../../yaml/index";

interface BaseChartOpts {
Expand Down Expand Up @@ -218,7 +218,7 @@ export class Chart extends yaml.CollectionComponentResource {
},
).toString();
return this.parseTemplate(
yamlStream, cfg.transformations, cfg.resourcePrefix, configDeps, cfg.namespace);
yamlStream, cfg.transformations, cfg.resourcePrefix, configDeps, cfg.namespace, opts);
} catch (e) {
// Shed stack trace, only emit the error.
throw new pulumi.RunError(e.toString());
Expand All @@ -236,9 +236,20 @@ export class Chart extends yaml.CollectionComponentResource {
resourcePrefix: string | undefined,
dependsOn: pulumi.Resource[],
defaultNamespace: string | undefined,
opts?: pulumi.ComponentResourceOptions,
): pulumi.Output<{ [key: string]: pulumi.CustomResource }> {
// Rather than using the default provider for the following invoke call, determine the
// provider from the parent if specified, or fallback to using the version specified
// in package.json.
let invokeOpts: pulumi.InvokeOptions = {async: true};
if (opts?.parent) {
invokeOpts = {...invokeOpts, parent: opts.parent};
} else {
invokeOpts = {...invokeOpts, version: getVersion()};
}

const promise = pulumi.runtime.invoke(
"kubernetes:yaml:decode", {text, defaultNamespace}, {async: true});
"kubernetes:yaml:decode", {text, defaultNamespace}, invokeOpts);
return pulumi.output(promise).apply<{[key: string]: pulumi.CustomResource}>(p => yaml.parse(
{
resourcePrefix: resourcePrefix,
Expand Down
21 changes: 16 additions & 5 deletions pkg/gen/nodejs-templates/yaml.ts.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as fs from "fs";
import * as glob from "glob";
import fetch from "node-fetch";
import * as k8s from "../index";
import { getVersion } from "../version";
import * as outputs from "../types/output";

export interface ConfigGroupOpts {
Expand Down Expand Up @@ -120,9 +121,19 @@ import * as outputs from "../types/output";
resourcePrefix?: string;
}

function yamlLoadAll(text: string): Promise<any[]> {
const promise = pulumi.runtime.invoke("kubernetes:yaml:decode", {text}, {async: true});
return promise.then(p => p.result);
function yamlLoadAll(text: string, opts?: pulumi.CustomResourceOptions): Promise<any[]> {
// Rather than using the default provider for the following invoke call, determine the
// provider from the parent if specified, or fallback to using the version specified
// in package.json.
let invokeOpts: pulumi.InvokeOptions = {async: true};
if (opts?.parent) {
invokeOpts = {...invokeOpts, parent: opts.parent};
} else {
invokeOpts = {...invokeOpts, version: getVersion()};
}

return pulumi.runtime.invoke("kubernetes:yaml:decode", {text}, invokeOpts)
.then((p => p.result));
}

/** @ignore */ export function parse(
Expand Down Expand Up @@ -172,7 +183,7 @@ import * as outputs from "../types/output";

for (const text of yamlTexts) {
const docResources = parseYamlDocument({
objs: yamlLoadAll(text),
objs: yamlLoadAll(text, opts),
transformations: config.transformations,
resourcePrefix: config.resourcePrefix
},
Expand Down Expand Up @@ -320,7 +331,7 @@ import * as outputs from "../types/output";
this.resources = pulumi.output(text.then(t => {
try {
return parseYamlDocument({
objs: yamlLoadAll(t),
objs: yamlLoadAll(t, opts),
transformations: config && config.transformations || [],
resourcePrefix: config && config.resourcePrefix || undefined
}, {parent: this})
Expand Down
17 changes: 14 additions & 3 deletions sdk/nodejs/helm/v2/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import * as pulumi from "@pulumi/pulumi";
import { execSync } from "child_process";
import * as fs from "fs";
import * as jsyaml from "js-yaml";
import * as nodepath from "path";
import * as shell from "shell-quote";
import * as tmp from "tmp";
import * as path from "../../path";
import { getVersion } from "../../version";
import * as yaml from "../../yaml/index";

interface BaseChartOpts {
Expand Down Expand Up @@ -218,7 +218,7 @@ export class Chart extends yaml.CollectionComponentResource {
},
).toString();
return this.parseTemplate(
yamlStream, cfg.transformations, cfg.resourcePrefix, configDeps, cfg.namespace);
yamlStream, cfg.transformations, cfg.resourcePrefix, configDeps, cfg.namespace, opts);
} catch (e) {
// Shed stack trace, only emit the error.
throw new pulumi.RunError(e.toString());
Expand All @@ -236,9 +236,20 @@ export class Chart extends yaml.CollectionComponentResource {
resourcePrefix: string | undefined,
dependsOn: pulumi.Resource[],
defaultNamespace: string | undefined,
opts?: pulumi.ComponentResourceOptions,
): pulumi.Output<{ [key: string]: pulumi.CustomResource }> {
// Rather than using the default provider for the following invoke call, determine the
// provider from the parent if specified, or fallback to using the version specified
// in package.json.
let invokeOpts: pulumi.InvokeOptions = {async: true};
if (opts?.parent) {
invokeOpts = {...invokeOpts, parent: opts.parent};
} else {
invokeOpts = {...invokeOpts, version: getVersion()};
}

const promise = pulumi.runtime.invoke(
"kubernetes:yaml:decode", {text, defaultNamespace}, {async: true});
"kubernetes:yaml:decode", {text, defaultNamespace}, invokeOpts);
return pulumi.output(promise).apply<{[key: string]: pulumi.CustomResource}>(p => yaml.parse(
{
resourcePrefix: resourcePrefix,
Expand Down
21 changes: 16 additions & 5 deletions sdk/nodejs/yaml/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as fs from "fs";
import * as glob from "glob";
import fetch from "node-fetch";
import * as k8s from "../index";
import { getVersion } from "../version";
import * as outputs from "../types/output";

export interface ConfigGroupOpts {
Expand Down Expand Up @@ -120,9 +121,19 @@ import * as outputs from "../types/output";
resourcePrefix?: string;
}

function yamlLoadAll(text: string): Promise<any[]> {
const promise = pulumi.runtime.invoke("kubernetes:yaml:decode", {text}, {async: true});
return promise.then(p => p.result);
function yamlLoadAll(text: string, opts?: pulumi.CustomResourceOptions): Promise<any[]> {
// Rather than using the default provider for the following invoke call, determine the
// provider from the parent if specified, or fallback to using the version specified
// in package.json.
let invokeOpts: pulumi.InvokeOptions = {async: true};
if (opts?.parent) {
invokeOpts = {...invokeOpts, parent: opts.parent};
} else {
invokeOpts = {...invokeOpts, version: getVersion()};
}

return pulumi.runtime.invoke("kubernetes:yaml:decode", {text}, invokeOpts)
.then((p => p.result));
}

/** @ignore */ export function parse(
Expand Down Expand Up @@ -172,7 +183,7 @@ import * as outputs from "../types/output";

for (const text of yamlTexts) {
const docResources = parseYamlDocument({
objs: yamlLoadAll(text),
objs: yamlLoadAll(text, opts),
transformations: config.transformations,
resourcePrefix: config.resourcePrefix
},
Expand Down Expand Up @@ -2462,7 +2473,7 @@ import * as outputs from "../types/output";
this.resources = pulumi.output(text.then(t => {
try {
return parseYamlDocument({
objs: yamlLoadAll(t),
objs: yamlLoadAll(t, opts),
transformations: config && config.transformations || [],
resourcePrefix: config && config.resourcePrefix || undefined
}, {parent: this})
Expand Down