controller-runtime icon indicating copy to clipboard operation
controller-runtime copied to clipboard

LazyRESTMapper KindsFor does not return all versions when single version is previously queried

Open tenstad opened this issue 2 years ago • 8 comments

Problem

addKnownGroupAndReload is only triggered when no matches are found. If priming the mapper with a single version and then requesting all versions (not specifying version), a match is found and only a single version returned (not multiple versions).

func (m *mapper) KindsFor(resource schema.GroupVersionResource) ([]schema.GroupVersionKind, error) {
	res, err := m.getMapper().KindsFor(resource)
	if meta.IsNoMatchError(err) {
		if err := m.addKnownGroupAndReload(resource.Group, resource.Version); err != nil {

Test Case

The test passes if lazyRestMapper.KindsFor(schema.GroupVersionResource{Group: "autoscaling", Version: "v1", Resource: "horizontalpodautoscaler"}) is removed, thus making the other KindsFor trigger a addKnownGroupAndReload.

t.Run("LazyRESTMapper should be able to fetch all versions after fetching single version", func(t *testing.T) {
	g := gmg.NewWithT(t)

	httpClient, err := rest.HTTPClientFor(restCfg)
	g.Expect(err).NotTo(gmg.HaveOccurred())

	lazyRestMapper, err := apiutil.NewDynamicRESTMapper(restCfg, httpClient)
	g.Expect(err).NotTo(gmg.HaveOccurred())

	_, err = lazyRestMapper.KindsFor(schema.GroupVersionResource{Group: "autoscaling", Version: "v1", Resource: "horizontalpodautoscaler"})
	g.Expect(err).NotTo(gmg.HaveOccurred())

	kinds, err := lazyRestMapper.KindsFor(schema.GroupVersionResource{Group: "autoscaling", Resource: "horizontalpodautoscaler"})
	g.Expect(err).NotTo(gmg.HaveOccurred())
	g.Expect(len(kinds)).To(gmg.BeNumerically(">", 1))
})

Suggestion

Trigger addKnownGroupAndReload when schema.GroupVersionResource input is partial, and some fields are unspecified.

tenstad avatar May 25 '23 07:05 tenstad

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Jan 21 '24 05:01 k8s-triage-robot

/triage accepted

We fixed a somewhat related issue recently via: https://github.com/kubernetes-sigs/controller-runtime/pull/2663. But I think this doesn't change the problem described here.

sbueringer avatar Feb 09 '24 14:02 sbueringer

This issue has not been updated in over 1 year, and should be re-triaged.

You can:

  • Confirm that this issue is still relevant with /triage accepted (org members only)
  • Close this issue with /close

For more details on the triage process, see https://www.kubernetes.dev/docs/guide/issue-triage/

/remove-triage accepted

k8s-triage-robot avatar Feb 08 '25 14:02 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Mar 10 '25 15:03 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-triage-robot avatar Apr 09 '25 16:04 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

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-sigs/prow repository.

k8s-ci-robot avatar Apr 09 '25 16:04 k8s-ci-robot

/remove-lifecycle rotten /lifecycle frozen /reopen

sbueringer avatar May 08 '25 04:05 sbueringer

@sbueringer: Reopened this issue.

In response to this:

/remove-lifecycle rotten /lifecycle frozen /reopen

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-sigs/prow repository.

k8s-ci-robot avatar May 08 '25 04:05 k8s-ci-robot