@@ -65,6 +65,18 @@ func TestVersionedValidationByFuzzing(t *testing.T) {
6565 {Group : "admissionregistration.k8s.io" , Version : "v1alpha1" },
6666 }
6767
68+ // subresourceOnly specifies the subresource path for types that can only be validated
69+ // as subresources (e.g. autoscaling/Scale) and do not support root-level validation.
70+ // For GVKs not in this map, the test defaults to fuzzing the root resource ("").
71+ // Other resources with subresources (e.g. Pod status, exec) share validation logic with
72+ // the root resource, so fuzzing the root is sufficient to verify validation equivalence.
73+ subresourceOnly := map [schema.GroupVersionKind ]string {
74+ {Group : "autoscaling" , Version : "v1" , Kind : "Scale" }: "scale" ,
75+ {Group : "autoscaling" , Version : "v1beta1" , Kind : "Scale" }: "scale" ,
76+ {Group : "autoscaling" , Version : "v1beta2" , Kind : "Scale" }: "scale" ,
77+ {Group : "autoscaling" , Version : "v2" , Kind : "Scale" }: "scale" ,
78+ }
79+
6880 fuzzIters := * roundtrip .FuzzIters / 10 // TODO: Find a better way to manage test running time
6981 f := fuzzer .FuzzerFor (FuzzerFuncs , rand .NewSource (rand .Int63 ()), legacyscheme .Codecs )
7082
@@ -77,17 +89,21 @@ func TestVersionedValidationByFuzzing(t *testing.T) {
7789 if err != nil {
7890 t .Fatalf ("could not create a %v: %s" , kind , err )
7991 }
80- f .Fill (obj )
92+
93+ subresource := ""
94+ if specific , ok := subresourceOnly [gvk ]; ok {
95+ subresource = specific
96+ }
8197
8298 var opts []ValidationTestConfig
8399 // TODO(API group level configuration): Consider configuring normalization rules at the
84100 // API group level to avoid potential collisions when multiple rule sets are combined.
85101 // This would allow each API group to register its own normalization rules independently.
86102 allRules := append ([]field.NormalizationRule {}, resourcevalidation .ResourceNormalizationRules ... )
87103 allRules = append (allRules , nodevalidation .NodeNormalizationRules ... )
88- opts = append (opts , WithNormalizationRules (allRules ... ))
89- if gv . Group == "autoscaling " {
90- opts = append (opts , WithIgnoreObjectConversionErrors ( ))
104+ opts = append (opts , WithNormalizationRules (allRules ... ), WithFuzzer ( f ) )
105+ if subresource != " " {
106+ opts = append (opts , WithSubResources ( subresource ))
91107 }
92108
93109 VerifyVersionedValidationEquivalence (t , obj , nil , opts ... )
@@ -96,7 +112,7 @@ func TestVersionedValidationByFuzzing(t *testing.T) {
96112 if err != nil {
97113 t .Fatalf ("could not create a %v: %s" , kind , err )
98114 }
99- f . Fill ( old )
115+
100116 VerifyVersionedValidationEquivalence (t , obj , old , opts ... )
101117 }
102118 })
0 commit comments