client-go icon indicating copy to clipboard operation
client-go copied to clipboard

Pluralization discrepancy in UnsafeGuessKindToResource still exists

Open Limorerez opened this issue 2 years ago • 21 comments

Expected:

gateway-> gateways Got: gateway-> gatewaies

Is there any way to affect this mistaken guessing?

Limorerez avatar Apr 07 '22 16:04 Limorerez

Is there any way to affect this mistaken guessing?

A workaround is to pass empty list of objects https://github.com/kubernetes/client-go/blob/cab7ba1d4a523956b6395dcbe38620159ac43fef/kubernetes/fake/clientset_generated.go#L124-L130 and manually use Create() on the tracker instead of Add() as suggested here https://github.com/kubernetes/client-go/blob/cab7ba1d4a523956b6395dcbe38620159ac43fef/testing/fixture.go#L326-L330

AlexanderYastrebov avatar May 19 '22 21:05 AlexanderYastrebov

Also https://github.com/kubernetes/code-generator uses https://pkg.go.dev/k8s.io/gengo/namer#NewAllLowercasePluralNamer

AlexanderYastrebov avatar May 19 '22 21:05 AlexanderYastrebov

I've also stumbled across this when using

		dynClient := dyn_fake.NewSimpleDynamicClientWithCustomListKinds(scheme.Scheme,
			map[schema.GroupVersionResource]string{
				{
					Group:    "gateway.networking.k8s.io",
					Version:  "v1beta1",
					Resource: "gateways",
				}: "GatewayList",
			},
			...
		)

and then listing a gateway (via unstructured client) yields

panic: coding error: you must register resource to list kind for every resource you're going to LIST when creating the client.  See NewSimpleDynamicClientWithCustomListKinds or register the list into the scheme: gateway.networking.k8s.io/v1beta1, Resource=gateways out of map[/, Resource=:List /v1, Resource=apigroups:APIGroupList /v1, Resource=apiresources:APIResourceList /v1, Resource=componentstatuses:ComponentStatusList /v1, Resource=configmaps:ConfigMapList /v1, Resource=endpoints:EndpointsList /v1, Resource=events:EventList /v1, Resource=limitranges:LimitRangeList /v1, Resource=namespaces:NamespaceList /v1, Resource=nodes:NodeList /v1, Resource=persistentvolumeclaims:PersistentVolumeClaimList /v1, Resource=persistentvolumes:PersistentVolumeList /v1, Resource=pods:PodList /v1, Resource=podtemplates:PodTemplateList /v1, Resource=replicationcontrollers:ReplicationControllerList /v1, Resource=resourcequotas:ResourceQuotaList /v1, Resource=secrets:SecretList /v1, Resource=serviceaccounts:ServiceAccountList /v1, Resource=services:ServiceList admissionregistration.k8s.io/v1, Resource=mutatingwebhookconfigurations:MutatingWebhookConfigurationList admissionregistration.k8s.io/v1, Resource=validatingwebhookconfigurations:ValidatingWebhookConfigurationList admissionregistration.k8s.io/v1beta1, Resource=mutatingwebhookconfigurations:MutatingWebhookConfigurationList admissionregistration.k8s.io/v1beta1, Resource=validatingwebhookconfigurations:ValidatingWebhookConfigurationList apps/v1, Resource=controllerrevisions:ControllerRevisionList apps/v1, Resource=daemonsets:DaemonSetList apps/v1, Resource=deployments:DeploymentList apps/v1, Resource=replicasets:ReplicaSetList apps/v1, Resource=statefulsets:StatefulSetList apps/v1beta1, Resource=controllerrevisions:ControllerRevisionList apps/v1beta1, Resource=deployments:DeploymentList apps/v1beta1, Resource=statefulsets:StatefulSetList apps/v1beta2, Resource=controllerrevisions:ControllerRevisionList apps/v1beta2, Resource=daemonsets:DaemonSetList apps/v1beta2, Resource=deployments:DeploymentList apps/v1beta2, Resource=replicasets:ReplicaSetList apps/v1beta2, Resource=statefulsets:StatefulSetList autoscaling/v1, Resource=horizontalpodautoscalers:HorizontalPodAutoscalerList autoscaling/v2, Resource=horizontalpodautoscalers:HorizontalPodAutoscalerList autoscaling/v2beta1, Resource=horizontalpodautoscalers:HorizontalPodAutoscalerList autoscaling/v2beta2, Resource=horizontalpodautoscalers:HorizontalPodAutoscalerList batch/v1, Resource=cronjobs:CronJobList batch/v1, Resource=jobs:JobList batch/v1beta1, Resource=cronjobs:CronJobList certificates.k8s.io/v1, Resource=certificatesigningrequests:CertificateSigningRequestList certificates.k8s.io/v1beta1, Resource=certificatesigningrequests:CertificateSigningRequestList coordination.k8s.io/v1, Resource=leases:LeaseList coordination.k8s.io/v1beta1, Resource=leases:LeaseList discovery.k8s.io/v1, Resource=endpointslices:EndpointSliceList discovery.k8s.io/v1beta1, Resource=endpointslices:EndpointSliceList events.k8s.io/v1, Resource=events:EventList events.k8s.io/v1beta1, Resource=events:EventList extensions/v1beta1, Resource=daemonsets:DaemonSetList extensions/v1beta1, Resource=deployments:DeploymentList extensions/v1beta1, Resource=ingresses:IngressList extensions/v1beta1, Resource=networkpolicies:NetworkPolicyList extensions/v1beta1, Resource=podsecuritypolicies:PodSecurityPolicyList extensions/v1beta1, Resource=replicasets:ReplicaSetList flowcontrol.apiserver.k8s.io/v1alpha1, Resource=flowschemas:FlowSchemaList flowcontrol.apiserver.k8s.io/v1alpha1, Resource=prioritylevelconfigurations:PriorityLevelConfigurationList flowcontrol.apiserver.k8s.io/v1beta1, Resource=flowschemas:FlowSchemaList flowcontrol.apiserver.k8s.io/v1beta1, Resource=prioritylevelconfigurations:PriorityLevelConfigurationList flowcontrol.apiserver.k8s.io/v1beta2, Resource=flowschemas:FlowSchemaList flowcontrol.apiserver.k8s.io/v1beta2, Resource=prioritylevelconfigurations:PriorityLevelConfigurationList gateway.networking.k8s.io/v1beta1, Resource=gatewaies:GatewayList gateway.networking.k8s.io/v1beta1, Resource=gatewayclasses:GatewayClassList gateway.networking.k8s.io/v1beta1, Resource=httproutes:HTTPRouteList internal.apiserver.k8s.io/v1alpha1, Resource=storageversions:StorageVersionList networking.k8s.io/v1, Resource=ingressclasses:IngressClassList networking.k8s.io/v1, Resource=ingresses:IngressList networking.k8s.io/v1, Resource=networkpolicies:NetworkPolicyList networking.k8s.io/v1beta1, Resource=ingressclasses:IngressClassList networking.k8s.io/v1beta1, Resource=ingresses:IngressList node.k8s.io/v1, Resource=runtimeclasses:RuntimeClassList node.k8s.io/v1alpha1, Resource=runtimeclasses:RuntimeClassList node.k8s.io/v1beta1, Resource=runtimeclasses:RuntimeClassList policy/v1, Resource=poddisruptionbudgets:PodDisruptionBudgetList policy/v1beta1, Resource=poddisruptionbudgets:PodDisruptionBudgetList policy/v1beta1, Resource=podsecuritypolicies:PodSecurityPolicyList rbac.authorization.k8s.io/v1, Resource=clusterrolebindings:ClusterRoleBindingList rbac.authorization.k8s.io/v1, Resource=clusterroles:ClusterRoleList rbac.authorization.k8s.io/v1, Resource=rolebindings:RoleBindingList rbac.authorization.k8s.io/v1, Resource=roles:RoleList rbac.authorization.k8s.io/v1alpha1, Resource=clusterrolebindings:ClusterRoleBindingList rbac.authorization.k8s.io/v1alpha1, Resource=clusterroles:ClusterRoleList rbac.authorization.k8s.io/v1alpha1, Resource=rolebindings:RoleBindingList rbac.authorization.k8s.io/v1alpha1, Resource=roles:RoleList rbac.authorization.k8s.io/v1beta1, Resource=clusterrolebindings:ClusterRoleBindingList rbac.authorization.k8s.io/v1beta1, Resource=clusterroles:ClusterRoleList rbac.authorization.k8s.io/v1beta1, Resource=rolebindings:RoleBindingList rbac.authorization.k8s.io/v1beta1, Resource=roles:RoleList scheduling.k8s.io/v1, Resource=priorityclasses:PriorityClassList scheduling.k8s.io/v1alpha1, Resource=priorityclasses:PriorityClassList scheduling.k8s.io/v1beta1, Resource=priorityclasses:PriorityClassList storage.k8s.io/v1, Resource=csidrivers:CSIDriverList storage.k8s.io/v1, Resource=csinodes:CSINodeList storage.k8s.io/v1, Resource=csistoragecapacities:CSIStorageCapacityList storage.k8s.io/v1, Resource=storageclasses:StorageClassList storage.k8s.io/v1, Resource=volumeattachments:VolumeAttachmentList storage.k8s.io/v1alpha1, Resource=csistoragecapacities:CSIStorageCapacityList storage.k8s.io/v1alpha1, Resource=volumeattachments:VolumeAttachmentList storage.k8s.io/v1beta1, Resource=csidrivers:CSIDriverList storage.k8s.io/v1beta1, Resource=csinodes:CSINodeList storage.k8s.io/v1beta1, Resource=csistoragecapacities:CSIStorageCapacityList storage.k8s.io/v1beta1, Resource=storageclasses:StorageClassList storage.k8s.io/v1beta1, Resource=volumeattachments:VolumeAttachmentList]
Resource=gatewaies:GatewayList gateway.networking.k8s.io/v1beta1

from k8s.io/[email protected]/dynamic/fake/simple.go:353.

Any work arounds for this?

pmalek avatar Aug 08 '22 18:08 pmalek

I tried adding a test case in https://github.com/kubernetes/gengo/blob/940203f2dae74b24bb30948aa5a9619ba259d4a5/namer/plural_namer_test.go to verify that this is indeed broken for Gateway/gateway but it doesn't look like that's the case. I've even checked several versions back to verify which version of gengo is being used by https://github.com/kubernetes/code-generator and match that with my cluster's version and that didn't yield a failure.


Ok, got it: https://github.com/kubernetes/kubernetes/pull/110053

pmalek avatar Aug 09 '22 08:08 pmalek

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

This bot triages issues and PRs 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 or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR 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 Nov 07 '22 09:11 k8s-triage-robot

/remove-lifecycle stale

pmalek avatar Nov 07 '22 11:11 pmalek

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

This bot triages issues and PRs 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 or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR 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 Feb 05 '23 11:02 k8s-triage-robot

Still an issue (I'm mostly bumping this because of the problem with Gateway APIs).

/remove-lifecycle stale

pmalek avatar Feb 12 '23 18:02 pmalek

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 May 13 '23 18:05 k8s-triage-robot

There seem to be a potential way forward to fix this. I've posted https://github.com/kubernetes/kubernetes/pull/110053#issuecomment-1585644795 to ensure it's "the right way" and if that's the case I can propose something for everyone to review.

/remove-lifecycle stale

pmalek avatar Jun 11 '23 08:06 pmalek

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 22 '24 07:01 k8s-triage-robot

/remove-lifecycle stale

mrueg avatar Jan 22 '24 07:01 mrueg

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 Apr 21 '24 08:04 k8s-triage-robot

/remove-lifecycle stale

pmalek avatar May 05 '24 15:05 pmalek