What do you want to happen?
@thockin had mentioned to me earlier that using CEL is problematic because of cost limits on name field:
// +kubebuilder:validation:XValidation:rule="!format.dns1123Label().validate(self.metadata.name).hasValue()",message="must be a valid DNS label"
Which let me to wonder a few things:
- Why not just set
format: k8s-short-name in the CRD declaration via Kubebuilder?
- Reason 1.1: I don't know how to put JSON Schema validation on CRDs using
+kubebuilder tags (it's possible in YAML, see below)
- Why not just put a
maxLength: 63 on metadata.name and then use the CEL format.dns1123Label() validation?
- Reason 2.1: Same as reason 1.1
- Why isn't CEL smart enough to know that the name field has a bounded length?
Is anyone aware of solutions that work well today? Is there appetite for PRs to add kubebuilder support for JSON Schema metadata.name validation in Kubebuilder or is CEL the answer? If there is appetite, any recommendations for the +kubebuilder tag representation?
CRD support for metdata.name (and generateName) validation:
CRD schemas allow the name and generateName field to be validated directly using JSON Schema:
For example:
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: ...
spec:
group: ...
versions:
- name: v1
# ...
schema:
openAPIV3Schema:
type: object
properties:
metadata:
type: object
properties:
name:
type: string
pattern: "^required-prefix.*" # metadata.name validation
maxLength: 40 # metadata.name validation
What do you want to happen?
@thockin had mentioned to me earlier that using CEL is problematic because of cost limits on name field:
// +kubebuilder:validation:XValidation:rule="!format.dns1123Label().validate(self.metadata.name).hasValue()",message="must be a valid DNS label"Which let me to wonder a few things:
format: k8s-short-namein the CRD declaration via Kubebuilder?+kubebuildertags (it's possible in YAML, see below)maxLength: 63on metadata.name and then use the CELformat.dns1123Label()validation?Is anyone aware of solutions that work well today? Is there appetite for PRs to add kubebuilder support for JSON Schema metadata.name validation in Kubebuilder or is CEL the answer? If there is appetite, any recommendations for the
+kubebuildertag representation?CRD support for metdata.name (and generateName) validation:
CRD schemas allow the name and generateName field to be validated directly using JSON Schema:
For example: