Azure / azure-service-operator

Azure Service Operator allows you to create Azure resources using kubectl
https://azure.github.io/azure-service-operator/
MIT License
738 stars 194 forks source link

kubectl version priority results in get using older version of resources than it should #4147

Open matthchr opened 3 months ago

matthchr commented 3 months ago

The versioning scheme we use for APIs doesn't comply with well with version priority, which states:

Version priority Regardless of the order in which versions are defined in a CustomResourceDefinition, the version with the highest priority is used by kubectl as the default version to access objects. The priority is determined by parsing the name field to determine the version number, the stability (GA, Beta, or Alpha), and the sequence within that stability level.

The algorithm used for sorting the versions is designed to sort versions in the same way that the Kubernetes project sorts Kubernetes versions. Versions start with a v followed by a number, an optional beta or alpha designation, and optional additional numeric versioning information. Broadly, a version string might look like v2 or v2beta1. Versions are sorted using the following algorithm:

Entries that follow Kubernetes version patterns are sorted before those that do not. For entries that follow Kubernetes version patterns, the numeric portions of the version string is sorted largest to smallest. If the strings beta or alpha follow the first numeric portion, they sorted in that order, after the equivalent string without the beta or alpha suffix (which is presumed to be the GA version).

If another number follows the beta, or alpha, those numbers are also sorted from largest to smallest. Strings that don't fit the above format are sorted alphabetically and the numeric portions are not treated specially. Notice that in the example below, foo1 is sorted above foo10. This is different from the sorting of the numeric portion of entries that do follow the Kubernetes version patterns.

Our APIs are versioned like so: v1api20210201 - GA ASO, GA ARM API v1api20240201 - GA ASO, GA ARM API (newer) v1api20210201preview - GA ASO, Preview ARM API v1beta20210201 - Beta ASO, GA ARM API v1beta20210201preview - Beta ASO, Preview ARM API

According to the Kubernetes version priority ordering, these get ordered:

This ordering results in the following problems:

Workaround users can work around this problem and specify the specific API version they'd like to use when getting the objects, with kubectl get virtualmachines.v1api20220301.compute.azure.com (specifying the APIVersion as part of the get command), but this is annoying.