-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(crd-generator): Ensure deterministic ordering of CRD versions #5784
Conversation
…t v1beta1 CRDVersion
The implementation uses a method from KubernetesVersionPriority to sort the versions by priority. The version with the highest priority comes first. This ensures deterministic generation und should fix fabric8io#5508.
Quality Gate failedFailed conditions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
* The kubernetes specs v1.17 at <a href= | ||
* "https://v1-17.docs.kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definition-versioning/#version-priority">Version | ||
* The kubernetes specs v1.28 at <a href= | ||
* "https://v1-28.docs.kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/#version-priority">Version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, do we really need to have version in the documentation? I checked https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/#version-priority
also works okay
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thx!
Description
If multiple versions of a CustomResource exist, the result of CRD generation is not deterministic. While this doesn't change the behaviour of Kubernetes, since the version order does not matter, it causes unnecessary changes if checked into git or applied to the cluster.
This PR resolves this issue by sorting the versions based on priority.
The implementation adds a decorator to the CRDGenerator which is configured to run late in the handler chain after all versions has been added. The decorator sorts the versions by priority so that the version with the highest priority comes first.
To be able to reuse existing functionality regarding sorting by priority and to keep the internal Version class package-private, a new method has been added to KubernetesVersionPriority.
The method allows creating a new sorted list by providing a generic list of objects and a version provider function.
Fixes #5508
Type of change
test, version modification, documentation, etc.)
Checklist