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

Make v2 YAML more forgiving when checking GVK for namespaced-ness #3186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -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
Expand Down
9 changes: 8 additions & 1 deletion provider/pkg/provider/yaml/v2/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() == "" {
Expand Down
22 changes: 22 additions & 0 deletions provider/pkg/provider/yaml/v2/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading