@@ -266,15 +266,24 @@ func (a *analyzer) needsStringMaxLength(markerSet markershelper.MarkerSet) bool
266266 return true
267267}
268268
269- // needsByteSliceMaxLength is like needsStringMaxLength but also accepts +k8s:maxBytes,
270- // which is the DV-correct marker for byte-length constraints on []byte fields.
271- // (+k8s:maxLength counts Unicode characters; +k8s:maxBytes counts raw bytes.)
269+ // needsByteSliceMaxLength is like needsStringMaxLength but enforces that for DV markers,
270+ // +k8s:maxBytes is used instead of +k8s:maxLength (which counts characters).
272271func (a * analyzer ) needsByteSliceMaxLength (markerSet markershelper.MarkerSet ) bool {
273- if markerSet .Has (markers .K8sMaxBytesMarker ) {
272+ switch {
273+ case markerSet .Has (markers .KubebuilderMaxLengthMarker ),
274+ markerSet .Has (markers .K8sMaxBytesMarker ),
275+ markerSet .Has (markers .KubebuilderEnumMarker ),
276+ markerSet .Has (markers .K8sEnumMarker ),
277+ markerSet .HasWithValue (kubebuilderFormatWithValue ("date" )),
278+ markerSet .HasWithValue (kubebuilderFormatWithValue ("date-time" )),
279+ markerSet .HasWithValue (kubebuilderFormatWithValue ("duration" )),
280+ markerSet .HasWithValue (k8sFormatWithValue ("date" )),
281+ markerSet .HasWithValue (k8sFormatWithValue ("date-time" )),
282+ markerSet .HasWithValue (k8sFormatWithValue ("duration" )):
274283 return false
275284 }
276285
277- return a . needsStringMaxLength ( markerSet )
286+ return true
278287}
279288
280289func (a * analyzer ) needsItemsMaxLength (markerSet markershelper.MarkerSet ) bool {
@@ -299,5 +308,5 @@ func kubebuilderItemsFormatWithValue(value string) string {
299308}
300309
301310func k8sFormatWithValue (value string ) string {
302- return fmt .Sprintf ("%s: =%s" , markers .K8sFormatMarker , value )
311+ return fmt .Sprintf ("%s=%s" , markers .K8sFormatMarker , value )
303312}
0 commit comments