Skip to content

Commit 72232d3

Browse files
committed
Clarify that resource versions in Kubernetes are now comparable as monotonically increasing integers starting from K8s 1.35
1 parent 0fcc949 commit 72232d3

File tree

1 file changed

+47
-6
lines changed

1 file changed

+47
-6
lines changed

content/en/docs/reference/using-api/api-concepts.md

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,12 +1364,53 @@ However:
13641364
Resource versions are strings that identify the server's internal version of an
13651365
object. Resource versions can be used by clients to determine when objects have
13661366
changed, or to express data consistency requirements when getting, listing and
1367-
watching resources. Resource versions must be treated as opaque by clients and passed
1368-
unmodified back to the server.
1369-
1370-
You must not assume resource versions are numeric or collatable. API clients may
1371-
only compare two resource versions for equality (this means that you must not compare
1372-
resource versions for greater-than or less-than relationships).
1367+
watching resources. Resource versions must be passed unmodified back to the
1368+
server.
1369+
1370+
Resource version strings are orderable as monotonically increasing integers
1371+
within the same resource type for all types served by kube-apiserver. This
1372+
includes built-in API types and types backed by custom resource definitions.
1373+
Both resource versions must be from objects of the same API group and resource
1374+
type. For example, two Deployments from the apps API group can have their
1375+
resource versions compared, but a Pod and a Deployment cannot. Provided that two
1376+
objects are retrieved from the same API resource type, you can compare them even
1377+
if they are in different namespaces.
1378+
1379+
If you are using API resources served by an extension API server, the client
1380+
needs to check whether the resource version string parses as a decimal number
1381+
(there are more details on that in the next few paragraphs). If either of two
1382+
resource version strings does not parse as a decimal number, the two strings can
1383+
be checked for equality but you **cannot** rely on comparisons for ordering.
1384+
1385+
Starting with Kubernetes 1.35, orderability of resource versions for all
1386+
Kubernetes types is included in [Certified
1387+
Kubernetes](https://www.cncf.io/training/certification/software-conformance/)
1388+
requirements. Base API objects and custom resources **must** be orderable as a
1389+
monotonically increasing integer for any 1.35+ APIServer implementation in order
1390+
to pass conformance tests.
1391+
1392+
In order to compare two resource version strings:
1393+
1394+
Ensure they meet the following requirements:
1395+
* Both resource versions must be from the same resource type as described above
1396+
* Both must start with a digit 1-9 and contain only digits 0-9
1397+
* Resource versions are compared as arbitrary bitsize decimal integers
1398+
1399+
To compare them without relying on a fixed bitsize one can compare them as
1400+
strings. The bitsize must not be assumed to be some fixed amount.
1401+
1402+
A lexicographical comparison can be used instead as shown here:
1403+
* If they are not of equal length, the longer one is greater (for example, "123" > "23")
1404+
* If they are of equal length, the lexicographically greater one is greater (for example, "234" > "123")
1405+
1406+
Some examples of resource version comparisons that should work:
1407+
* "2345678901234567890123456789012345678901" > "345678901234567890123456789012345678901"
1408+
* "345678901234567890123456789012345678901" == "345678901234567890123456789012345678901"
1409+
* "345678901234567890123456789012345678900" < "345678901234567890123456789012345678901"
1410+
1411+
A helper method is available for
1412+
[client-go](https://pkg.go.dev/k8s.io/apimachinery/pkg/util/resourceversion#CompareResourceVersion)
1413+
to perform this comparison.
13731414

13741415
### `resourceVersion` fields in metadata {#resourceversion-in-metadata}
13751416

0 commit comments

Comments
 (0)