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

Fix hang on large YAML files #974

Merged
merged 2 commits into from
Feb 3, 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
Expand Up @@ -6,6 +6,10 @@
- Automatically set Secret inputs as pulumi.secret. (https://github.com/pulumi/pulumi-kubernetes/pull/961).
- Create helm.v3 alias. (https://github.com/pulumi/pulumi-kubernetes/pull/970).

### Bug fixes

- Fix hang on large YAML files. (https://github.com/pulumi/pulumi-kubernetes/pull/974).

## 1.4.5 (January 22, 2020)

### Bug fixes
Expand Down
13 changes: 6 additions & 7 deletions pkg/gen/nodejs-templates/yaml.ts.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import * as outputs from "../types/output";

export interface ConfigOpts {
/** JavaScript objects representing Kubernetes resources. */
objs: pulumi.Input<pulumi.Input<any>[]>;
pgavlin marked this conversation as resolved.
Show resolved Hide resolved
objs: Promise<any[]>;

/**
* A set of transformations to apply to Kubernetes resource definitions before registering
Expand Down Expand Up @@ -182,7 +182,7 @@ import * as outputs from "../types/output";
}

if (config.objs !== undefined) {
const objs = Array.isArray(config.objs) ? config.objs: [config.objs];
const objs: Promise<any[]> = Array.isArray(config.objs) ? Promise.resolve(config.objs) : Promise.resolve([config.objs]);
const docResources = parseYamlDocument({objs, transformations: config.transformations}, opts);
resources = pulumi.all([resources, docResources]).apply(([rs, drs]) => ({...rs, ...drs}));
}
Expand Down Expand Up @@ -335,14 +335,13 @@ import * as outputs from "../types/output";
config: ConfigOpts,
opts?: pulumi.CustomResourceOptions,
): pulumi.Output<{[key: string]: pulumi.CustomResource}> {
return pulumi.output(config.objs).apply(configObjs => {
const objs = configObjs
const objs = config.objs.then(configObjs => {
return configObjs
.map(obj => parseYamlObject(obj, config.transformations, config.resourcePrefix, opts))
.reduce((array, objs) => (array.concat(...objs)), []);

return pulumi.output(objs).apply(objs => objs
.reduce((map: {[key: string]: pulumi.CustomResource}, val) => (map[val.name] = val.resource, map), {}))
});
return pulumi.output(objs).apply(objs => objs
.reduce((map: {[key: string]: pulumi.CustomResource}, val) => (map[val.name] = val.resource, map), {}));
}

/** @ignore */ function parseYamlObject(
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/invoke_decode_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func decodeYaml(text, defaultNamespace string, clientSet *clients.DynamicClientS
resources = append(resources, resource)
}

result := make([]interface{}, len(resources))
result := make([]interface{}, 0, len(resources))
for _, resource := range resources {
result = append(result, resource.Object)
}
Expand Down
13 changes: 6 additions & 7 deletions sdk/nodejs/yaml/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import * as outputs from "../types/output";

export interface ConfigOpts {
/** JavaScript objects representing Kubernetes resources. */
objs: pulumi.Input<pulumi.Input<any>[]>;
objs: Promise<any[]>;

/**
* A set of transformations to apply to Kubernetes resource definitions before registering
Expand Down Expand Up @@ -182,7 +182,7 @@ import * as outputs from "../types/output";
}

if (config.objs !== undefined) {
const objs = Array.isArray(config.objs) ? config.objs: [config.objs];
const objs: Promise<any[]> = Array.isArray(config.objs) ? Promise.resolve(config.objs) : Promise.resolve([config.objs]);
const docResources = parseYamlDocument({objs, transformations: config.transformations}, opts);
resources = pulumi.all([resources, docResources]).apply(([rs, drs]) => ({...rs, ...drs}));
}
Expand Down Expand Up @@ -2477,14 +2477,13 @@ import * as outputs from "../types/output";
config: ConfigOpts,
opts?: pulumi.CustomResourceOptions,
): pulumi.Output<{[key: string]: pulumi.CustomResource}> {
return pulumi.output(config.objs).apply(configObjs => {
const objs = configObjs
const objs = config.objs.then(configObjs => {
return configObjs
.map(obj => parseYamlObject(obj, config.transformations, config.resourcePrefix, opts))
.reduce((array, objs) => (array.concat(...objs)), []);

return pulumi.output(objs).apply(objs => objs
.reduce((map: {[key: string]: pulumi.CustomResource}, val) => (map[val.name] = val.resource, map), {}))
});
return pulumi.output(objs).apply(objs => objs
.reduce((map: {[key: string]: pulumi.CustomResource}, val) => (map[val.name] = val.resource, map), {}));
}

/** @ignore */ function parseYamlObject(
Expand Down
36 changes: 36 additions & 0 deletions tests/integration/performance/performance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2016-2019, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ints

import (
"os"
"testing"

"github.com/pulumi/pulumi/pkg/testing/integration"
)

func TestPerformance(t *testing.T) {
kubectx := os.Getenv("KUBERNETES_CONTEXT")

if kubectx == "" {
t.Skipf("Skipping test due to missing KUBERNETES_CONTEXT variable")
}

integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: "step1",
Dependencies: []string{"@pulumi/kubernetes"},
ExpectRefreshChanges: true, // The Mutating and Validating webhooks update on refresh.
})
}
3 changes: 3 additions & 0 deletions tests/integration/performance/step1/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: performance-tests
description: Regression tests related to performance of large resource inputs.
runtime: nodejs
Loading