docs: Marker docs about required fields are not fully accurate #3675
Labels
kind/bug
Categorizes issue or PR as related to a bug.
kind/documentation
Categorizes issue or PR as related to documentation.
What broke? What's expected?
In CRD validation documentation (https://book.kubebuilder.io/reference/markers/crd-validation)
//+kubebuilder:validation:Required
marker is advertised as "specifies that this field is required".However, it seems for a struct field, empty struct in a YAML manifest (i.e.
{}
) or for a string field empty string""
bypasses this check.I think it's somewhat misleading that this validation allows zero values (which the
omitempty
would've omitted) through just fine.Reproducing this issue
//+kubebuilder:validation:Required
",omitempty"
on a string field.kubectl apply --validate=false
your custom resource without specifying the field → observe the validation error""
as the value for the string field and re-apply → no error.KubeBuilder (CLI) Version
3.10.0
PROJECT version
3
Plugin versions
go.kubebuilder.io/v4
Other versions
sigs.k8s.io/controller-runtime v0.16.2
kube-apiserver 1.21.14
kubectl 1.21.14
Extra Labels
/kind documentation
The text was updated successfully, but these errors were encountered: