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

Bugfix for ambiguous kinds #2889

Merged
merged 4 commits into from
Mar 19, 2024
Merged

Bugfix for ambiguous kinds #2889

merged 4 commits into from
Mar 19, 2024

Conversation

EronWright
Copy link
Contributor

@EronWright EronWright commented Mar 16, 2024

Proposed changes

This PR fixes a couple of related problems with "ambiguous kinds":

  1. For kinds with clashing names (e.g. Role), be sure to check the apiversion before using built-in information or dynamic discovery.
  2. For kinds with casing problems, don't mask the problem; show the API server error.

Note that kubectl has the following behavior w.r.t (2):

apiVersion: awx.ansible.com/v1beta1
kind: awx
metadata:
  name: my-awx
  namespace: awx
❯ kubectl apply -f manifest.yaml --server-side=false
The awx "my-awx" is invalid: kind: Invalid value: "awx": must be AWX
❯ kubectl apply -f manifest.yaml --server-side=true
Error from server (BadRequest): invalid object type: awx.ansible.com/v1beta1, Kind=awx

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 where Kind is used, and ensured that it wasn't being used for arbitrary kinds. Where necessary, the use of Kind was conditioned on the apiVersion being one of the well-known values.

Related issues (optional)

Closes #2865
Closes #2143

Copy link

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

Copy link

codecov bot commented Mar 16, 2024

Codecov Report

Attention: Patch coverage is 41.37931% with 17 lines in your changes are missing coverage. Please review.

Project coverage is 26.91%. Comparing base (76bf618) to head (ac13430).
Report is 1 commits behind head on master.

Files Patch % Lines
provider/pkg/provider/provider.go 0.00% 9 Missing ⚠️
provider/pkg/provider/invoke_decode_yaml.go 0.00% 4 Missing ⚠️
provider/pkg/clients/clients.go 70.00% 2 Missing and 1 partial ⚠️
provider/pkg/kinds/deprecated.go 83.33% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

Comment on lines -96 to -101
namespaced, err := IsNamespacedKind(gvk, dcs)
if err != nil {
return nil, err
}

if namespaced {
Copy link
Contributor Author

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.

Comment on lines -264 to -268
switch k {
case PodSecurityPolicy, PodSecurityPolicyList:
return &v125
}

Copy link
Contributor Author

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).

Comment on lines -167 to +169
func IsNamespacedKind(gvk schema.GroupVersionKind, clientSet *DynamicClientSet) (bool, error) {
func IsNamespacedKind(gvk schema.GroupVersionKind, disco discovery.DiscoveryInterface) (bool, error) {
Copy link
Contributor Author

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
Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Member

@lblackstone lblackstone left a 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.

@EronWright EronWright merged commit 1d7e3b6 into master Mar 19, 2024
17 of 18 checks passed
@EronWright EronWright deleted the eronwright/issue-2865 branch March 19, 2024 21:26
lumiere-bot bot added a commit to coolguy1771/home-ops that referenced this pull request Apr 12, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@pulumi/kubernetes](https://pulumi.com)
([source](https://togithub.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 (@&#8203;pulumi/kubernetes)</summary>

###
[`v4.10.0`](https://togithub.com/pulumi/pulumi-kubernetes/blob/HEAD/CHANGELOG.md#4100-April-11-2024)

[Compare
Source](https://togithub.com/pulumi/pulumi-kubernetes/compare/v4.9.1...v4.10.0)

- ConfigGroup V2
([pulumi/pulumi-kubernetes#2844)
- ConfigFile V2
([pulumi/pulumi-kubernetes#2862)
- Bugfix for ambiguous kinds
([pulumi/pulumi-kubernetes#2889)
- \[yaml/v2] Support for resource ordering
[pulumi/pulumi-kubernetes#2894)
- Bugfix for deployment await logic not referencing the correct
deployment status
([pulumi/pulumi-kubernetes#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
[pulumi/pulumi#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://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yODcuMSIsInVwZGF0ZWRJblZlciI6IjM3LjI4Ny4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9ucG0iLCJ0eXBlL21pbm9yIl19-->

Co-authored-by: lumiere-bot[bot] <98047013+lumiere-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants