mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 06:54:01 +00:00
allow apigroups to opt out of proto round trip testing
This commit is contained in:
parent
04437f6403
commit
d9cc8119ef
@ -33,12 +33,18 @@ import (
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/runtime/serializer/protobuf"
|
||||
"k8s.io/kubernetes/pkg/util/diff"
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
)
|
||||
|
||||
var nonProtobaleAPIGroups = sets.NewString()
|
||||
|
||||
func init() {
|
||||
codecsToTest = append(codecsToTest, func(version unversioned.GroupVersion, item runtime.Object) (runtime.Codec, error) {
|
||||
codecsToTest = append(codecsToTest, func(version unversioned.GroupVersion, item runtime.Object) (runtime.Codec, bool, error) {
|
||||
if nonProtobaleAPIGroups.Has(version.Group) {
|
||||
return nil, false, nil
|
||||
}
|
||||
s := protobuf.NewSerializer(api.Scheme, api.Scheme, "application/arbitrary.content.type")
|
||||
return api.Codecs.CodecForVersions(s, s, testapi.ExternalGroupVersions(), nil), nil
|
||||
return api.Codecs.CodecForVersions(s, s, testapi.ExternalGroupVersions(), nil), true, nil
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -51,9 +51,10 @@ import (
|
||||
|
||||
var fuzzIters = flag.Int("fuzz-iters", 20, "How many fuzzing iterations to do.")
|
||||
|
||||
var codecsToTest = []func(version unversioned.GroupVersion, item runtime.Object) (runtime.Codec, error){
|
||||
func(version unversioned.GroupVersion, item runtime.Object) (runtime.Codec, error) {
|
||||
return testapi.GetCodecForObject(item)
|
||||
var codecsToTest = []func(version unversioned.GroupVersion, item runtime.Object) (runtime.Codec, bool, error){
|
||||
func(version unversioned.GroupVersion, item runtime.Object) (runtime.Codec, bool, error) {
|
||||
c, err := testapi.GetCodecForObject(item)
|
||||
return c, true, err
|
||||
},
|
||||
}
|
||||
|
||||
@ -135,11 +136,14 @@ func roundTripSame(t *testing.T, group testapi.TestGroup, item runtime.Object, e
|
||||
version := *group.GroupVersion()
|
||||
codecs := []runtime.Codec{}
|
||||
for _, fn := range codecsToTest {
|
||||
codec, err := fn(version, item)
|
||||
codec, ok, err := fn(version, item)
|
||||
if err != nil {
|
||||
t.Errorf("unable to get codec: %v", err)
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
codecs = append(codecs, codec)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user