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

Change invoke call to always use latest version #987

Merged
merged 4 commits into from
Feb 11, 2020
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
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() };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still also need to pass through a parent so that it uses the right provider instance? Or does this invoke not actually care about the provider? Even if it doesn’t now, should we pass the parent through regardless?

I actually don’t know for sure - so maybe input from @pgavlin would be good.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried passing both args, and it was failing the same way (invoke returning an empty object {}). That may be a bug with the engine, but I don't know enough about it to be sure.

I think using the version makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if it doesn’t now, should we pass the parent through regardless?

I think the version makes the most sense here as well. This invoke does not need the particular provider instance (yet, at least).


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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment block seems outdated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, good catch.

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