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

[sdk/python] Add ready attribute to await Helm charts #1782

Merged
merged 5 commits into from
Nov 1, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## HEAD (Unreleased)

- [sdk/python] Add ready attribute to await Helm charts (https://github.com/pulumi/pulumi-kubernetes/pull/1782)

## 3.8.3 (October 29, 2021)

- Add env variable lookup for k8s client settings (https://github.com/pulumi/pulumi-kubernetes/pull/1777)
Expand Down
2 changes: 1 addition & 1 deletion provider/cmd/pulumi-resource-kubernetes/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -45647,7 +45647,7 @@
},
"readme": "The Kubernetes provider package offers support for all Kubernetes resources and their properties.\nResources are exposed as types from modules based on Kubernetes API groups such as 'apps', 'core',\n'rbac', and 'storage', among many others. Additionally, support for deploying Helm charts ('helm')\nand YAML files ('yaml') is available in this package. Using this package allows you to\nprogrammatically declare instances of any Kubernetes resources and any supported resource version\nusing infrastructure as code, which Pulumi then uses to drive the Kubernetes API.\n\nIf this is your first time using this package, these two resources may be helpful:\n\n* [Kubernetes Getting Started Guide](https://www.pulumi.com/docs/quickstart/kubernetes/): Get up and running quickly.\n* [Kubernetes Pulumi Setup Documentation](https://www.pulumi.com/docs/quickstart/kubernetes/configure/): How to configure Pulumi\n for use with your Kubernetes cluster.\n",
"requires": {
"pulumi": ">=3.0.0,<4.0.0",
"pulumi": ">=3.9.0,<4.0.0",
"pyyaml": ">=5.3.1",
"requests": ">=2.21,<3.0"
},
Expand Down
16 changes: 16 additions & 0 deletions provider/pkg/gen/python-templates/helm/v2/helm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2016-2021, 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.

# *** WARNING: this file was generated by the Pulumi Kubernetes codegen tool. ***
# *** Do not edit by hand unless you're certain you know what you are doing! ***

Expand All @@ -20,6 +34,7 @@ class Chart(pulumi.ComponentResource):
"""
Kubernetes resources contained in this Chart.
"""
ready: pulumi.Output[Sequence[pulumi.Output[pulumi.Resource]]]

def __init__(self,
release_name: str,
Expand Down Expand Up @@ -180,6 +195,7 @@ def omit_resource(obj, opts):
# resolution of all resources that this Helm chart created.
self.resources = all_config.apply(_parse_chart)
self.register_outputs({"resources": self.resources})
self.ready = self.resources.apply(lambda x: list(x.values()))

def get_resource(self,
group_version_kind: str,
Expand Down
16 changes: 16 additions & 0 deletions provider/pkg/gen/python-templates/helm/v3/helm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2016-2021, 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.

# *** WARNING: this file was generated by the Pulumi Kubernetes codegen tool. ***
# *** Do not edit by hand unless you're certain you know what you are doing! ***

Expand All @@ -15,6 +29,7 @@ class Chart(pulumi.ComponentResource):
"""
Kubernetes resources contained in this Chart.
"""
ready: pulumi.Output[Sequence[pulumi.Output[pulumi.Resource]]]

def __init__(self,
release_name: str,
Expand Down Expand Up @@ -181,6 +196,7 @@ def omit_resource(obj, opts):
# resolution of all resources that this Helm chart created.
self.resources = all_config.apply(_parse_chart)
self.register_outputs({"resources": self.resources})
self.ready = self.resources.apply(lambda x: list(x.values()))

def get_resource(self,
group_version_kind: str,
Expand Down
2 changes: 1 addition & 1 deletion provider/pkg/gen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ Use the navigation below to see detailed documentation for each of the supported
})
pkg.Language["python"] = rawMessage(map[string]interface{}{
"requires": map[string]string{
"pulumi": ">=3.0.0,<4.0.0",
"pulumi": ">=3.9.0,<4.0.0",
"requests": ">=2.21,<3.0",
"pyyaml": ">=5.3.1",
},
Expand Down
16 changes: 16 additions & 0 deletions sdk/python/pulumi_kubernetes/helm/v2/helm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2016-2021, 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.

# *** WARNING: this file was generated by the Pulumi Kubernetes codegen tool. ***
# *** Do not edit by hand unless you're certain you know what you are doing! ***

Expand All @@ -20,6 +34,7 @@ class Chart(pulumi.ComponentResource):
"""
Kubernetes resources contained in this Chart.
"""
ready: pulumi.Output[Sequence[pulumi.Output[pulumi.Resource]]]

def __init__(self,
release_name: str,
Expand Down Expand Up @@ -180,6 +195,7 @@ def omit_resource(obj, opts):
# resolution of all resources that this Helm chart created.
self.resources = all_config.apply(_parse_chart)
self.register_outputs({"resources": self.resources})
self.ready = self.resources.apply(lambda x: list(x.values()))

def get_resource(self,
group_version_kind: str,
Expand Down
16 changes: 16 additions & 0 deletions sdk/python/pulumi_kubernetes/helm/v3/helm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2016-2021, 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.

# *** WARNING: this file was generated by the Pulumi Kubernetes codegen tool. ***
# *** Do not edit by hand unless you're certain you know what you are doing! ***

Expand All @@ -15,6 +29,7 @@ class Chart(pulumi.ComponentResource):
"""
Kubernetes resources contained in this Chart.
"""
ready: pulumi.Output[Sequence[pulumi.Output[pulumi.Resource]]]

def __init__(self,
release_name: str,
Expand Down Expand Up @@ -181,6 +196,7 @@ def omit_resource(obj, opts):
# resolution of all resources that this Helm chart created.
self.resources = all_config.apply(_parse_chart)
self.register_outputs({"resources": self.resources})
self.ready = self.resources.apply(lambda x: list(x.values()))

def get_resource(self,
group_version_kind: str,
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def readme():
},
install_requires=[
'parver>=0.2.1',
'pulumi>=3.0.0,<4.0.0',
'pulumi>=3.9.0,<4.0.0',
'pyyaml>=5.3.1',
'requests>=2.21,<3.0',
'semver>=2.8.1'
Expand Down
26 changes: 15 additions & 11 deletions tests/sdk/python/helm-local/step1/__main__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# Copyright 2016-2020, Pulumi Corporation.
# Copyright 2016-2021, 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
# 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
# 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.
# 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.

import pulumi
from pulumi_kubernetes.core.v1 import ConfigMap, ConfigMapInitArgs
from pulumi_kubernetes.helm.v2 import Chart, LocalChartOpts

values = {"service": {"type": "ClusterIP"}}

Chart("nginx", LocalChartOpts(path="nginx", values=values))
chart = Chart("nginx", LocalChartOpts(path="nginx", values=values))
foo = ConfigMap("foo", ConfigMapInitArgs(data={"foo": "bar"}), opts=pulumi.ResourceOptions(depends_on=chart.ready))

# Deploy a duplicate chart with a different resource prefix to verify that multiple instances of the Chart
# can be managed in the same stack.
Expand Down
2 changes: 1 addition & 1 deletion tests/sdk/python/helm-local/step1/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pulumi>=2.0.0,<3.0.0
pulumi>=3.0.0,<4.0.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be >= 3.9.0 as well?

Copy link
Member Author

@lblackstone lblackstone Nov 1, 2021

Choose a reason for hiding this comment

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

Yeah, but I figured I'd leave it as is so that it's easier to find/replace when 4.0 rolls around.

26 changes: 15 additions & 11 deletions tests/sdk/python/helm-local/step2/__main__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# Copyright 2016-2019, Pulumi Corporation.
# Copyright 2016-2021, 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
# 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
# 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.
# 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.

import pulumi
from pulumi_kubernetes.core.v1 import ConfigMap, ConfigMapInitArgs
from pulumi_kubernetes.helm.v3 import Chart, LocalChartOpts

values = {"service": {"type": "ClusterIP"}}

Chart("nginx", LocalChartOpts(path="nginx", values=values))
chart = Chart("nginx", LocalChartOpts(path="nginx", values=values))
foo = ConfigMap("foo", ConfigMapInitArgs(data={"foo": "bar"}), opts=pulumi.ResourceOptions(depends_on=chart.ready))

# Deploy a duplicate chart with a different resource prefix to verify that multiple instances of the Chart
# can be managed in the same stack.
Expand Down
31 changes: 30 additions & 1 deletion tests/sdk/python/python_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016-2020, Pulumi Corporation.
// Copyright 2016-2021, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@ import (
"fmt"
"os"
"path/filepath"
"regexp"
"sort"
"strings"
"testing"
Expand Down Expand Up @@ -360,6 +361,34 @@ func TestHelmLocal(t *testing.T) {
}
options := baseOptions.With(integration.ProgramTestOptions{
Dir: filepath.Join(cwd, "helm-local", "step1"),
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is neat! DId you verify this fails before the fix?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep! Without the fix, both ConfigMap resources will create before the Deployment and Service.

// Verify resource creation order using the Event stream. The Chart resources must be created
// first, followed by the dependent ConfigMap. (The ConfigMap doesn't actually need the Chart, but
// it creates almost instantly, so it's a good choice to test creation ordering)
cmRegex := regexp.MustCompile(`ConfigMap::nginx-server-block`)
svcRegex := regexp.MustCompile(`Service::nginx`)
deployRegex := regexp.MustCompile(`Deployment::nginx`)
dependentRegex := regexp.MustCompile(`ConfigMap::foo`)

var configmapFound, serviceFound, deploymentFound, dependentFound bool
for _, e := range stackInfo.Events {
if e.ResOutputsEvent != nil {
switch {
case cmRegex.MatchString(e.ResOutputsEvent.Metadata.URN):
configmapFound = true
case svcRegex.MatchString(e.ResOutputsEvent.Metadata.URN):
serviceFound = true
case deployRegex.MatchString(e.ResOutputsEvent.Metadata.URN):
deploymentFound = true
case dependentRegex.MatchString(e.ResOutputsEvent.Metadata.URN):
dependentFound = true
}
assert.Falsef(t, dependentFound && !(configmapFound && serviceFound && deploymentFound),
"dependent ConfigMap created before all chart resources were ready")
fmt.Println(e.ResOutputsEvent.Metadata.URN)
}
}
},
EditDirs: []integration.EditDir{
{
Dir: filepath.Join(cwd, "helm-local", "step2"),
Expand Down