diff --git a/CHANGELOG.md b/CHANGELOG.md index 302ce8c365..db0e24516a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,6 +85,10 @@ - Fixed a panic that could occur during deletion. (https://github.com/pulumi/pulumi-kubernetes/issues/3157) +- Fixed an error that could occur when previewing `yaml/v2` resources which + depend on CRDs created in the same update. + (https://github.com/pulumi/pulumi-kubernetes/issues/3176) + ## 4.17.1 (August 16, 2024) ### Fixed diff --git a/provider/pkg/provider/yaml/v2/yaml.go b/provider/pkg/provider/yaml/v2/yaml.go index 1275f42b07..2903fa568a 100644 --- a/provider/pkg/provider/yaml/v2/yaml.go +++ b/provider/pkg/provider/yaml/v2/yaml.go @@ -167,7 +167,14 @@ func Normalize(objs []unstructured.Unstructured, defaultNamespace string, client // determine whether the kind is namespaced, which may involve a call to the API server. // note that the object list is searched for a matching CRD before resorting to a discovery call. isNamespaced, err := clients.IsNamespacedKind(gvk, clientSet, objs...) - if err != nil { + if clients.IsNoNamespaceInfoErr(err) { + // This can happen during previews, or when running concurrent with + // a Release which doesn't give us visibility into the CRDs it will + // be creating. Since we can't tell for sure at this point, assume + // it is namespaced, and correct if required during the Create + // step. + isNamespaced = true + } else if err != nil { return nil, err } if isNamespaced && obj.GetNamespace() == "" { diff --git a/provider/pkg/provider/yaml/v2/yaml_test.go b/provider/pkg/provider/yaml/v2/yaml_test.go index 362352a1c4..8dd1d42969 100644 --- a/provider/pkg/provider/yaml/v2/yaml_test.go +++ b/provider/pkg/provider/yaml/v2/yaml_test.go @@ -553,6 +553,28 @@ var _ = Describe("Normalize", func() { )) }) }) + + Context("when the object is an unrecognized custom resource", func() { + BeforeEach(func() { + objs = []unstructured.Unstructured{{ + Object: map[string]any{ + "apiVersion": "test.pulumi.com/v1", + "kind": "Unknown", + "metadata": map[string]any{ + "name": "foo", + }, + }, + }} + }) + + It("should assume it is namespaced", func(ctx context.Context) { + objs, err := Normalize(objs, defaultNamespace, clientSet) + Expect(err).ShouldNot(HaveOccurred()) + Expect(objs).To(HaveExactElements( + matchUnstructured(Keys{"metadata": MatchKeys(IgnoreExtras, Keys{"namespace": Equal("default")})}), + )) + }) + }) }) Describe("special-case kinds", func() {