2015-01-29 00:57:33 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2015 The Kubernetes Authors All rights reserved.
|
2015-01-29 00:57:33 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package testing
|
|
|
|
|
|
|
|
import (
|
2015-09-01 09:48:53 +00:00
|
|
|
"fmt"
|
2015-01-29 00:57:33 +00:00
|
|
|
"math/rand"
|
2015-04-20 23:29:26 +00:00
|
|
|
"reflect"
|
2015-01-29 00:57:33 +00:00
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
|
2015-08-05 22:05:17 +00:00
|
|
|
docker "github.com/fsouza/go-dockerclient"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
|
|
|
"k8s.io/kubernetes/pkg/api/resource"
|
2015-12-19 05:08:34 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api/testapi"
|
2015-09-09 21:59:11 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
2015-10-09 22:04:41 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/fields"
|
|
|
|
"k8s.io/kubernetes/pkg/labels"
|
|
|
|
"k8s.io/kubernetes/pkg/runtime"
|
|
|
|
"k8s.io/kubernetes/pkg/types"
|
2015-11-10 06:28:45 +00:00
|
|
|
"k8s.io/kubernetes/pkg/util/intstr"
|
2015-03-20 20:50:06 +00:00
|
|
|
|
2015-07-23 04:52:05 +00:00
|
|
|
"github.com/google/gofuzz"
|
2015-01-29 00:57:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// FuzzerFor can randomly populate api objects that are destined for version.
|
2015-12-17 21:20:22 +00:00
|
|
|
func FuzzerFor(t *testing.T, version unversioned.GroupVersion, src rand.Source) *fuzz.Fuzzer {
|
2015-01-29 00:57:33 +00:00
|
|
|
f := fuzz.New().NilChance(.5).NumElements(1, 1)
|
|
|
|
if src != nil {
|
|
|
|
f.RandSource(src)
|
|
|
|
}
|
|
|
|
f.Funcs(
|
2015-11-18 18:24:54 +00:00
|
|
|
func(j *int, c fuzz.Continue) {
|
|
|
|
*j = int(c.Int31())
|
|
|
|
},
|
|
|
|
func(j **int, c fuzz.Continue) {
|
|
|
|
if c.RandBool() {
|
|
|
|
i := int(c.Int31())
|
|
|
|
*j = &i
|
|
|
|
} else {
|
|
|
|
*j = nil
|
|
|
|
}
|
|
|
|
},
|
2016-01-07 22:55:19 +00:00
|
|
|
func(q *resource.Quantity, c fuzz.Continue) {
|
|
|
|
*q = *resource.NewQuantity(c.Int63n(1000), resource.DecimalExponent)
|
|
|
|
},
|
2015-01-29 00:57:33 +00:00
|
|
|
func(j *runtime.TypeMeta, c fuzz.Continue) {
|
|
|
|
// We have to customize the randomization of TypeMetas because their
|
|
|
|
// APIVersion and Kind must remain blank in memory.
|
|
|
|
j.APIVersion = ""
|
|
|
|
j.Kind = ""
|
|
|
|
},
|
2015-09-09 21:59:11 +00:00
|
|
|
func(j *unversioned.TypeMeta, c fuzz.Continue) {
|
2015-01-29 00:57:33 +00:00
|
|
|
// We have to customize the randomization of TypeMetas because their
|
|
|
|
// APIVersion and Kind must remain blank in memory.
|
|
|
|
j.APIVersion = ""
|
|
|
|
j.Kind = ""
|
|
|
|
},
|
|
|
|
func(j *api.ObjectMeta, c fuzz.Continue) {
|
|
|
|
j.Name = c.RandString()
|
|
|
|
j.ResourceVersion = strconv.FormatUint(c.RandUint64(), 10)
|
|
|
|
j.SelfLink = c.RandString()
|
2015-01-28 04:50:01 +00:00
|
|
|
j.UID = types.UID(c.RandString())
|
|
|
|
j.GenerateName = c.RandString()
|
2015-01-29 00:57:33 +00:00
|
|
|
|
|
|
|
var sec, nsec int64
|
|
|
|
c.Fuzz(&sec)
|
|
|
|
c.Fuzz(&nsec)
|
2015-09-17 22:21:55 +00:00
|
|
|
j.CreationTimestamp = unversioned.Unix(sec, nsec).Rfc3339Copy()
|
2015-01-29 00:57:33 +00:00
|
|
|
},
|
|
|
|
func(j *api.ObjectReference, c fuzz.Continue) {
|
|
|
|
// We have to customize the randomization of TypeMetas because their
|
|
|
|
// APIVersion and Kind must remain blank in memory.
|
|
|
|
j.APIVersion = c.RandString()
|
|
|
|
j.Kind = c.RandString()
|
|
|
|
j.Namespace = c.RandString()
|
|
|
|
j.Name = c.RandString()
|
|
|
|
j.ResourceVersion = strconv.FormatUint(c.RandUint64(), 10)
|
|
|
|
j.FieldPath = c.RandString()
|
|
|
|
},
|
2015-09-09 21:59:11 +00:00
|
|
|
func(j *unversioned.ListMeta, c fuzz.Continue) {
|
2015-01-29 00:57:33 +00:00
|
|
|
j.ResourceVersion = strconv.FormatUint(c.RandUint64(), 10)
|
|
|
|
j.SelfLink = c.RandString()
|
|
|
|
},
|
2015-12-10 09:39:03 +00:00
|
|
|
func(j *api.ListOptions, c fuzz.Continue) {
|
|
|
|
label, _ := labels.Parse("a=b")
|
|
|
|
j.LabelSelector = label
|
|
|
|
field, _ := fields.ParseSelector("a=b")
|
|
|
|
j.FieldSelector = field
|
|
|
|
},
|
2015-11-10 08:51:47 +00:00
|
|
|
func(j *api.PodExecOptions, c fuzz.Continue) {
|
|
|
|
j.Stdout = true
|
|
|
|
j.Stderr = true
|
|
|
|
},
|
|
|
|
func(j *api.PodAttachOptions, c fuzz.Continue) {
|
|
|
|
j.Stdout = true
|
|
|
|
j.Stderr = true
|
|
|
|
},
|
2015-09-14 21:56:51 +00:00
|
|
|
func(s *api.PodSpec, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(s)
|
2015-08-19 23:59:43 +00:00
|
|
|
// has a default value
|
|
|
|
ttl := int64(30)
|
|
|
|
if c.RandBool() {
|
|
|
|
ttl = int64(c.Uint32())
|
|
|
|
}
|
2015-09-14 21:56:51 +00:00
|
|
|
s.TerminationGracePeriodSeconds = &ttl
|
|
|
|
|
2015-10-20 18:03:32 +00:00
|
|
|
c.Fuzz(s.SecurityContext)
|
|
|
|
|
2015-09-14 21:56:51 +00:00
|
|
|
if s.SecurityContext == nil {
|
2015-10-20 18:03:32 +00:00
|
|
|
s.SecurityContext = new(api.PodSecurityContext)
|
2015-09-14 21:56:51 +00:00
|
|
|
}
|
2015-08-19 23:59:43 +00:00
|
|
|
},
|
2015-01-29 00:57:33 +00:00
|
|
|
func(j *api.PodPhase, c fuzz.Continue) {
|
|
|
|
statuses := []api.PodPhase{api.PodPending, api.PodRunning, api.PodFailed, api.PodUnknown}
|
|
|
|
*j = statuses[c.Rand.Intn(len(statuses))]
|
|
|
|
},
|
2015-03-04 20:55:41 +00:00
|
|
|
func(j *api.Binding, c fuzz.Continue) {
|
|
|
|
c.Fuzz(&j.ObjectMeta)
|
|
|
|
j.Target.Name = c.RandString()
|
|
|
|
},
|
2015-01-29 00:57:33 +00:00
|
|
|
func(j *api.ReplicationControllerSpec, c fuzz.Continue) {
|
2015-05-28 23:29:06 +00:00
|
|
|
c.FuzzNoCustom(j) // fuzz self without calling this function again
|
|
|
|
//j.TemplateRef = nil // this is required for round trip
|
2015-01-29 00:57:33 +00:00
|
|
|
},
|
2015-10-09 22:49:10 +00:00
|
|
|
func(j *extensions.DeploymentStrategy, c fuzz.Continue) {
|
2015-07-25 19:08:34 +00:00
|
|
|
c.FuzzNoCustom(j) // fuzz self without calling this function again
|
2015-09-01 09:48:53 +00:00
|
|
|
// Ensure that strategyType is one of valid values.
|
2015-10-09 22:49:10 +00:00
|
|
|
strategyTypes := []extensions.DeploymentStrategyType{extensions.RecreateDeploymentStrategyType, extensions.RollingUpdateDeploymentStrategyType}
|
2015-09-01 09:48:53 +00:00
|
|
|
j.Type = strategyTypes[c.Rand.Intn(len(strategyTypes))]
|
2015-10-09 22:49:10 +00:00
|
|
|
if j.Type != extensions.RollingUpdateDeploymentStrategyType {
|
2015-09-01 09:48:53 +00:00
|
|
|
j.RollingUpdate = nil
|
|
|
|
} else {
|
2015-10-09 22:49:10 +00:00
|
|
|
rollingUpdate := extensions.RollingUpdateDeployment{}
|
2015-09-01 09:48:53 +00:00
|
|
|
if c.RandBool() {
|
2015-11-10 06:28:45 +00:00
|
|
|
rollingUpdate.MaxUnavailable = intstr.FromInt(int(c.RandUint64()))
|
|
|
|
rollingUpdate.MaxSurge = intstr.FromInt(int(c.RandUint64()))
|
2015-09-01 09:48:53 +00:00
|
|
|
} else {
|
2015-11-10 06:28:45 +00:00
|
|
|
rollingUpdate.MaxSurge = intstr.FromString(fmt.Sprintf("%d%%", c.RandUint64()))
|
2015-09-01 09:48:53 +00:00
|
|
|
}
|
|
|
|
j.RollingUpdate = &rollingUpdate
|
|
|
|
}
|
2015-01-29 00:57:33 +00:00
|
|
|
},
|
2015-10-09 22:49:10 +00:00
|
|
|
func(j *extensions.JobSpec, c fuzz.Continue) {
|
2015-08-27 12:19:35 +00:00
|
|
|
c.FuzzNoCustom(j) // fuzz self without calling this function again
|
2015-11-18 18:24:54 +00:00
|
|
|
completions := int(c.Rand.Int31())
|
|
|
|
parallelism := int(c.Rand.Int31())
|
2015-08-27 12:19:35 +00:00
|
|
|
j.Completions = &completions
|
|
|
|
j.Parallelism = ¶llelism
|
|
|
|
},
|
2015-01-29 00:57:33 +00:00
|
|
|
func(j *api.List, c fuzz.Continue) {
|
2015-03-07 08:04:14 +00:00
|
|
|
c.FuzzNoCustom(j) // fuzz self without calling this function again
|
2015-04-29 03:15:16 +00:00
|
|
|
// TODO: uncomment when round trip starts from a versioned object
|
|
|
|
if false { //j.Items == nil {
|
2015-01-29 00:57:33 +00:00
|
|
|
j.Items = []runtime.Object{}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
func(j *runtime.Object, c fuzz.Continue) {
|
2015-04-29 03:15:16 +00:00
|
|
|
// TODO: uncomment when round trip starts from a versioned object
|
|
|
|
if true { //c.RandBool() {
|
2015-01-29 00:57:33 +00:00
|
|
|
*j = &runtime.Unknown{
|
2015-12-21 05:21:26 +00:00
|
|
|
// We do not set TypeMeta here because it is not carried through a round trip
|
|
|
|
RawJSON: []byte(`{"apiVersion":"unknown.group/unknown","kind":"Something","someKey":"someValue"}`),
|
2015-01-29 00:57:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
types := []runtime.Object{&api.Pod{}, &api.ReplicationController{}}
|
|
|
|
t := types[c.Rand.Intn(len(types))]
|
|
|
|
c.Fuzz(t)
|
|
|
|
*j = t
|
|
|
|
}
|
|
|
|
},
|
|
|
|
func(pb map[docker.Port][]docker.PortBinding, c fuzz.Continue) {
|
|
|
|
// This is necessary because keys with nil values get omitted.
|
|
|
|
// TODO: Is this a bug?
|
|
|
|
pb[docker.Port(c.RandString())] = []docker.PortBinding{
|
|
|
|
{c.RandString(), c.RandString()},
|
|
|
|
{c.RandString(), c.RandString()},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
func(pm map[string]docker.PortMapping, c fuzz.Continue) {
|
|
|
|
// This is necessary because keys with nil values get omitted.
|
|
|
|
// TODO: Is this a bug?
|
|
|
|
pm[c.RandString()] = docker.PortMapping{
|
|
|
|
c.RandString(): c.RandString(),
|
|
|
|
}
|
|
|
|
},
|
2015-07-30 19:59:22 +00:00
|
|
|
func(q *api.ResourceRequirements, c fuzz.Continue) {
|
|
|
|
randomQuantity := func() resource.Quantity {
|
2016-01-07 22:55:19 +00:00
|
|
|
var q resource.Quantity
|
|
|
|
c.Fuzz(&q)
|
|
|
|
return q
|
2015-07-30 19:59:22 +00:00
|
|
|
}
|
|
|
|
q.Limits = make(api.ResourceList)
|
|
|
|
q.Requests = make(api.ResourceList)
|
|
|
|
cpuLimit := randomQuantity()
|
|
|
|
q.Limits[api.ResourceCPU] = *cpuLimit.Copy()
|
|
|
|
q.Requests[api.ResourceCPU] = *cpuLimit.Copy()
|
|
|
|
memoryLimit := randomQuantity()
|
|
|
|
q.Limits[api.ResourceMemory] = *memoryLimit.Copy()
|
|
|
|
q.Requests[api.ResourceMemory] = *memoryLimit.Copy()
|
|
|
|
storageLimit := randomQuantity()
|
|
|
|
q.Limits[api.ResourceStorage] = *storageLimit.Copy()
|
|
|
|
q.Requests[api.ResourceStorage] = *storageLimit.Copy()
|
|
|
|
},
|
2015-08-28 16:26:36 +00:00
|
|
|
func(q *api.LimitRangeItem, c fuzz.Continue) {
|
2016-01-07 22:55:19 +00:00
|
|
|
var cpuLimit resource.Quantity
|
|
|
|
c.Fuzz(&cpuLimit)
|
2015-08-28 16:26:36 +00:00
|
|
|
|
|
|
|
q.Type = api.LimitTypeContainer
|
|
|
|
q.Default = make(api.ResourceList)
|
|
|
|
q.Default[api.ResourceCPU] = *(cpuLimit.Copy())
|
|
|
|
|
|
|
|
q.DefaultRequest = make(api.ResourceList)
|
|
|
|
q.DefaultRequest[api.ResourceCPU] = *(cpuLimit.Copy())
|
|
|
|
|
|
|
|
q.Max = make(api.ResourceList)
|
|
|
|
q.Max[api.ResourceCPU] = *(cpuLimit.Copy())
|
|
|
|
|
|
|
|
q.Min = make(api.ResourceList)
|
|
|
|
q.Min[api.ResourceCPU] = *(cpuLimit.Copy())
|
|
|
|
|
|
|
|
q.MaxLimitRequestRatio = make(api.ResourceList)
|
|
|
|
q.MaxLimitRequestRatio[api.ResourceCPU] = resource.MustParse("10")
|
|
|
|
},
|
2015-01-29 00:57:33 +00:00
|
|
|
func(p *api.PullPolicy, c fuzz.Continue) {
|
|
|
|
policies := []api.PullPolicy{api.PullAlways, api.PullNever, api.PullIfNotPresent}
|
|
|
|
*p = policies[c.Rand.Intn(len(policies))]
|
|
|
|
},
|
2015-01-26 17:52:50 +00:00
|
|
|
func(rp *api.RestartPolicy, c fuzz.Continue) {
|
2015-03-14 01:38:07 +00:00
|
|
|
policies := []api.RestartPolicy{api.RestartPolicyAlways, api.RestartPolicyNever, api.RestartPolicyOnFailure}
|
|
|
|
*rp = policies[c.Rand.Intn(len(policies))]
|
2015-01-26 17:52:50 +00:00
|
|
|
},
|
2015-11-18 18:24:54 +00:00
|
|
|
// Only api.DownwardAPIVolumeFile needs to have a specific func since FieldRef has to be
|
|
|
|
// defaulted to a version otherwise roundtrip will fail
|
|
|
|
// For the remaining volume plugins the default fuzzer is enough.
|
|
|
|
func(m *api.DownwardAPIVolumeFile, c fuzz.Continue) {
|
|
|
|
m.Path = c.RandString()
|
|
|
|
versions := []string{"v1"}
|
|
|
|
m.FieldRef.APIVersion = versions[c.Rand.Intn(len(versions))]
|
|
|
|
m.FieldRef.FieldPath = c.RandString()
|
|
|
|
},
|
2015-01-26 17:52:50 +00:00
|
|
|
func(vs *api.VolumeSource, c fuzz.Continue) {
|
2015-04-20 23:29:26 +00:00
|
|
|
// Exactly one of the fields must be set.
|
|
|
|
v := reflect.ValueOf(vs).Elem()
|
|
|
|
i := int(c.RandUint64() % uint64(v.NumField()))
|
2015-11-18 18:24:54 +00:00
|
|
|
t := v.Field(i).Addr()
|
|
|
|
for v.Field(i).IsNil() {
|
|
|
|
c.Fuzz(t.Interface())
|
|
|
|
}
|
2015-01-26 17:52:50 +00:00
|
|
|
},
|
2015-11-05 19:06:20 +00:00
|
|
|
func(i *api.ISCSIVolumeSource, c fuzz.Continue) {
|
|
|
|
i.ISCSIInterface = c.RandString()
|
|
|
|
if i.ISCSIInterface == "" {
|
|
|
|
i.ISCSIInterface = "default"
|
|
|
|
}
|
|
|
|
},
|
2015-01-26 17:52:50 +00:00
|
|
|
func(d *api.DNSPolicy, c fuzz.Continue) {
|
|
|
|
policies := []api.DNSPolicy{api.DNSClusterFirst, api.DNSDefault}
|
|
|
|
*d = policies[c.Rand.Intn(len(policies))]
|
|
|
|
},
|
|
|
|
func(p *api.Protocol, c fuzz.Continue) {
|
|
|
|
protocols := []api.Protocol{api.ProtocolTCP, api.ProtocolUDP}
|
|
|
|
*p = protocols[c.Rand.Intn(len(protocols))]
|
|
|
|
},
|
2015-05-18 20:13:42 +00:00
|
|
|
func(p *api.ServiceAffinity, c fuzz.Continue) {
|
|
|
|
types := []api.ServiceAffinity{api.ServiceAffinityClientIP, api.ServiceAffinityNone}
|
2015-01-26 17:52:50 +00:00
|
|
|
*p = types[c.Rand.Intn(len(types))]
|
|
|
|
},
|
2015-05-22 21:49:26 +00:00
|
|
|
func(p *api.ServiceType, c fuzz.Continue) {
|
2015-05-20 15:59:34 +00:00
|
|
|
types := []api.ServiceType{api.ServiceTypeClusterIP, api.ServiceTypeNodePort, api.ServiceTypeLoadBalancer}
|
2015-05-22 21:49:26 +00:00
|
|
|
*p = types[c.Rand.Intn(len(types))]
|
|
|
|
},
|
2015-01-26 17:52:50 +00:00
|
|
|
func(ct *api.Container, c fuzz.Continue) {
|
2015-03-07 08:04:14 +00:00
|
|
|
c.FuzzNoCustom(ct) // fuzz self without calling this function again
|
|
|
|
ct.TerminationMessagePath = "/" + ct.TerminationMessagePath // Must be non-empty
|
2015-01-26 17:52:50 +00:00
|
|
|
},
|
2015-11-05 23:38:46 +00:00
|
|
|
func(p *api.Probe, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(p)
|
|
|
|
// These fields have default values.
|
|
|
|
intFieldsWithDefaults := [...]string{"TimeoutSeconds", "PeriodSeconds", "SuccessThreshold", "FailureThreshold"}
|
|
|
|
v := reflect.ValueOf(p).Elem()
|
|
|
|
for _, field := range intFieldsWithDefaults {
|
|
|
|
f := v.FieldByName(field)
|
|
|
|
if f.Int() == 0 {
|
|
|
|
f.SetInt(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2015-04-23 20:57:30 +00:00
|
|
|
func(ev *api.EnvVar, c fuzz.Continue) {
|
|
|
|
ev.Name = c.RandString()
|
|
|
|
if c.RandBool() {
|
|
|
|
ev.Value = c.RandString()
|
|
|
|
} else {
|
|
|
|
ev.ValueFrom = &api.EnvVarSource{}
|
2015-05-04 17:31:36 +00:00
|
|
|
ev.ValueFrom.FieldRef = &api.ObjectFieldSelector{}
|
2015-04-23 20:57:30 +00:00
|
|
|
|
2015-12-19 05:08:34 +00:00
|
|
|
var versions []unversioned.GroupVersion
|
|
|
|
for _, testGroup := range testapi.Groups {
|
|
|
|
versions = append(versions, *testGroup.GroupVersion())
|
|
|
|
}
|
2015-04-23 20:57:30 +00:00
|
|
|
|
2015-11-16 16:42:09 +00:00
|
|
|
ev.ValueFrom.FieldRef.APIVersion = versions[c.Rand.Intn(len(versions))].String()
|
2015-05-04 17:31:36 +00:00
|
|
|
ev.ValueFrom.FieldRef.FieldPath = c.RandString()
|
2015-04-23 20:57:30 +00:00
|
|
|
}
|
|
|
|
},
|
2015-05-05 23:02:13 +00:00
|
|
|
func(sc *api.SecurityContext, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(sc) // fuzz self without calling this function again
|
2015-10-20 18:03:32 +00:00
|
|
|
if c.RandBool() {
|
|
|
|
priv := c.RandBool()
|
|
|
|
sc.Privileged = &priv
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.RandBool() {
|
|
|
|
sc.Capabilities = &api.Capabilities{
|
|
|
|
Add: make([]api.Capability, 0),
|
|
|
|
Drop: make([]api.Capability, 0),
|
|
|
|
}
|
|
|
|
c.Fuzz(&sc.Capabilities.Add)
|
|
|
|
c.Fuzz(&sc.Capabilities.Drop)
|
2015-05-05 23:02:13 +00:00
|
|
|
}
|
|
|
|
},
|
2015-02-18 01:24:50 +00:00
|
|
|
func(s *api.Secret, c fuzz.Continue) {
|
2015-03-07 08:04:14 +00:00
|
|
|
c.FuzzNoCustom(s) // fuzz self without calling this function again
|
2015-02-18 01:24:50 +00:00
|
|
|
s.Type = api.SecretTypeOpaque
|
|
|
|
},
|
2015-04-21 15:05:15 +00:00
|
|
|
func(pv *api.PersistentVolume, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(pv) // fuzz self without calling this function again
|
2015-05-29 20:12:10 +00:00
|
|
|
types := []api.PersistentVolumePhase{api.VolumeAvailable, api.VolumePending, api.VolumeBound, api.VolumeReleased, api.VolumeFailed}
|
2015-04-27 18:57:07 +00:00
|
|
|
pv.Status.Phase = types[c.Rand.Intn(len(types))]
|
2015-05-29 20:12:10 +00:00
|
|
|
pv.Status.Message = c.RandString()
|
|
|
|
reclamationPolicies := []api.PersistentVolumeReclaimPolicy{api.PersistentVolumeReclaimRecycle, api.PersistentVolumeReclaimRetain}
|
|
|
|
pv.Spec.PersistentVolumeReclaimPolicy = reclamationPolicies[c.Rand.Intn(len(reclamationPolicies))]
|
2015-04-21 15:05:15 +00:00
|
|
|
},
|
|
|
|
func(pvc *api.PersistentVolumeClaim, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(pvc) // fuzz self without calling this function again
|
2015-04-27 18:57:07 +00:00
|
|
|
types := []api.PersistentVolumeClaimPhase{api.ClaimBound, api.ClaimPending}
|
|
|
|
pvc.Status.Phase = types[c.Rand.Intn(len(types))]
|
2015-04-21 15:05:15 +00:00
|
|
|
},
|
2015-03-20 16:48:12 +00:00
|
|
|
func(s *api.NamespaceSpec, c fuzz.Continue) {
|
|
|
|
s.Finalizers = []api.FinalizerName{api.FinalizerKubernetes}
|
|
|
|
},
|
2015-03-10 15:21:09 +00:00
|
|
|
func(s *api.NamespaceStatus, c fuzz.Continue) {
|
|
|
|
s.Phase = api.NamespaceActive
|
|
|
|
},
|
2015-02-28 01:33:58 +00:00
|
|
|
func(http *api.HTTPGetAction, c fuzz.Continue) {
|
2015-06-25 17:53:41 +00:00
|
|
|
c.FuzzNoCustom(http) // fuzz self without calling this function again
|
|
|
|
http.Path = "/" + http.Path // can't be blank
|
|
|
|
http.Scheme = "x" + http.Scheme // can't be blank
|
2015-02-28 01:33:58 +00:00
|
|
|
},
|
2015-03-01 21:34:57 +00:00
|
|
|
func(ss *api.ServiceSpec, c fuzz.Continue) {
|
2015-03-07 08:04:14 +00:00
|
|
|
c.FuzzNoCustom(ss) // fuzz self without calling this function again
|
2015-03-13 15:16:41 +00:00
|
|
|
if len(ss.Ports) == 0 {
|
|
|
|
// There must be at least 1 port.
|
|
|
|
ss.Ports = append(ss.Ports, api.ServicePort{})
|
|
|
|
c.Fuzz(&ss.Ports[0])
|
|
|
|
}
|
|
|
|
for i := range ss.Ports {
|
2015-11-10 06:28:45 +00:00
|
|
|
switch ss.Ports[i].TargetPort.Type {
|
|
|
|
case intstr.Int:
|
2015-03-13 15:16:41 +00:00
|
|
|
ss.Ports[i].TargetPort.IntVal = 1 + ss.Ports[i].TargetPort.IntVal%65535 // non-zero
|
2015-11-10 06:28:45 +00:00
|
|
|
case intstr.String:
|
2015-03-13 15:16:41 +00:00
|
|
|
ss.Ports[i].TargetPort.StrVal = "x" + ss.Ports[i].TargetPort.StrVal // non-empty
|
|
|
|
}
|
2015-03-01 21:34:57 +00:00
|
|
|
}
|
|
|
|
},
|
2015-04-01 23:11:33 +00:00
|
|
|
func(n *api.Node, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(n)
|
|
|
|
n.Spec.ExternalID = "external"
|
|
|
|
},
|
2015-12-15 02:01:30 +00:00
|
|
|
func(s *api.NodeStatus, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(s)
|
|
|
|
s.Allocatable = s.Capacity
|
|
|
|
},
|
2015-10-09 22:49:10 +00:00
|
|
|
func(s *extensions.APIVersion, c fuzz.Continue) {
|
2015-08-24 21:41:02 +00:00
|
|
|
// We can't use c.RandString() here because it may generate empty
|
|
|
|
// string, which will cause tests failure.
|
|
|
|
s.APIGroup = "something"
|
|
|
|
},
|
2015-10-13 15:24:23 +00:00
|
|
|
func(s *extensions.HorizontalPodAutoscalerSpec, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(s) // fuzz self without calling this function again
|
2015-11-18 18:24:54 +00:00
|
|
|
minReplicas := int(c.Rand.Int31())
|
2015-10-13 15:24:23 +00:00
|
|
|
s.MinReplicas = &minReplicas
|
2015-11-18 23:28:06 +00:00
|
|
|
s.CPUUtilization = &extensions.CPUTargetUtilization{TargetPercentage: int(int32(c.RandUint64()))}
|
2015-10-13 15:24:23 +00:00
|
|
|
},
|
2015-12-14 13:31:23 +00:00
|
|
|
func(psp *extensions.PodSecurityPolicySpec, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(psp) // fuzz self without calling this function again
|
|
|
|
userTypes := []extensions.RunAsUserStrategy{extensions.RunAsUserStrategyMustRunAsNonRoot, extensions.RunAsUserStrategyMustRunAs, extensions.RunAsUserStrategyRunAsAny}
|
|
|
|
psp.RunAsUser.Type = userTypes[c.Rand.Intn(len(userTypes))]
|
|
|
|
seLinuxTypes := []extensions.SELinuxContextStrategy{extensions.SELinuxStrategyRunAsAny, extensions.SELinuxStrategyMustRunAs}
|
|
|
|
psp.SELinuxContext.Type = seLinuxTypes[c.Rand.Intn(len(seLinuxTypes))]
|
|
|
|
},
|
2015-01-29 00:57:33 +00:00
|
|
|
)
|
|
|
|
return f
|
|
|
|
}
|