k8s.io/apiserver: add example api group
This commit is contained in:
@@ -35,17 +35,19 @@ import (
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/api/v1"
|
||||
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
||||
"k8s.io/kubernetes/pkg/apis/batch"
|
||||
"k8s.io/kubernetes/pkg/apis/certificates"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
extensionsv1beta1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
|
||||
"k8s.io/kubernetes/pkg/apis/policy"
|
||||
"k8s.io/kubernetes/pkg/apis/rbac"
|
||||
)
|
||||
|
||||
// overrideGenericFuncs override some generic fuzzer funcs from k8s.io/apiserver in order to have more realistic
|
||||
// values in a Kubernetes context.
|
||||
func overrideGenericFuncs(t apitesting.TestingCommon) []interface{} {
|
||||
func overrideGenericFuncs(t apitesting.TestingCommon, codecs runtimeserializer.CodecFactory) []interface{} {
|
||||
return []interface{}{
|
||||
func(j *runtime.Object, c fuzz.Continue) {
|
||||
// TODO: uncomment when round trip starts from a versioned object
|
||||
@@ -68,20 +70,12 @@ func overrideGenericFuncs(t apitesting.TestingCommon) []interface{} {
|
||||
obj := types[c.Rand.Intn(len(types))]
|
||||
c.Fuzz(obj)
|
||||
|
||||
// Find a codec for converting the object to raw bytes. This is necessary for the
|
||||
// api version and kind to be correctly set be serialization.
|
||||
var codec runtime.Codec
|
||||
switch obj.(type) {
|
||||
case *api.Pod:
|
||||
codec = testapi.Default.Codec()
|
||||
case *extensions.Deployment:
|
||||
codec = testapi.Extensions.Codec()
|
||||
case *api.Service:
|
||||
codec = testapi.Default.Codec()
|
||||
codec = apitesting.TestCodec(codecs, extensionsv1beta1.SchemeGroupVersion)
|
||||
default:
|
||||
|
||||
t.Errorf("Failed to find codec for object type: %T", obj)
|
||||
return
|
||||
codec = apitesting.TestCodec(codecs, v1.SchemeGroupVersion)
|
||||
}
|
||||
|
||||
// Convert the object to raw bytes
|
||||
@@ -604,9 +598,9 @@ func certificateFuncs(t apitesting.TestingCommon) []interface{} {
|
||||
}
|
||||
|
||||
func FuzzerFuncs(t apitesting.TestingCommon, codecs runtimeserializer.CodecFactory) []interface{} {
|
||||
return mergeFuncLists(t,
|
||||
return apitesting.MergeFuzzerFuncs(t,
|
||||
apitesting.GenericFuzzerFuncs(t, codecs),
|
||||
overrideGenericFuncs(t),
|
||||
overrideGenericFuncs(t, codecs),
|
||||
coreFuncs(t),
|
||||
extensionFuncs(t),
|
||||
batchFuncs(t),
|
||||
@@ -623,25 +617,3 @@ func newBool(val bool) *bool {
|
||||
*p = val
|
||||
return p
|
||||
}
|
||||
|
||||
// mergeFuncLists will merge the given funcLists, overriding early funcs with later ones if there first
|
||||
// argument has the same type.
|
||||
func mergeFuncLists(t apitesting.TestingCommon, funcLists ...[]interface{}) []interface{} {
|
||||
funcMap := map[string]interface{}{}
|
||||
for _, list := range funcLists {
|
||||
for _, f := range list {
|
||||
fT := reflect.TypeOf(f)
|
||||
if fT.Kind() != reflect.Func || fT.NumIn() != 2 {
|
||||
t.Errorf("Fuzzer func with invalid type: %v", fT)
|
||||
continue
|
||||
}
|
||||
funcMap[fT.In(0).String()] = f
|
||||
}
|
||||
}
|
||||
|
||||
result := []interface{}{}
|
||||
for _, f := range funcMap {
|
||||
result = append(result, f)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
Reference in New Issue
Block a user