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 panic with computed values on preview #1368

Merged
merged 3 commits into from
Nov 10, 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: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
## HEAD (Unreleased)

- Add support for previewing Create and Update operations for API servers that support dry-run (https://github.com/pulumi/pulumi-kubernetes/pull/1355)
- Fix panic introduced in #1355 (https://github.com/pulumi/pulumi-kubernetes/pull/1368)

## 2.6.3 (October 12, 2020)

- Add support for previewing Create and Update operations for API servers that support dry-run (https://github.com/pulumi/pulumi-kubernetes/pull/1355)
- Revert Helm v2 deprecation warnings (https://github.com/pulumi/pulumi-kubernetes/pull/1352)

## 2.6.2 (October 7, 2020)
Expand Down
38 changes: 19 additions & 19 deletions provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1418,26 +1418,26 @@ func (k *kubeProvider) Create(

newInputs := propMapToUnstructured(newResInputs)

annotatedInputs, err := withLastAppliedConfig(newInputs)
if err != nil {
return nil, pkgerrors.Wrapf(
err, "Failed to create resource %s/%s because of an error generating the %s value in "+
"`.metadata.annotations`",
newInputs.GetNamespace(), newInputs.GetName(), lastAppliedConfigKey)
}

// If this is a preview and the input values contain unknowns, return them as-is. This is compatible with
// prior behavior implemented by the Pulumi engine. Similarly, if the server does not support server-side
// dry run, return the inputs as-is.
if req.GetPreview() &&
(hasComputedValue(annotatedInputs) || !k.supportsDryRun(annotatedInputs.GroupVersionKind())) {
(hasComputedValue(newInputs) || !k.supportsDryRun(newInputs.GroupVersionKind())) {

logger.V(9).Infof("cannot preview Create(%v)", urn)
return &pulumirpc.CreateResponse{
Id: fqObjName(annotatedInputs), Properties: req.GetProperties(),
Id: fqObjName(newInputs), Properties: req.GetProperties(),
}, nil
}

annotatedInputs, err := withLastAppliedConfig(newInputs)
if err != nil {
return nil, pkgerrors.Wrapf(
err, "Failed to create resource %s/%s because of an error generating the %s value in "+
"`.metadata.annotations`",
newInputs.GetNamespace(), newInputs.GetName(), lastAppliedConfigKey)
}

initialAPIVersion := newInputs.GetAPIVersion()

if k.yamlRenderMode {
Expand Down Expand Up @@ -1818,24 +1818,24 @@ func (k *kubeProvider) Update(
}
newInputs := propMapToUnstructured(newResInputs)

annotatedInputs, err := withLastAppliedConfig(newInputs)
if err != nil {
return nil, pkgerrors.Wrapf(
err, "Failed to update resource %s/%s because of an error generating the %s value in "+
"`.metadata.annotations`",
newInputs.GetNamespace(), newInputs.GetName(), lastAppliedConfigKey)
}

// If this is a preview and the input values contain unknowns, return them as-is. This is compatible with
// prior behavior implemented by the Pulumi engine. Similarly, if the server does not support server-side
// dry run, return the inputs as-is.
if req.GetPreview() &&
(hasComputedValue(annotatedInputs) || !k.supportsDryRun(annotatedInputs.GroupVersionKind())) {
(hasComputedValue(newInputs) || !k.supportsDryRun(newInputs.GroupVersionKind())) {

logger.V(9).Infof("cannot preview Update(%v)", urn)
return &pulumirpc.UpdateResponse{Properties: req.News}, nil
}

annotatedInputs, err := withLastAppliedConfig(newInputs)
if err != nil {
return nil, pkgerrors.Wrapf(
err, "Failed to update resource %s/%s because of an error generating the %s value in "+
"`.metadata.annotations`",
newInputs.GetNamespace(), newInputs.GetName(), lastAppliedConfigKey)
}

initialAPIVersion, err := initialAPIVersion(oldState, oldInputs)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ replace (
require (
github.com/pulumi/pulumi-kubernetes/provider/v2 v2.0.0
github.com/pulumi/pulumi-kubernetes/sdk/v2 v2.4.3
github.com/pulumi/pulumi/pkg/v2 v2.10.2
github.com/pulumi/pulumi/sdk/v2 v2.10.2
github.com/pulumi/pulumi/pkg/v2 v2.11.3-0.20201012185126-156aa9862e15
github.com/pulumi/pulumi/sdk/v2 v2.11.3-0.20201012185126-156aa9862e15
github.com/stretchr/testify v1.6.1
)
4 changes: 4 additions & 0 deletions tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -858,11 +858,15 @@ github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+Gx
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/pulumi/pulumi/pkg/v2 v2.10.2 h1:fmqbtsf+GR9DKJjB8dVYzu5b9J5C1ZPCKpmY+hGjSnc=
github.com/pulumi/pulumi/pkg/v2 v2.10.2/go.mod h1:zQWe2D4tYJDeXNzSclqNmP8/SMSKOh8k22AbWg3+mVc=
github.com/pulumi/pulumi/pkg/v2 v2.11.3-0.20201012185126-156aa9862e15 h1:N4+VC5U8weg6k9DeJhX2GdOTaxgzjzG5JU0BjRIDlnM=
github.com/pulumi/pulumi/pkg/v2 v2.11.3-0.20201012185126-156aa9862e15/go.mod h1:7NmgAy555Lk7v4Ddb6HF1BVAhdyT3012h47vz/hLD2k=
github.com/pulumi/pulumi/sdk/v2 v2.2.1/go.mod h1:QNbWpL4gvf3X0lUFT7TXA2Jo1ff/Ti2l97AyFGYwvW4=
github.com/pulumi/pulumi/sdk/v2 v2.10.2-0.20200917182150-ab70dd3d645d h1:xIY2dPPLqnqCbNbd3SF/+k9hYYxW0d+4O+xfkKWxL/k=
github.com/pulumi/pulumi/sdk/v2 v2.10.2-0.20200917182150-ab70dd3d645d/go.mod h1:EED7KCDOohYIewUppsav5KHTFTmfYGqUFib1uRvYdWQ=
github.com/pulumi/pulumi/sdk/v2 v2.10.2 h1:NPB5bs1b6ta/LEKQKh0hVIRUxczI4MTrEfAeymls5xY=
github.com/pulumi/pulumi/sdk/v2 v2.10.2/go.mod h1:EED7KCDOohYIewUppsav5KHTFTmfYGqUFib1uRvYdWQ=
github.com/pulumi/pulumi/sdk/v2 v2.11.3-0.20201012185126-156aa9862e15 h1:ivePIkhn9MsrBSJFqYVJKf03BxWVWN5WrSLQL7SJ9zM=
github.com/pulumi/pulumi/sdk/v2 v2.11.3-0.20201012185126-156aa9862e15/go.mod h1:WQ4WaHMA7mduVHAJi87iIqbWvqsuBUYccBiKK+FrayI=
github.com/qri-io/starlib v0.4.2-0.20200213133954-ff2e8cd5ef8d/go.mod h1:7DPO4domFU579Ga6E61sB9VFNaniPVwJP5C4bBCu3wA=
github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
Expand Down
57 changes: 57 additions & 0 deletions tests/sdk/python/get-old/step1/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2016-2020, 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.
#
# 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.

import pulumi
from pulumi_kubernetes.apiextensions.CustomResource import CustomResource
from pulumi_kubernetes.apiextensions.v1beta1.CustomResourceDefinition import CustomResourceDefinition
from pulumi_kubernetes.core.v1 import Service
from pulumi_kubernetes.core.v1.Namespace import Namespace

service = Service.get("kube-api", "kubernetes")

crd = CustomResourceDefinition(
resource_name="foo",
metadata={"name": "gettests.python.test"},
spec={
"group": "python.test",
"version": "v1",
"scope": "Namespaced",
"names": {
"plural": "gettests",
"singular": "gettest",
"kind": "GetTest",
}
})

ns = Namespace("ns")

cr = CustomResource(
resource_name="foo",
api_version="python.test/v1",
kind="GetTest",
metadata={"namespace": ns.metadata["name"]},
spec={"foo": "bar"},
opts=pulumi.ResourceOptions(depends_on=[crd]))
50 changes: 50 additions & 0 deletions tests/sdk/python/get/step1/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2016-2020, 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.

import pulumi
from pulumi_kubernetes.apiextensions.CustomResource import CustomResource
from pulumi_kubernetes.apiextensions.v1beta1.CustomResourceDefinition import (
CustomResourceDefinition,
CustomResourceDefinitionNamesArgs,
CustomResourceDefinitionSpecArgs,
)
from pulumi_kubernetes.core.v1 import Service
from pulumi_kubernetes.core.v1.Namespace import Namespace
from pulumi_kubernetes.meta.v1 import ObjectMetaArgs

service = Service.get("kube-api", "kubernetes")

crd = CustomResourceDefinition(
resource_name="foo",
metadata=ObjectMetaArgs(name="gettests.python.test"),
spec=CustomResourceDefinitionSpecArgs(
group="python.test",
version="v1",
scope="Namespaced",
names=CustomResourceDefinitionNamesArgs(
plural="gettests",
singular="gettest",
kind="GetTest",
),
))

ns = Namespace("ns")

cr = CustomResource(
resource_name="foo",
api_version="python.test/v1",
kind="GetTest",
metadata={"namespace": ns.metadata["name"]},
spec={"foo": "bar"},
opts=pulumi.ResourceOptions(depends_on=[crd]))
10 changes: 8 additions & 2 deletions tests/sdk/python/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,18 @@ func TestGet(t *testing.T) {
if !assert.NoError(t, err) {
t.FailNow()
}
for _, dir := range []string{"get", "get-old"} {
for _, dir := range []string{ "get-old"} {
t.Run(dir, func(t *testing.T) {
options := baseOptions.With(integration.ProgramTestOptions{
ExpectRefreshChanges: true, // CRD changes on refresh
Dir: filepath.Join(cwd, dir),
Dir: filepath.Join(cwd, dir, "step1"),
NoParallel: true,
EditDirs: []integration.EditDir{
{
Dir: "step2",
Additive: true,
},
},
})
integration.ProgramTest(t, &options)
})
Expand Down