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

api: add plural exception for "parameters" #123936

Conversation

pohly
Copy link
Contributor

@pohly pohly commented Mar 14, 2024

What type of PR is this?

/kind bug

What this PR does / why we need it:

This is for ResourceClassParameters and ResourceClaimParameters (added in 1.30). Without this, the fake clientset does not handle those objects correctly because it computes the resource name
incorrectly ("resourceclassparameterses").

Which issue(s) this PR fixes:

Nothing affected in the wild (yet).

Does this PR introduce a user-facing change?

NONE

This is for ResourceClassParameters and ResourceClaimParameters (added in
1.30). Without this, the fake clientset does not handle those objects correctly
because it computes the resource name
incorrectly ("resourceclassparameterses").
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. labels Mar 14, 2024
@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Mar 14, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pohly
Once this PR has been reviewed and has the lgtm label, please assign caesarxuchao for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Mar 14, 2024
@jiahuif
Copy link
Member

jiahuif commented Mar 14, 2024

/assign @liggitt
For staging/apimachinery
Thank you
/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Mar 14, 2024
@liggitt
Copy link
Member

liggitt commented Mar 14, 2024

xref previous attempts to expand this function in #110053

I'm -1 on adding more things to this list for the same reasons indicated in that issue. Changes here affects all apimachinery callers ... instead, this should be motivation to fix how fake clients are told the resource name to use (e.g. attempts in #119924)

@pohly
Copy link
Contributor Author

pohly commented Mar 14, 2024

Ack. Is there any short-term workaround? I need the fake client to handle ResourceClaimParameters and ResourceClassParameters correctly for unit testing in #123938.

@pohly
Copy link
Contributor Author

pohly commented Mar 14, 2024

I found a workaround:

	// Quick-and-dirty workaround for fake client storing ResourceClassParameters and
	// ResourceClaimParameters as "resourceclassparameterses" and "resourceclaimparameterses":
	// intercept the correct LIST from the informers and reply to them with the incorrect
	// LIST result.
	tc.client.PrependReactor("list", "resourceclaimparameters", createListReactor(tc.client.Tracker(), "ResourceClaimParameters"))
	tc.client.PrependReactor("list", "resourceclassparameters", createListReactor(tc.client.Tracker(), "ResourceClassParameters"))

...

func createListReactor(tracker cgotesting.ObjectTracker, kind string) func(action cgotesting.Action) (handled bool, ret apiruntime.Object, err error) {
	return func(action cgotesting.Action) (handled bool, ret apiruntime.Object, err error) {
		// listAction := action.(cgotesting.ListAction)
		gvr := action.GetResource()
		ns := action.GetNamespace()
		gvr.Resource += "es"
		list, err := tracker.List(gvr, schema.GroupVersionKind{Group: gvr.Group, Version: gvr.Version, Kind: kind}, ns)
		return true, list, err
	}
}

/close

@k8s-ci-robot
Copy link
Contributor

@pohly: Closed this PR.

In response to this:

I found a workaround:

  // Quick-and-dirty workaround for fake client storing ResourceClassParameters and
  // ResourceClaimParameters as "resourceclassparameterses" and "resourceclaimparameterses":
  // intercept the correct LIST from the informers and reply to them with the incorrect
  // LIST result.
  tc.client.PrependReactor("list", "resourceclaimparameters", createListReactor(tc.client.Tracker(), "ResourceClaimParameters"))
  tc.client.PrependReactor("list", "resourceclassparameters", createListReactor(tc.client.Tracker(), "ResourceClassParameters"))

...

func createListReactor(tracker cgotesting.ObjectTracker, kind string) func(action cgotesting.Action) (handled bool, ret apiruntime.Object, err error) {
  return func(action cgotesting.Action) (handled bool, ret apiruntime.Object, err error) {
  	// listAction := action.(cgotesting.ListAction)
  	gvr := action.GetResource()
  	ns := action.GetNamespace()
  	gvr.Resource += "es"
  	list, err := tracker.List(gvr, schema.GroupVersionKind{Group: gvr.Group, Version: gvr.Version, Kind: kind}, ns)
  	return true, list, err
  }
}

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants