preprocess_spec.py: Add conditional for crd_mode or metadata without $ref key
erikgb opened this issue · comments
It seems like the api-server returns an invalid CRD List type, as commented here: kubernetes-client/java#921 (comment). As a result, the API specification returned by the api-server for a CRD List type may look like this (extract):
{
"metadata": {
"description": "ListMeta describes metadata that synthetic resources must have, including lists and various status objects. A resource may have only one of {ObjectMeta, ListMeta}.",
"type": "object",
"properties": {
"continue": {
"description": "continue may be set if the user set a limit on the number of items returned, and indicates that the server has more data available. The value is opaque and may be used to issue another request to the endpoint that served this list to retrieve the next set of available objects. Continuing a consistent list may not be possible if the server configuration has changed or more than a few minutes have passed. The resourceVersion field returned when using this continue value will be identical to the value in the first response, unless you have received this token from an error message.",
"type": "string"
},
"remainingItemCount": {
"description": "remainingItemCount is the number of subsequent items in the list which are not included in this list response. If the list request contained label or field selectors, then the number of remaining items is unknown and the field will be left unset and omitted during serialization. If the list is complete (either because it is not chunking or because this is the last chunk), then there are no more remaining items and this field will be left unset and omitted during serialization. Servers older than v1.15 do not set this field. The intended use of the remainingItemCount is *estimating* the size of a collection. Clients should not rely on the remainingItemCount to be set or to be exact.",
"type": "integer",
"format": "int64"
},
"resourceVersion": {
"description": "String that identifies the server's internal version of this object that can be used by clients to determine when objects have changed. Value must be treated as opaque by clients and passed unmodified back to the server. Populated by the system. Read-only. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency",
"type": "string"
},
"selfLink": {
"description": "selfLink is a URL representing this object. Populated by the system. Read-only.\n\nDEPRECATED Kubernetes will stop propagating this field in 1.20 release and the field is planned to be removed in 1.21 release.",
"type": "string"
}
}
}
}
instead of the usual:
{
"metadata": {
"$ref": "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ListMeta"
}
}
This was compensated for in deac82e, but d5a4e0d introduces a change that breaks the crd_mode. It works with the previous commit.
I think this is the problematic line:
gen/openapi/preprocess_spec.py
Line 396 in d5a4e0d
Which results in the following error running preprocess_spec.py
in crd_mode:
if v["properties"]["metadata"]["$ref"] == "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ListMeta":
KeyError: '$ref'
We'd be happy to take a PR with a fix for this, or we'll get to it eventually.
i'm sending a workaround to fix the script, on the other hand there's a fix proposed in the upstream kubernetes/kubernetes#92546