Skip to content

Commit

Permalink
Change invoke call to always use latest version (#987)
Browse files Browse the repository at this point in the history
  • Loading branch information
lblackstone committed Feb 11, 2020
1 parent 5714a10 commit de362a8
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 81 deletions.
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

- Change invoke call to always use latest version. (https://github.com/pulumi/pulumi-kubernetes/pull/987).

## 1.5.2 (February 10, 2020)

### Improvements
Expand Down
16 changes: 4 additions & 12 deletions pkg/gen/nodejs-templates/helm/v2/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class Chart extends yaml.CollectionComponentResource {
},
).toString();
return this.parseTemplate(
yamlStream, cfg.transformations, cfg.resourcePrefix, configDeps, cfg.namespace, opts);
yamlStream, cfg.transformations, cfg.resourcePrefix, configDeps, cfg.namespace);
} catch (e) {
// Shed stack trace, only emit the error.
throw new pulumi.RunError(e.toString());
Expand All @@ -236,20 +236,12 @@ 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
// Rather than using the default provider for the following invoke call, use 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()};
}
let invokeOpts: pulumi.InvokeOptions = { async: true, version: getVersion() };

const promise = pulumi.runtime.invoke(
"kubernetes:yaml:decode", {text, defaultNamespace}, invokeOpts);
const promise = pulumi.runtime.invoke("kubernetes:yaml:decode", {text, defaultNamespace}, invokeOpts);
return pulumi.output(promise).apply<{[key: string]: pulumi.CustomResource}>(p => yaml.parse(
{
resourcePrefix: resourcePrefix,
Expand Down
16 changes: 5 additions & 11 deletions pkg/gen/nodejs-templates/yaml.ts.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,10 @@ import * as outputs from "../types/output";
resourcePrefix?: string;
}

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
function yamlLoadAll(text: string): Promise<any[]> {
// Rather than using the default provider for the following invoke call, use 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()};
}
let invokeOpts: pulumi.InvokeOptions = { async: true, version: getVersion() };

return pulumi.runtime.invoke("kubernetes:yaml:decode", {text}, invokeOpts)
.then((p => p.result));
Expand Down Expand Up @@ -183,7 +177,7 @@ import * as outputs from "../types/output";

for (const text of yamlTexts) {
const docResources = parseYamlDocument({
objs: yamlLoadAll(text, opts),
objs: yamlLoadAll(text),
transformations: config.transformations,
resourcePrefix: config.resourcePrefix
},
Expand Down Expand Up @@ -331,7 +325,7 @@ import * as outputs from "../types/output";
this.resources = pulumi.output(text.then(t => {
try {
return parseYamlDocument({
objs: yamlLoadAll(t, opts),
objs: yamlLoadAll(t),
transformations: config && config.transformations || [],
resourcePrefix: config && config.resourcePrefix || undefined
}, {parent: this})
Expand Down
9 changes: 2 additions & 7 deletions pkg/gen/python-templates/helm/v2/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,9 @@ def _parse_chart(all_config: Tuple[str, Union[ChartOpts, LocalChartOpts], pulumi

chart_resources = pulumi.Output.all(cmd, data).apply(_run_helm_cmd)

# 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
# Rather than using the default provider for the following invoke call, use the version specified
# in package.json.
invoke_opts = pulumi.InvokeOptions()
if opts.parent is not None:
invoke_opts.parent = opts.parent
else:
invoke_opts.version = get_version()
invoke_opts = pulumi.InvokeOptions(version=get_version())

objects = chart_resources.apply(
lambda text: pulumi.runtime.invoke('kubernetes:yaml:decode', {
Expand Down
11 changes: 3 additions & 8 deletions pkg/gen/python-templates/yaml.py.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ from typing import Callable, Dict, List, Optional
import pulumi.runtime
import requests
from pulumi_kubernetes.apiextensions import CustomResource

from . import tables
from .version import get_version


class ConfigFile(pulumi.ComponentResource):
Expand Down Expand Up @@ -57,14 +57,9 @@ class ConfigFile(pulumi.ComponentResource):

opts = pulumi.ResourceOptions.merge(opts, pulumi.ResourceOptions(parent=self))

# 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
# Rather than using the default provider for the following invoke call, use the version specified
# in package.json.
invoke_opts = pulumi.InvokeOptions()
if opts.parent is not None:
invoke_opts.parent = opts.parent
else:
invoke_opts.version = get_version()
invoke_opts = pulumi.InvokeOptions(version=get_version())

__ret__ = pulumi.runtime.invoke('kubernetes:yaml:decode', {'text': text}, invoke_opts).value['result']

Expand Down
16 changes: 4 additions & 12 deletions sdk/nodejs/helm/v2/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class Chart extends yaml.CollectionComponentResource {
},
).toString();
return this.parseTemplate(
yamlStream, cfg.transformations, cfg.resourcePrefix, configDeps, cfg.namespace, opts);
yamlStream, cfg.transformations, cfg.resourcePrefix, configDeps, cfg.namespace);
} catch (e) {
// Shed stack trace, only emit the error.
throw new pulumi.RunError(e.toString());
Expand All @@ -236,20 +236,12 @@ 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
// Rather than using the default provider for the following invoke call, use 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()};
}
let invokeOpts: pulumi.InvokeOptions = { async: true, version: getVersion() };

const promise = pulumi.runtime.invoke(
"kubernetes:yaml:decode", {text, defaultNamespace}, invokeOpts);
const promise = pulumi.runtime.invoke("kubernetes:yaml:decode", {text, defaultNamespace}, invokeOpts);
return pulumi.output(promise).apply<{[key: string]: pulumi.CustomResource}>(p => yaml.parse(
{
resourcePrefix: resourcePrefix,
Expand Down
16 changes: 5 additions & 11 deletions sdk/nodejs/yaml/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,10 @@ import * as outputs from "../types/output";
resourcePrefix?: string;
}

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
function yamlLoadAll(text: string): Promise<any[]> {
// Rather than using the default provider for the following invoke call, use 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()};
}
let invokeOpts: pulumi.InvokeOptions = { async: true, version: getVersion() };

return pulumi.runtime.invoke("kubernetes:yaml:decode", {text}, invokeOpts)
.then((p => p.result));
Expand Down Expand Up @@ -183,7 +177,7 @@ import * as outputs from "../types/output";

for (const text of yamlTexts) {
const docResources = parseYamlDocument({
objs: yamlLoadAll(text, opts),
objs: yamlLoadAll(text),
transformations: config.transformations,
resourcePrefix: config.resourcePrefix
},
Expand Down Expand Up @@ -2473,7 +2467,7 @@ import * as outputs from "../types/output";
this.resources = pulumi.output(text.then(t => {
try {
return parseYamlDocument({
objs: yamlLoadAll(t, opts),
objs: yamlLoadAll(t),
transformations: config && config.transformations || [],
resourcePrefix: config && config.resourcePrefix || undefined
}, {parent: this})
Expand Down
9 changes: 2 additions & 7 deletions sdk/python/pulumi_kubernetes/helm/v2/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,9 @@ def _parse_chart(all_config: Tuple[str, Union[ChartOpts, LocalChartOpts], pulumi

chart_resources = pulumi.Output.all(cmd, data).apply(_run_helm_cmd)

# 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
# Rather than using the default provider for the following invoke call, use the version specified
# in package.json.
invoke_opts = pulumi.InvokeOptions()
if opts.parent is not None:
invoke_opts.parent = opts.parent
else:
invoke_opts.version = get_version()
invoke_opts = pulumi.InvokeOptions(version=get_version())

objects = chart_resources.apply(
lambda text: pulumi.runtime.invoke('kubernetes:yaml:decode', {
Expand Down
11 changes: 3 additions & 8 deletions sdk/python/pulumi_kubernetes/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import pulumi.runtime
import requests
from pulumi_kubernetes.apiextensions import CustomResource

from . import tables
from .version import get_version


class ConfigFile(pulumi.ComponentResource):
Expand Down Expand Up @@ -57,14 +57,9 @@ def __init__(self, name, file_id, opts=None, transformations=None, resource_pref

opts = pulumi.ResourceOptions.merge(opts, pulumi.ResourceOptions(parent=self))

# 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
# Rather than using the default provider for the following invoke call, use the version specified
# in package.json.
invoke_opts = pulumi.InvokeOptions()
if opts.parent is not None:
invoke_opts.parent = opts.parent
else:
invoke_opts.version = get_version()
invoke_opts = pulumi.InvokeOptions(version=get_version())

__ret__ = pulumi.runtime.invoke('kubernetes:yaml:decode', {'text': text}, invoke_opts).value['result']

Expand Down
8 changes: 3 additions & 5 deletions tests/examples/python/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestYaml(t *testing.T) {
ExpectRefreshChanges: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stackInfo.Deployment)
assert.Equal(t, 15, len(stackInfo.Deployment.Resources))
assert.Equal(t, 14, len(stackInfo.Deployment.Resources))

sort.Slice(stackInfo.Deployment.Resources, func(i, j int) bool {
ri := stackInfo.Deployment.Resources[i]
Expand Down Expand Up @@ -159,11 +159,9 @@ func TestYaml(t *testing.T) {
// Verify the provider resources.
provRes := stackInfo.Deployment.Resources[12]
assert.True(t, providers.IsProviderType(provRes.URN.Type()))
provRes = stackInfo.Deployment.Resources[13]
assert.True(t, providers.IsProviderType(provRes.URN.Type()))

// Verify root resource.
stackRes := stackInfo.Deployment.Resources[14]
stackRes := stackInfo.Deployment.Resources[13]
assert.Equal(t, resource.RootStackType, stackRes.URN.Type())

// TODO[pulumi/pulumi#2782] Testing of secrets blocked on a bug in Python support for secrets.
Expand Down Expand Up @@ -312,7 +310,7 @@ func TestHelm(t *testing.T) {
ExpectRefreshChanges: true, // PodDisruptionBudget status gets updated by the Deployment.
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stackInfo.Deployment)
assert.Equal(t, 16, len(stackInfo.Deployment.Resources))
assert.Equal(t, 15, len(stackInfo.Deployment.Resources))

sort.Slice(stackInfo.Deployment.Resources, func(i, j int) bool {
ri := stackInfo.Deployment.Resources[i]
Expand Down

0 comments on commit de362a8

Please sign in to comment.