gateway-api
gateway-api copied to clipboard
Investigate if CEL can validate that a list is sorted alphabetically
What happened:
In #2461 we added a SupportedFeatures list to GatewayClass status. The spec requires that to be sorted alphabetically, but ideally we could also validate that with CEL. At first glance this appears to be impossible, but it would be good to get a more authoritative answer.
What you expected to happen: Validation to enforce that this field is in alphabetical order.
cc @alexzielenski @cici37 @TristonianJones
@robscott you would need to introduce custom functions to check sortedness, as CEL doesn't currently support this feature. It can definitely be done, especially if we supported index, value style comprehensions in CEL.
values.range(idx, v, idx == 0 || values[idx-1] <= v)
Thanks @TristonianJones! Are there any plans to support index, value style comprehensions in CEL? Do you happen to know if CRD authors have the flexibility to define custom functions or if those can only be added via upstream Kubernetes changes?
This issue has not been updated in over 1 year, and should be re-triaged.
You can:
- Confirm that this issue is still relevant with
/triage accepted(org members only) - Close this issue with
/close
For more details on the triage process, see https://www.kubernetes.dev/docs/guide/issue-triage/
/remove-triage accepted
@robscott CEL just added support for two variable comprehensions. I'll cut a release once in back from vacation, but they're in HEAD now
Very cool, thanks for the update @TristonianJones! Looking forward to seeing this in k8s.
/triage accepted
This issue has not been updated in over 1 year, and should be re-triaged.
You can:
- Confirm that this issue is still relevant with
/triage accepted(org members only) - Close this issue with
/close
For more details on the triage process, see https://www.kubernetes.dev/docs/guide/issue-triage/
/remove-triage accepted
Kubernetes library has the isSorted for lists: https://kubernetes.io/docs/reference/using-api/cel/#kubernetes-list-library
I have tested here against an array field and worked like :chefkiss:
// +kubebuilder:validation:XValidation:message="should be sorted alphabetically",rule="self.isSorted()"
Features []Feature `json:"features,omitempty"`
Once applying, VAP blocks unordered features.
@robscott I am worried this may be some breaking change on the API if we decide to apply it to status, but otherwise we can move with it :)