kubernetes: NewGVKParser fails when an aggregated api server encounters types of same name but different version
What happened:
Attempting to create a new GVKParser fails with
duplicate entry for /v1, Kind=APIResourceList
Upon looking at the output of /openapi/v2 I see that the OpenAPIDoc has an entry for both "io.k8s.apimachinery.pkg.apis.meta.v1.APIResourceList" and "io.k8s.apimachinery.pkg.apis.meta.v1.APIResourceList_v2".
The only difference between them is the link to the documentation in the description of “apiVersion” property. The only reference to _v2 is from "/apis/metrics.k8s.io/v1beta1/" meaning the metrics server is on a different version of kubernetes than the kube-apiserver.
Anything else we need to know?:
When the kube-aggregator aggregates the openAPI from it’s subcomponents, it sometimes encounters two types that have the same name and different definitions. It resolves this by appending _v2, etc to the second definition, which resolves the issue for the openAPI doc, but then the GVKParser does nothing to disambiguate these gvks and will fail if NewGVKParser is ever called.
What do you expect to happen?:
Not completely sure. Nothing is behaving incorrectly in kubernetes and it is almost certainly a bug that GKE is running it’s metrics server (and maybe others) on a different version of k8s than the kubeapi server, but it still seems like a massive footgun for the aggregated api-server to successfully aggregate servers that serve the same kind with different definitions (by renaming the definition) but not giving the GVKParser any way to disambiguate them.
Possible solutions could involve modifying the GVKParser to use a wrapper around GVK and a reference to the server it came from or something (instead of just the GVK).
How to reproduce it (as minimally and precisely as possible):
Given a valid kubeconfig:
dc := discovery.NewDiscoveryClientForConfigOrDie(config)
doc, err := dc.OpenAPISchema()
models, err := proto.NewOpenAPIData(doc)
gvkParser, err := fieldmanager.NewGVKParser(models, false)
if err != nil {
panic(err) // this will panic with `duplicate entry for /v1, Kind=APIResourceList`
}
Environment:
- Kubernetes version (use
kubectl version): 1.20.6-gke.1000 - Cloud provider or hardware configuration: GKE
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (11 by maintainers)
Yeah, and even if an aggregated apiserver has that condition, we probably shouldn’t break the world.
note that the _v2 objects show up even when there’s no aggregated server… this is a bug internal to kube-apiserver tracked in https://github.com/kubernetes/kubernetes/issues/109275