|
| 1 | +package b |
| 2 | + |
| 3 | +// DVPreferredMaxLength exercises the linter when configured to prefer DV markers. |
| 4 | +// Fields that carry only DV markers should NOT lint. |
| 5 | +// Fields that are missing markers should lint with a diagnostic citing the k8s:* form. |
| 6 | +type DVPreferredMaxLength struct { |
| 7 | + // +k8s:maxLength=256 |
| 8 | + StringWithDVMaxLength string // satisfied by DV marker — no lint |
| 9 | + |
| 10 | + // +kubebuilder:validation:MaxLength:=128 |
| 11 | + StringWithKubebuilderMaxLength string // kubebuilder marker also satisfies — no lint |
| 12 | + |
| 13 | + StringWithoutMaxLength string // want `field DVPreferredMaxLength.StringWithoutMaxLength must have a maximum length, add k8s:maxLength marker` |
| 14 | + |
| 15 | + // +k8s:maxBytes=512 |
| 16 | + ByteSliceWithDVMaxBytes []byte // satisfied by k8s:maxBytes — no lint |
| 17 | + |
| 18 | + ByteSliceWithoutMax []byte // want `field DVPreferredMaxLength.ByteSliceWithoutMax must have a maximum length, add k8s:maxLength marker` |
| 19 | + |
| 20 | + // +k8s:maxItems=128 |
| 21 | + ArrayWithDVMaxItems []int // satisfied by k8s:maxItems — no lint |
| 22 | + |
| 23 | + // +kubebuilder:validation:MaxItems:=64 |
| 24 | + ArrayWithKubebuilderMaxItems []int // kubebuilder marker also satisfies — no lint |
| 25 | + |
| 26 | + ArrayWithoutMaxItems []int // want `field DVPreferredMaxLength.ArrayWithoutMaxItems must have a maximum items, add k8s:maxItems marker` |
| 27 | + |
| 28 | + // +k8s:maxProperties=64 |
| 29 | + MapWithDVMaxProperties map[string]string // satisfied by k8s:maxProperties — no lint |
| 30 | + |
| 31 | + // +kubebuilder:validation:MaxProperties:=32 |
| 32 | + MapWithKubebuilderMaxProperties map[string]string // kubebuilder marker also satisfies — no lint |
| 33 | + |
| 34 | + MapWithoutMaxProperties map[string]string // want `field DVPreferredMaxLength.MapWithoutMaxProperties must have a maximum properties, add k8s:maxProperties marker` |
| 35 | + |
| 36 | + // Non-string-keyed map — never linted regardless of config. |
| 37 | + MapWithIntKey map[int]string |
| 38 | + |
| 39 | + // +k8s:enum |
| 40 | + DVEnumString string // enum exempts from max-length — no lint |
| 41 | + |
| 42 | + // +kubebuilder:validation:Enum:="A";"B" |
| 43 | + KubebuilderEnumString string // kubebuilder enum also exempts in DV-preferred mode — no lint |
| 44 | + |
| 45 | + // +k8s:format=date-time |
| 46 | + DVDateTimeString string // format exempts from max-length — no lint |
| 47 | + |
| 48 | + // +k8s:format=date |
| 49 | + DVDateString string // format exempts from max-length — no lint |
| 50 | + |
| 51 | + // +k8s:format=duration |
| 52 | + DVDurationString string // format exempts from max-length — no lint |
| 53 | + |
| 54 | + // +kubebuilder:validation:Format:=date-time |
| 55 | + KubebuilderDateTimeString string // kubebuilder format also exempts in DV-preferred mode — no lint |
| 56 | + |
| 57 | + // +kubebuilder:validation:Format:=date |
| 58 | + KubebuilderDateString string // kubebuilder format also exempts in DV-preferred mode — no lint |
| 59 | + |
| 60 | + // +kubebuilder:validation:Format:=duration |
| 61 | + KubebuilderDurationString string // kubebuilder format also exempts in DV-preferred mode — no lint |
| 62 | + |
| 63 | + // +k8s:maxLength=256 on a []byte field is the WRONG DV marker; +k8s:maxBytes should be used. |
| 64 | + // The linter must still report the field as missing a valid max-length constraint. |
| 65 | + // +k8s:maxLength=256 |
| 66 | + ByteSliceWithWrongDVMarker []byte // want `field DVPreferredMaxLength.ByteSliceWithWrongDVMarker must have a maximum length, add k8s:maxLength marker` |
| 67 | + |
| 68 | + // Raw []string — needs both MaxItems and items:MaxLength. |
| 69 | + // +k8s:maxItems=16 |
| 70 | + // +kubebuilder:validation:items:MaxLength:=64 |
| 71 | + StringArrayWithMaxItemsAndElementLength []string // no lint |
| 72 | + |
| 73 | + // +k8s:maxItems=16 |
| 74 | + StringArrayWithMaxItemsWithoutElementLength []string // want `field DVPreferredMaxLength.StringArrayWithMaxItemsWithoutElementLength array element must have a maximum length, add kubebuilder:validation:items:MaxLength` |
| 75 | + |
| 76 | + StringArrayWithoutMaxItemsOrElementLength []string // want `field DVPreferredMaxLength.StringArrayWithoutMaxItemsOrElementLength must have a maximum items, add k8s:maxItems marker` `field DVPreferredMaxLength.StringArrayWithoutMaxItemsOrElementLength array element must have a maximum length, add kubebuilder:validation:items:MaxLength` |
| 77 | +} |
| 78 | + |
| 79 | +// StringAliasDVMaxLength is a string alias carrying a DV maxLength marker. |
| 80 | +// +k8s:maxLength=512 |
| 81 | +type StringAliasDVMaxLength string |
| 82 | + |
| 83 | +// StringAliasNoMaxLength is a string alias without any max-length marker. |
| 84 | +type StringAliasNoMaxLength string |
| 85 | + |
| 86 | +// DVPreferredAliases exercises alias-level DV markers. |
| 87 | +type DVPreferredAliases struct { |
| 88 | + StringWithAliasMaxLength StringAliasDVMaxLength // satisfied by alias marker — no lint |
| 89 | + |
| 90 | + StringWithoutMaxLength StringAliasNoMaxLength // want `field DVPreferredAliases.StringWithoutMaxLength type StringAliasNoMaxLength must have a maximum length, add k8s:maxLength marker` |
| 91 | + |
| 92 | + // +k8s:maxItems=64 |
| 93 | + AliasArrayWithMaxItems []StringAliasDVMaxLength // array element max-length satisfied by alias — no lint |
| 94 | + |
| 95 | + AliasArrayWithoutMaxItems []StringAliasDVMaxLength // want `field DVPreferredAliases.AliasArrayWithoutMaxItems must have a maximum items, add k8s:maxItems marker` |
| 96 | +} |
0 commit comments