Skip to content
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

wip: crd: require unique hosts #37

Closed
wants to merge 1 commit into from
Closed

Conversation

AlexanderYastrebov
Copy link
Collaborator

@AlexanderYastrebov AlexanderYastrebov commented Mar 26, 2024

CRD does not support uniqueItems: true validation:

The CustomResourceDefinition "routegroups.zalando.org" is invalid:
spec.validation.openAPIV3Schema.properties[spec].properties[hosts].uniqueItems:
Forbidden: uniqueItems cannot be set to true since the runtime complexity becomes quadratic

This change adds validation rule
to enforce unique hosts.

It also adds maxItems limit to overcome rule cost error:

The CustomResourceDefinition "routegroups.zalando.org" is invalid:
* spec.validation.openAPIV3Schema.properties[spec].properties[hosts].x-kubernetes-validations[0].rule: Forbidden: estimated rule cost exceeds budget by factor of more than 100x (try simplifying the rule, or adding maxItems, maxProperties, and maxLength where arrays, maps, and strings are declared)
* spec.validation.openAPIV3Schema.properties[spec].properties[hosts].x-kubernetes-validations[0].rule: Forbidden: contributed to estimated rule cost total exceeding cost limit for entire OpenAPIv3 schema
* spec.validation.openAPIV3Schema: Forbidden: x-kubernetes-validations estimated rule cost total for entire OpenAPIv3 schema exceeds budget by factor of more than 100x (try simplifying the rule, or adding maxItems, maxProperties, and maxLength where arrays, maps, and strings are declared)

Note that validation rule is not added to tls spec because then rule cost error re-appears apparently due to exceeding total allowed schema cost.

Example validation error:

Error from server (Invalid): error when creating "rg.yaml": RouteGroup.zalando.org "duplicate-hosts" is invalid: spec.hosts: Invalid value: "array": hosts must be unique

CRD does not support `uniqueItems: true` validation:
```
The CustomResourceDefinition "routegroups.zalando.org" is invalid:
spec.validation.openAPIV3Schema.properties[spec].properties[hosts].uniqueItems:
Forbidden: uniqueItems cannot be set to true since the runtime complexity becomes quadratic
```

This change adds [validation rule](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#validation-rules)
to enforce unique hosts.

It also adds maxItems limit to overcome rule cost error:
```
The CustomResourceDefinition "routegroups.zalando.org" is invalid:
* spec.validation.openAPIV3Schema.properties[spec].properties[hosts].x-kubernetes-validations[0].rule: Forbidden: estimated rule cost exceeds budget by factor of more than 100x (try simplifying the rule, or adding maxItems, maxProperties, and maxLength where arrays, maps, and strings are declared)
* spec.validation.openAPIV3Schema.properties[spec].properties[hosts].x-kubernetes-validations[0].rule: Forbidden: contributed to estimated rule cost total exceeding cost limit for entire OpenAPIv3 schema
* spec.validation.openAPIV3Schema: Forbidden: x-kubernetes-validations estimated rule cost total for entire OpenAPIv3 schema exceeds budget by factor of more than 100x (try simplifying the rule, or adding maxItems, maxProperties, and maxLength where arrays, maps, and strings are declared)
```

Note that validation rule is not added to `tls` spec because then rule cost error re-appears apparently due to exceeding total allowed schema cost.

Example validation error:
```
Error from server (Invalid): error when creating "rg.yaml": RouteGroup.zalando.org "duplicate-hosts" is invalid: spec.hosts: Invalid value: "array": hosts must be unique
```

Signed-off-by: Alexander Yastrebov <[email protected]>
@AlexanderYastrebov
Copy link
Collaborator Author

See #41

@AlexanderYastrebov AlexanderYastrebov deleted the crd-unique-hosts branch March 27, 2024 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant