kubernetes / client-go

Go client for Kubernetes.
Apache License 2.0
9.08k stars 2.95k forks source link

Pluralization discrepancy in UnsafeGuessKindToResource still exists #1082

Open Limorerez opened 2 years ago

Limorerez commented 2 years ago

Expected:

gateway-> gateways Got: gateway-> gatewaies

Is there any way to affect this mistaken guessing?

AlexanderYastrebov commented 2 years ago

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 commented 2 years ago

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

pmalek commented 2 years ago

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/client-go@v0.24.3/dynamic/fake/simple.go:353.

Any work arounds for this?

pmalek commented 2 years ago

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

k8s-triage-robot commented 2 years ago

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:

You can:

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

/lifecycle stale

pmalek commented 2 years ago

/remove-lifecycle stale

k8s-triage-robot commented 1 year ago

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:

You can:

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

/lifecycle stale

pmalek commented 1 year ago

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

/remove-lifecycle stale

k8s-triage-robot commented 1 year ago

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

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

You can:

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

/lifecycle stale

pmalek commented 1 year ago

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

k8s-triage-robot commented 9 months ago

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

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

You can:

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

/lifecycle stale

mrueg commented 9 months ago

/remove-lifecycle stale

k8s-triage-robot commented 6 months ago

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

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

You can:

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

/lifecycle stale

pmalek commented 6 months ago

/remove-lifecycle stale

k8s-triage-robot commented 3 months ago

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

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

You can:

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

/lifecycle stale

mjnovice commented 3 months ago

any updates ?

k8s-triage-robot commented 2 months ago

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:

You can:

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

/lifecycle rotten

k8s-triage-robot commented 1 month ago

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:

You can:

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

/close not-planned

k8s-ci-robot commented 1 month ago

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

In response to [this](https://github.com/kubernetes/client-go/issues/1082#issuecomment-2401016397): >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][1] > >Please send feedback to sig-contributor-experience at [kubernetes/community](https://github.com/kubernetes/community). > >/close not-planned > >[1]: https://www.kubernetes.dev/docs/guide/issue-triage/ Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
pmalek commented 1 month ago

/reopen /remove-lifecycle rotten

k8s-ci-robot commented 1 month ago

@pmalek: Reopened this issue.

In response to [this](https://github.com/kubernetes/client-go/issues/1082#issuecomment-2401499374): >/reopen >/remove-lifecycle rotten Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.