-
Notifications
You must be signed in to change notification settings - Fork 115
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
Bugfix for ambiguous kinds #2889
Conversation
Does the PR have any schema changes?Looking good! No breaking changes found. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2889 +/- ##
==========================================
+ Coverage 26.86% 26.91% +0.04%
==========================================
Files 53 53
Lines 7724 7736 +12
==========================================
+ Hits 2075 2082 +7
- Misses 5476 5481 +5
Partials 173 173 ☔ View full report in Codecov by Sentry. |
namespaced, err := IsNamespacedKind(gvk, dcs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if namespaced { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rationale: the mapper returns the requisite scope information, the call to IsNamespaceKind
is redundant. It is also problematic because the mapper is case-insensitive whereas kinds.go
is not.
switch k { | ||
case PodSecurityPolicy, PodSecurityPolicyList: | ||
return &v125 | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rationale: this code wasn't considering the GroupVersion, and was actually returning the wrong result for extensions/v1beta1:PodSecurityPolicy
(which was removed in v1.16).
func IsNamespacedKind(gvk schema.GroupVersionKind, clientSet *DynamicClientSet) (bool, error) { | ||
func IsNamespacedKind(gvk schema.GroupVersionKind, disco discovery.DiscoveryInterface) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rationale: changing the function signature to make it more easily testable (using the fake disco client).
if known, namespaced := kinds.Kind(kind).Namespaced(); known { | ||
return namespaced, nil | ||
if kinds.KnownGroupVersions.Has(gvk.GroupVersion().String()) { | ||
kind := strings.TrimSuffix(gvk.Kind, "Patch") // Check using the underlying kind for Patch resources |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it unnecessary to trim the Patch
suffix (because the kind
of the patch resource is Pod
not PodPatch
), but is also harmless because it is applied only to the well-known kinds. cc @lblackstone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Looking at the context of the change again, I think that may have been a holdover from a previous implementation. It's probably not needed, but also doesn't hurt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I'll defer to @rquitales for approval since it's been a long time since I've thought about this code.
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [@pulumi/kubernetes](https://pulumi.com) ([source](https://github.com/pulumi/pulumi-kubernetes)) | dependencies | minor | [`4.9.1` -> `4.10.0`](https://renovatebot.com/diffs/npm/@pulumi%2fkubernetes/4.9.1/4.10.0) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>pulumi/pulumi-kubernetes (@​pulumi/kubernetes)</summary> ### [`v4.10.0`](https://github.com/pulumi/pulumi-kubernetes/blob/HEAD/CHANGELOG.md#4100-April-11-2024) [Compare Source](https://github.com/pulumi/pulumi-kubernetes/compare/v4.9.1...v4.10.0) - ConfigGroup V2 ([https://github.com/pulumi/pulumi-kubernetes/pull/2844](https://github.com/pulumi/pulumi-kubernetes/pull/2844)) - ConfigFile V2 ([https://github.com/pulumi/pulumi-kubernetes/pull/2862](https://github.com/pulumi/pulumi-kubernetes/pull/2862)) - Bugfix for ambiguous kinds ([https://github.com/pulumi/pulumi-kubernetes/pull/2889](https://github.com/pulumi/pulumi-kubernetes/pull/2889)) - \[yaml/v2] Support for resource ordering [https://github.com/pulumi/pulumi-kubernetes/pull/2894](https://github.com/pulumi/pulumi-kubernetes/pull/2894)4) - Bugfix for deployment await logic not referencing the correct deployment status ([https://github.com/pulumi/pulumi-kubernetes/pull/2943](https://github.com/pulumi/pulumi-kubernetes/pull/2943)) ##### New Features A new MLC-based implementation of `ConfigGroup` and of `ConfigFile` is now available in the "yaml/v2" package. These resources are usable in all Pulumi languages, including Pulumi YAML and in the Java Pulumi SDK. Note that transformations aren't supported in this release (see [https://github.com/pulumi/pulumi/issues/12996](https://github.com/pulumi/pulumi/issues/12996)). </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yODcuMSIsInVwZGF0ZWRJblZlciI6IjM3LjI4Ny4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9ucG0iLCJ0eXBlL21pbm9yIl19--> Co-authored-by: lumiere-bot[bot] <98047013+lumiere-bot[bot]@users.noreply.github.com>
Proposed changes
This PR fixes a couple of related problems with "ambiguous kinds":
Role
), be sure to check the apiversion before using built-in information or dynamic discovery.Note that kubectl has the following behavior w.r.t (2):
An explanation of the technical approach: the
kinds.Kind
type is used in the codebase to represent a well-known kind, i.e. known at code generation time. To prepare this PR, I audited the locations whereKind
is used, and ensured that it wasn't being used for arbitrary kinds. Where necessary, the use ofKind
was conditioned on theapiVersion
being one of the well-known values.Related issues (optional)
Closes #2865
Closes #2143