2015-01-29 08:57:33 +08:00
|
|
|
/*
|
2016-06-03 08:25:58 +08:00
|
|
|
Copyright 2015 The Kubernetes Authors.
|
2015-01-29 08:57:33 +08: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 17:48:53 +08:00
|
|
|
"fmt"
|
2015-01-29 08:57:33 +08:00
|
|
|
"math/rand"
|
2015-04-21 07:29:26 +08:00
|
|
|
"reflect"
|
2015-01-29 08:57:33 +08:00
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
|
2017-01-11 22:09:48 +08:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/labels"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
|
|
"k8s.io/apimachinery/pkg/types"
|
2016-11-02 07:48:04 +08:00
|
|
|
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
2015-08-06 06:03:47 +08:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
|
|
|
"k8s.io/kubernetes/pkg/api/resource"
|
2015-12-19 13:08:34 +08:00
|
|
|
"k8s.io/kubernetes/pkg/api/testapi"
|
2016-05-05 18:27:24 +08:00
|
|
|
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
2016-04-18 23:44:19 +08:00
|
|
|
"k8s.io/kubernetes/pkg/apis/batch"
|
2017-01-11 07:47:17 +08:00
|
|
|
"k8s.io/kubernetes/pkg/apis/certificates"
|
2015-10-10 06:04:41 +08:00
|
|
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
2016-10-26 16:40:07 +08:00
|
|
|
"k8s.io/kubernetes/pkg/apis/policy"
|
2016-08-25 02:23:27 +08:00
|
|
|
"k8s.io/kubernetes/pkg/apis/rbac"
|
2015-08-06 06:03:47 +08:00
|
|
|
"k8s.io/kubernetes/pkg/fields"
|
2015-11-10 14:28:45 +08:00
|
|
|
"k8s.io/kubernetes/pkg/util/intstr"
|
2015-03-21 04:50:06 +08:00
|
|
|
|
2015-07-23 12:52:05 +08:00
|
|
|
"github.com/google/gofuzz"
|
2015-01-29 08:57:33 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// FuzzerFor can randomly populate api objects that are destined for version.
|
2016-11-21 10:55:31 +08:00
|
|
|
func FuzzerFor(t *testing.T, version schema.GroupVersion, src rand.Source) *fuzz.Fuzzer {
|
2016-12-01 22:23:55 +08:00
|
|
|
f := fuzz.New().NilChance(.5).NumElements(0, 1)
|
2015-01-29 08:57:33 +08:00
|
|
|
if src != nil {
|
|
|
|
f.RandSource(src)
|
|
|
|
}
|
|
|
|
f.Funcs(
|
2015-11-19 02:24:54 +08: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-08 06:55:19 +08:00
|
|
|
func(q *resource.Quantity, c fuzz.Continue) {
|
|
|
|
*q = *resource.NewQuantity(c.Int63n(1000), resource.DecimalExponent)
|
|
|
|
},
|
2015-01-29 08:57:33 +08: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 = ""
|
|
|
|
},
|
2016-12-04 02:57:26 +08:00
|
|
|
func(j *metav1.TypeMeta, c fuzz.Continue) {
|
2015-01-29 08:57:33 +08: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 12:50:01 +08:00
|
|
|
j.UID = types.UID(c.RandString())
|
|
|
|
j.GenerateName = c.RandString()
|
2015-01-29 08:57:33 +08:00
|
|
|
|
|
|
|
var sec, nsec int64
|
|
|
|
c.Fuzz(&sec)
|
|
|
|
c.Fuzz(&nsec)
|
2016-12-04 02:57:26 +08:00
|
|
|
j.CreationTimestamp = metav1.Unix(sec, nsec).Rfc3339Copy()
|
2015-01-29 08:57:33 +08: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()
|
|
|
|
},
|
2016-12-04 02:57:26 +08:00
|
|
|
func(j *metav1.ListMeta, c fuzz.Continue) {
|
2015-01-29 08:57:33 +08:00
|
|
|
j.ResourceVersion = strconv.FormatUint(c.RandUint64(), 10)
|
|
|
|
j.SelfLink = c.RandString()
|
|
|
|
},
|
2015-12-10 17:39:03 +08: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 16:51:47 +08: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-15 05:56:51 +08:00
|
|
|
func(s *api.PodSpec, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(s)
|
2015-08-20 07:59:43 +08:00
|
|
|
// has a default value
|
|
|
|
ttl := int64(30)
|
|
|
|
if c.RandBool() {
|
|
|
|
ttl = int64(c.Uint32())
|
|
|
|
}
|
2015-09-15 05:56:51 +08:00
|
|
|
s.TerminationGracePeriodSeconds = &ttl
|
|
|
|
|
2015-10-21 02:03:32 +08:00
|
|
|
c.Fuzz(s.SecurityContext)
|
|
|
|
|
2015-09-15 05:56:51 +08:00
|
|
|
if s.SecurityContext == nil {
|
2015-10-21 02:03:32 +08:00
|
|
|
s.SecurityContext = new(api.PodSecurityContext)
|
2015-09-15 05:56:51 +08:00
|
|
|
}
|
2016-12-01 00:51:12 +08:00
|
|
|
if s.Affinity == nil {
|
|
|
|
s.Affinity = new(api.Affinity)
|
|
|
|
}
|
2015-08-20 07:59:43 +08:00
|
|
|
},
|
2015-01-29 08:57:33 +08: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-05 04:55:41 +08:00
|
|
|
func(j *api.Binding, c fuzz.Continue) {
|
|
|
|
c.Fuzz(&j.ObjectMeta)
|
|
|
|
j.Target.Name = c.RandString()
|
|
|
|
},
|
2015-01-29 08:57:33 +08:00
|
|
|
func(j *api.ReplicationControllerSpec, c fuzz.Continue) {
|
2015-05-29 07:29:06 +08:00
|
|
|
c.FuzzNoCustom(j) // fuzz self without calling this function again
|
|
|
|
//j.TemplateRef = nil // this is required for round trip
|
2015-01-29 08:57:33 +08:00
|
|
|
},
|
2015-10-10 06:49:10 +08:00
|
|
|
func(j *extensions.DeploymentStrategy, c fuzz.Continue) {
|
2015-07-26 03:08:34 +08:00
|
|
|
c.FuzzNoCustom(j) // fuzz self without calling this function again
|
2015-09-01 17:48:53 +08:00
|
|
|
// Ensure that strategyType is one of valid values.
|
2015-10-10 06:49:10 +08:00
|
|
|
strategyTypes := []extensions.DeploymentStrategyType{extensions.RecreateDeploymentStrategyType, extensions.RollingUpdateDeploymentStrategyType}
|
2015-09-01 17:48:53 +08:00
|
|
|
j.Type = strategyTypes[c.Rand.Intn(len(strategyTypes))]
|
2015-10-10 06:49:10 +08:00
|
|
|
if j.Type != extensions.RollingUpdateDeploymentStrategyType {
|
2015-09-01 17:48:53 +08:00
|
|
|
j.RollingUpdate = nil
|
|
|
|
} else {
|
2015-10-10 06:49:10 +08:00
|
|
|
rollingUpdate := extensions.RollingUpdateDeployment{}
|
2015-09-01 17:48:53 +08:00
|
|
|
if c.RandBool() {
|
2016-12-01 22:24:44 +08:00
|
|
|
rollingUpdate.MaxUnavailable = intstr.FromInt(int(c.Rand.Int31()))
|
|
|
|
rollingUpdate.MaxSurge = intstr.FromInt(int(c.Rand.Int31()))
|
2015-09-01 17:48:53 +08:00
|
|
|
} else {
|
2016-12-01 22:24:44 +08:00
|
|
|
rollingUpdate.MaxSurge = intstr.FromString(fmt.Sprintf("%d%%", c.Rand.Int31()))
|
2015-09-01 17:48:53 +08:00
|
|
|
}
|
|
|
|
j.RollingUpdate = &rollingUpdate
|
|
|
|
}
|
2015-01-29 08:57:33 +08:00
|
|
|
},
|
2016-04-18 23:44:19 +08:00
|
|
|
func(j *batch.JobSpec, c fuzz.Continue) {
|
2015-08-27 20:19:35 +08:00
|
|
|
c.FuzzNoCustom(j) // fuzz self without calling this function again
|
2016-04-27 12:35:14 +08:00
|
|
|
completions := int32(c.Rand.Int31())
|
|
|
|
parallelism := int32(c.Rand.Int31())
|
2015-08-27 20:19:35 +08:00
|
|
|
j.Completions = &completions
|
|
|
|
j.Parallelism = ¶llelism
|
Added Selector Generation to Job.
Added selector generation to Job's
strategy.Validate, right before validation.
Can't do in defaulting since UID is not known.
Added a validation to Job to ensure that the generated
labels and selector are correct when generation was requested.
This happens right after generation, but validation is in a better
place to return an error.
Adds "manualSelector" field to batch/v1 Job to control selector generation.
Adds same field to extensions/__internal. Conversion between those two
is automatic.
Adds "autoSelector" field to extensions/v1beta1 Job. Used for storing batch/v1 Jobs
- Default for v1 is to do generation.
- Default for v1beta1 is to not do it.
- In both cases, unset == false == do the default thing.
Release notes:
Added batch/v1 group, which contains just Job, and which is the next
version of extensions/v1beta1 Job.
The changes from the previous version are:
- Users no longer need to ensure labels on their pod template are unique to the enclosing
job (but may add labels as needed for categorization).
- In v1beta1, job.spec.selector was defaulted from pod labels, with the user responsible for uniqueness.
In v1, a unique label is generated and added to the pod template, and used as the selector (other
labels added by user stay on pod template, but need not be used by selector).
- a new field called "manualSelector" field exists to control whether the new behavior is used,
versus a more error-prone but more flexible "manual" (not generated) seletor. Most users
will not need to use this field and should leave it unset.
Users who are creating extensions.Job go objects and then posting them using the go client
will see a change in the default behavior. They need to either stop providing a selector (relying on
selector generation) or else specify "spec.manualSelector" until they are ready to do the former.
2016-02-09 07:55:40 +08:00
|
|
|
if c.Rand.Int31()%2 == 0 {
|
|
|
|
j.ManualSelector = newBool(true)
|
|
|
|
} else {
|
|
|
|
j.ManualSelector = nil
|
|
|
|
}
|
2015-08-27 20:19:35 +08:00
|
|
|
},
|
2016-11-02 06:46:23 +08:00
|
|
|
func(sj *batch.CronJobSpec, c fuzz.Continue) {
|
2016-07-13 23:56:30 +08:00
|
|
|
c.FuzzNoCustom(sj)
|
|
|
|
suspend := c.RandBool()
|
|
|
|
sj.Suspend = &suspend
|
|
|
|
sds := int64(c.RandUint64())
|
|
|
|
sj.StartingDeadlineSeconds = &sds
|
|
|
|
sj.Schedule = c.RandString()
|
|
|
|
},
|
2016-05-17 16:52:07 +08:00
|
|
|
func(cp *batch.ConcurrencyPolicy, c fuzz.Continue) {
|
|
|
|
policies := []batch.ConcurrencyPolicy{batch.AllowConcurrent, batch.ForbidConcurrent, batch.ReplaceConcurrent}
|
|
|
|
*cp = policies[c.Rand.Intn(len(policies))]
|
|
|
|
},
|
2015-01-29 08:57:33 +08:00
|
|
|
func(j *api.List, c fuzz.Continue) {
|
2015-03-07 16:04:14 +08:00
|
|
|
c.FuzzNoCustom(j) // fuzz self without calling this function again
|
2015-04-29 11:15:16 +08:00
|
|
|
// TODO: uncomment when round trip starts from a versioned object
|
|
|
|
if false { //j.Items == nil {
|
2015-01-29 08:57:33 +08:00
|
|
|
j.Items = []runtime.Object{}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
func(j *runtime.Object, c fuzz.Continue) {
|
2015-04-29 11:15:16 +08:00
|
|
|
// TODO: uncomment when round trip starts from a versioned object
|
|
|
|
if true { //c.RandBool() {
|
2015-01-29 08:57:33 +08:00
|
|
|
*j = &runtime.Unknown{
|
2015-12-21 13:21:26 +08:00
|
|
|
// We do not set TypeMeta here because it is not carried through a round trip
|
2016-03-16 16:03:33 +08:00
|
|
|
Raw: []byte(`{"apiVersion":"unknown.group/unknown","kind":"Something","someKey":"someValue"}`),
|
|
|
|
ContentType: runtime.ContentTypeJSON,
|
2015-01-29 08:57:33 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
types := []runtime.Object{&api.Pod{}, &api.ReplicationController{}}
|
|
|
|
t := types[c.Rand.Intn(len(types))]
|
|
|
|
c.Fuzz(t)
|
|
|
|
*j = t
|
|
|
|
}
|
|
|
|
},
|
2015-07-31 03:59:22 +08:00
|
|
|
func(q *api.ResourceRequirements, c fuzz.Continue) {
|
|
|
|
randomQuantity := func() resource.Quantity {
|
2016-01-08 06:55:19 +08:00
|
|
|
var q resource.Quantity
|
|
|
|
c.Fuzz(&q)
|
2016-05-22 09:56:55 +08:00
|
|
|
// precalc the string for benchmarking purposes
|
|
|
|
_ = q.String()
|
2016-01-08 06:55:19 +08:00
|
|
|
return q
|
2015-07-31 03:59:22 +08: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-29 00:26:36 +08:00
|
|
|
func(q *api.LimitRangeItem, c fuzz.Continue) {
|
2016-01-08 06:55:19 +08:00
|
|
|
var cpuLimit resource.Quantity
|
|
|
|
c.Fuzz(&cpuLimit)
|
2015-08-29 00:26:36 +08: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 08:57:33 +08: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-27 01:52:50 +08:00
|
|
|
func(rp *api.RestartPolicy, c fuzz.Continue) {
|
2015-03-14 09:38:07 +08:00
|
|
|
policies := []api.RestartPolicy{api.RestartPolicyAlways, api.RestartPolicyNever, api.RestartPolicyOnFailure}
|
|
|
|
*rp = policies[c.Rand.Intn(len(policies))]
|
2015-01-27 01:52:50 +08:00
|
|
|
},
|
2016-07-11 08:48:28 +08:00
|
|
|
// api.DownwardAPIVolumeFile needs to have a specific func since FieldRef has to be
|
2015-11-19 02:24:54 +08:00
|
|
|
// defaulted to a version otherwise roundtrip will fail
|
|
|
|
func(m *api.DownwardAPIVolumeFile, c fuzz.Continue) {
|
|
|
|
m.Path = c.RandString()
|
|
|
|
versions := []string{"v1"}
|
2016-05-24 06:08:22 +08:00
|
|
|
m.FieldRef = &api.ObjectFieldSelector{}
|
2015-11-19 02:24:54 +08:00
|
|
|
m.FieldRef.APIVersion = versions[c.Rand.Intn(len(versions))]
|
|
|
|
m.FieldRef.FieldPath = c.RandString()
|
2016-07-11 08:48:28 +08:00
|
|
|
c.Fuzz(m.Mode)
|
|
|
|
if m.Mode != nil {
|
|
|
|
*m.Mode &= 0777
|
|
|
|
}
|
|
|
|
},
|
|
|
|
func(s *api.SecretVolumeSource, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(s) // fuzz self without calling this function again
|
|
|
|
|
|
|
|
// DefaultMode should always be set, it has a default
|
|
|
|
// value and it is expected to be between 0 and 0777
|
|
|
|
var mode int32
|
|
|
|
c.Fuzz(&mode)
|
|
|
|
mode &= 0777
|
|
|
|
s.DefaultMode = &mode
|
|
|
|
},
|
|
|
|
func(cm *api.ConfigMapVolumeSource, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(cm) // fuzz self without calling this function again
|
|
|
|
|
|
|
|
// DefaultMode should always be set, it has a default
|
|
|
|
// value and it is expected to be between 0 and 0777
|
|
|
|
var mode int32
|
|
|
|
c.Fuzz(&mode)
|
|
|
|
mode &= 0777
|
|
|
|
cm.DefaultMode = &mode
|
|
|
|
},
|
|
|
|
func(d *api.DownwardAPIVolumeSource, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(d) // fuzz self without calling this function again
|
|
|
|
|
|
|
|
// DefaultMode should always be set, it has a default
|
|
|
|
// value and it is expected to be between 0 and 0777
|
|
|
|
var mode int32
|
|
|
|
c.Fuzz(&mode)
|
|
|
|
mode &= 0777
|
|
|
|
d.DefaultMode = &mode
|
|
|
|
},
|
|
|
|
func(k *api.KeyToPath, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(k) // fuzz self without calling this function again
|
|
|
|
k.Key = c.RandString()
|
|
|
|
k.Path = c.RandString()
|
|
|
|
|
|
|
|
// Mode is not mandatory, but if it is set, it should be
|
|
|
|
// a value between 0 and 0777
|
|
|
|
if k.Mode != nil {
|
|
|
|
*k.Mode &= 0777
|
|
|
|
}
|
2015-11-19 02:24:54 +08:00
|
|
|
},
|
2015-01-27 01:52:50 +08:00
|
|
|
func(vs *api.VolumeSource, c fuzz.Continue) {
|
2015-04-21 07:29:26 +08:00
|
|
|
// Exactly one of the fields must be set.
|
|
|
|
v := reflect.ValueOf(vs).Elem()
|
|
|
|
i := int(c.RandUint64() % uint64(v.NumField()))
|
2015-11-19 02:24:54 +08:00
|
|
|
t := v.Field(i).Addr()
|
|
|
|
for v.Field(i).IsNil() {
|
|
|
|
c.Fuzz(t.Interface())
|
|
|
|
}
|
2015-01-27 01:52:50 +08:00
|
|
|
},
|
2015-11-06 03:06:20 +08:00
|
|
|
func(i *api.ISCSIVolumeSource, c fuzz.Continue) {
|
|
|
|
i.ISCSIInterface = c.RandString()
|
|
|
|
if i.ISCSIInterface == "" {
|
|
|
|
i.ISCSIInterface = "default"
|
|
|
|
}
|
|
|
|
},
|
2015-01-27 01:52:50 +08: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-19 04:13:42 +08:00
|
|
|
func(p *api.ServiceAffinity, c fuzz.Continue) {
|
|
|
|
types := []api.ServiceAffinity{api.ServiceAffinityClientIP, api.ServiceAffinityNone}
|
2015-01-27 01:52:50 +08:00
|
|
|
*p = types[c.Rand.Intn(len(types))]
|
|
|
|
},
|
2015-05-23 05:49:26 +08:00
|
|
|
func(p *api.ServiceType, c fuzz.Continue) {
|
2015-05-20 23:59:34 +08:00
|
|
|
types := []api.ServiceType{api.ServiceTypeClusterIP, api.ServiceTypeNodePort, api.ServiceTypeLoadBalancer}
|
2015-05-23 05:49:26 +08:00
|
|
|
*p = types[c.Rand.Intn(len(types))]
|
|
|
|
},
|
2015-01-27 01:52:50 +08:00
|
|
|
func(ct *api.Container, c fuzz.Continue) {
|
2015-03-07 16:04:14 +08:00
|
|
|
c.FuzzNoCustom(ct) // fuzz self without calling this function again
|
|
|
|
ct.TerminationMessagePath = "/" + ct.TerminationMessagePath // Must be non-empty
|
2015-01-27 01:52:50 +08:00
|
|
|
},
|
2015-11-06 07:38:46 +08: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-24 04:57:30 +08: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-05 01:31:36 +08:00
|
|
|
ev.ValueFrom.FieldRef = &api.ObjectFieldSelector{}
|
2015-04-24 04:57:30 +08:00
|
|
|
|
2016-11-21 10:55:31 +08:00
|
|
|
var versions []schema.GroupVersion
|
2015-12-19 13:08:34 +08:00
|
|
|
for _, testGroup := range testapi.Groups {
|
|
|
|
versions = append(versions, *testGroup.GroupVersion())
|
|
|
|
}
|
2015-04-24 04:57:30 +08:00
|
|
|
|
2015-11-17 00:42:09 +08:00
|
|
|
ev.ValueFrom.FieldRef.APIVersion = versions[c.Rand.Intn(len(versions))].String()
|
2015-05-05 01:31:36 +08:00
|
|
|
ev.ValueFrom.FieldRef.FieldPath = c.RandString()
|
2015-04-24 04:57:30 +08:00
|
|
|
}
|
|
|
|
},
|
2016-11-30 10:57:35 +08:00
|
|
|
func(ev *api.EnvFromSource, c fuzz.Continue) {
|
|
|
|
if c.RandBool() {
|
|
|
|
ev.Prefix = "p_"
|
|
|
|
}
|
|
|
|
if c.RandBool() {
|
|
|
|
c.Fuzz(&ev.ConfigMapRef)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
func(cm *api.ConfigMapEnvSource, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(cm) // fuzz self without calling this function again
|
|
|
|
},
|
2015-05-06 07:02:13 +08:00
|
|
|
func(sc *api.SecurityContext, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(sc) // fuzz self without calling this function again
|
2015-10-21 02:03:32 +08: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-06 07:02:13 +08:00
|
|
|
}
|
|
|
|
},
|
2015-02-18 09:24:50 +08:00
|
|
|
func(s *api.Secret, c fuzz.Continue) {
|
2015-03-07 16:04:14 +08:00
|
|
|
c.FuzzNoCustom(s) // fuzz self without calling this function again
|
2015-02-18 09:24:50 +08:00
|
|
|
s.Type = api.SecretTypeOpaque
|
|
|
|
},
|
2016-05-12 01:11:03 +08:00
|
|
|
func(r *api.RBDVolumeSource, c fuzz.Continue) {
|
|
|
|
r.RBDPool = c.RandString()
|
|
|
|
if r.RBDPool == "" {
|
|
|
|
r.RBDPool = "rbd"
|
|
|
|
}
|
|
|
|
r.RadosUser = c.RandString()
|
|
|
|
if r.RadosUser == "" {
|
|
|
|
r.RadosUser = "admin"
|
|
|
|
}
|
|
|
|
r.Keyring = c.RandString()
|
|
|
|
if r.Keyring == "" {
|
|
|
|
r.Keyring = "/etc/ceph/keyring"
|
|
|
|
}
|
|
|
|
},
|
2015-04-21 23:05:15 +08:00
|
|
|
func(pv *api.PersistentVolume, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(pv) // fuzz self without calling this function again
|
2015-05-30 04:12:10 +08:00
|
|
|
types := []api.PersistentVolumePhase{api.VolumeAvailable, api.VolumePending, api.VolumeBound, api.VolumeReleased, api.VolumeFailed}
|
2015-04-28 02:57:07 +08:00
|
|
|
pv.Status.Phase = types[c.Rand.Intn(len(types))]
|
2015-05-30 04:12:10 +08: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 23:05:15 +08:00
|
|
|
},
|
|
|
|
func(pvc *api.PersistentVolumeClaim, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(pvc) // fuzz self without calling this function again
|
2016-05-17 20:55:10 +08:00
|
|
|
types := []api.PersistentVolumeClaimPhase{api.ClaimBound, api.ClaimPending, api.ClaimLost}
|
2015-04-28 02:57:07 +08:00
|
|
|
pvc.Status.Phase = types[c.Rand.Intn(len(types))]
|
2015-04-21 23:05:15 +08:00
|
|
|
},
|
2016-07-28 02:07:34 +08:00
|
|
|
func(obj *api.AzureDiskVolumeSource, c fuzz.Continue) {
|
|
|
|
if obj.CachingMode == nil {
|
|
|
|
obj.CachingMode = new(api.AzureDataDiskCachingMode)
|
|
|
|
*obj.CachingMode = api.AzureDataDiskCachingNone
|
|
|
|
}
|
|
|
|
if obj.FSType == nil {
|
|
|
|
obj.FSType = new(string)
|
|
|
|
*obj.FSType = "ext4"
|
|
|
|
}
|
|
|
|
if obj.ReadOnly == nil {
|
|
|
|
obj.ReadOnly = new(bool)
|
|
|
|
*obj.ReadOnly = false
|
|
|
|
}
|
|
|
|
},
|
2015-03-21 00:48:12 +08:00
|
|
|
func(s *api.NamespaceSpec, c fuzz.Continue) {
|
|
|
|
s.Finalizers = []api.FinalizerName{api.FinalizerKubernetes}
|
|
|
|
},
|
2015-03-10 23:21:09 +08:00
|
|
|
func(s *api.NamespaceStatus, c fuzz.Continue) {
|
|
|
|
s.Phase = api.NamespaceActive
|
|
|
|
},
|
2015-02-28 09:33:58 +08:00
|
|
|
func(http *api.HTTPGetAction, c fuzz.Continue) {
|
2015-06-26 01:53:41 +08: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 09:33:58 +08:00
|
|
|
},
|
2015-03-02 05:34:57 +08:00
|
|
|
func(ss *api.ServiceSpec, c fuzz.Continue) {
|
2015-03-07 16:04:14 +08:00
|
|
|
c.FuzzNoCustom(ss) // fuzz self without calling this function again
|
2015-03-13 23:16:41 +08: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 14:28:45 +08:00
|
|
|
switch ss.Ports[i].TargetPort.Type {
|
|
|
|
case intstr.Int:
|
2015-03-13 23:16:41 +08:00
|
|
|
ss.Ports[i].TargetPort.IntVal = 1 + ss.Ports[i].TargetPort.IntVal%65535 // non-zero
|
2015-11-10 14:28:45 +08:00
|
|
|
case intstr.String:
|
2015-03-13 23:16:41 +08:00
|
|
|
ss.Ports[i].TargetPort.StrVal = "x" + ss.Ports[i].TargetPort.StrVal // non-empty
|
|
|
|
}
|
2015-03-02 05:34:57 +08:00
|
|
|
}
|
|
|
|
},
|
2015-04-02 07:11:33 +08:00
|
|
|
func(n *api.Node, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(n)
|
|
|
|
n.Spec.ExternalID = "external"
|
|
|
|
},
|
2015-12-15 10:01:30 +08:00
|
|
|
func(s *api.NodeStatus, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(s)
|
|
|
|
s.Allocatable = s.Capacity
|
|
|
|
},
|
2016-05-05 18:27:24 +08:00
|
|
|
func(s *autoscaling.HorizontalPodAutoscalerSpec, c fuzz.Continue) {
|
2015-10-13 23:24:23 +08:00
|
|
|
c.FuzzNoCustom(s) // fuzz self without calling this function again
|
2016-04-27 12:35:14 +08:00
|
|
|
minReplicas := int32(c.Rand.Int31())
|
2015-10-13 23:24:23 +08:00
|
|
|
s.MinReplicas = &minReplicas
|
2016-05-05 18:27:24 +08:00
|
|
|
targetCpu := int32(c.RandUint64())
|
|
|
|
s.TargetCPUUtilizationPercentage = &targetCpu
|
2016-02-08 22:03:59 +08:00
|
|
|
},
|
2015-12-14 21:31:23 +08:00
|
|
|
func(psp *extensions.PodSecurityPolicySpec, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(psp) // fuzz self without calling this function again
|
2016-03-03 08:50:14 +08:00
|
|
|
runAsUserRules := []extensions.RunAsUserStrategy{extensions.RunAsUserStrategyMustRunAsNonRoot, extensions.RunAsUserStrategyMustRunAs, extensions.RunAsUserStrategyRunAsAny}
|
|
|
|
psp.RunAsUser.Rule = runAsUserRules[c.Rand.Intn(len(runAsUserRules))]
|
|
|
|
seLinuxRules := []extensions.SELinuxStrategy{extensions.SELinuxStrategyRunAsAny, extensions.SELinuxStrategyMustRunAs}
|
|
|
|
psp.SELinux.Rule = seLinuxRules[c.Rand.Intn(len(seLinuxRules))]
|
2015-12-14 21:31:23 +08:00
|
|
|
},
|
2016-03-09 08:27:13 +08:00
|
|
|
func(s *extensions.Scale, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(s) // fuzz self without calling this function again
|
|
|
|
// TODO: Implement a fuzzer to generate valid keys, values and operators for
|
|
|
|
// selector requirements.
|
|
|
|
if s.Status.Selector != nil {
|
2016-12-04 02:57:26 +08:00
|
|
|
s.Status.Selector = &metav1.LabelSelector{
|
2016-03-09 08:27:13 +08:00
|
|
|
MatchLabels: map[string]string{
|
|
|
|
"testlabelkey": "testlabelval",
|
|
|
|
},
|
2016-12-04 02:57:26 +08:00
|
|
|
MatchExpressions: []metav1.LabelSelectorRequirement{
|
2016-03-09 08:27:13 +08:00
|
|
|
{
|
|
|
|
Key: "testkey",
|
2016-12-04 02:57:26 +08:00
|
|
|
Operator: metav1.LabelSelectorOpIn,
|
2016-03-09 08:27:13 +08:00
|
|
|
Values: []string{"val1", "val2", "val3"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2016-08-25 02:23:27 +08:00
|
|
|
func(r *rbac.RoleRef, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(r) // fuzz self without calling this function again
|
|
|
|
|
|
|
|
// match defaulter
|
|
|
|
if len(r.APIGroup) == 0 {
|
|
|
|
r.APIGroup = rbac.GroupName
|
|
|
|
}
|
|
|
|
},
|
2016-05-05 06:52:19 +08:00
|
|
|
func(r *runtime.RawExtension, c fuzz.Continue) {
|
|
|
|
// Pick an arbitrary type and fuzz it
|
|
|
|
types := []runtime.Object{&api.Pod{}, &extensions.Deployment{}, &api.Service{}}
|
|
|
|
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()
|
|
|
|
default:
|
|
|
|
t.Errorf("Failed to find codec for object type: %T", obj)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the object to raw bytes
|
|
|
|
bytes, err := runtime.Encode(codec, obj)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Failed to encode object: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the bytes field on the RawExtension
|
|
|
|
r.Raw = bytes
|
|
|
|
},
|
2016-11-02 07:48:04 +08:00
|
|
|
func(obj *kubeadm.MasterConfiguration, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(obj)
|
|
|
|
obj.KubernetesVersion = "v10"
|
2016-11-09 03:27:16 +08:00
|
|
|
obj.API.Port = 20
|
2016-11-02 07:48:04 +08:00
|
|
|
obj.Networking.ServiceSubnet = "foo"
|
|
|
|
obj.Networking.DNSDomain = "foo"
|
2016-12-22 02:02:53 +08:00
|
|
|
obj.Discovery.Token = &kubeadm.TokenDiscovery{}
|
2016-11-02 07:48:04 +08:00
|
|
|
},
|
2016-10-26 16:40:07 +08:00
|
|
|
func(s *policy.PodDisruptionBudgetStatus, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(s) // fuzz self without calling this function again
|
|
|
|
s.PodDisruptionsAllowed = int32(c.Rand.Intn(2))
|
|
|
|
},
|
2017-01-11 07:47:17 +08:00
|
|
|
func(obj *certificates.CertificateSigningRequestSpec, c fuzz.Continue) {
|
|
|
|
c.FuzzNoCustom(obj) // fuzz self without calling this function again
|
|
|
|
obj.Usages = []certificates.KeyUsage{certificates.UsageKeyEncipherment}
|
|
|
|
},
|
2015-01-29 08:57:33 +08:00
|
|
|
)
|
|
|
|
return f
|
|
|
|
}
|
Added Selector Generation to Job.
Added selector generation to Job's
strategy.Validate, right before validation.
Can't do in defaulting since UID is not known.
Added a validation to Job to ensure that the generated
labels and selector are correct when generation was requested.
This happens right after generation, but validation is in a better
place to return an error.
Adds "manualSelector" field to batch/v1 Job to control selector generation.
Adds same field to extensions/__internal. Conversion between those two
is automatic.
Adds "autoSelector" field to extensions/v1beta1 Job. Used for storing batch/v1 Jobs
- Default for v1 is to do generation.
- Default for v1beta1 is to not do it.
- In both cases, unset == false == do the default thing.
Release notes:
Added batch/v1 group, which contains just Job, and which is the next
version of extensions/v1beta1 Job.
The changes from the previous version are:
- Users no longer need to ensure labels on their pod template are unique to the enclosing
job (but may add labels as needed for categorization).
- In v1beta1, job.spec.selector was defaulted from pod labels, with the user responsible for uniqueness.
In v1, a unique label is generated and added to the pod template, and used as the selector (other
labels added by user stay on pod template, but need not be used by selector).
- a new field called "manualSelector" field exists to control whether the new behavior is used,
versus a more error-prone but more flexible "manual" (not generated) seletor. Most users
will not need to use this field and should leave it unset.
Users who are creating extensions.Job go objects and then posting them using the go client
will see a change in the default behavior. They need to either stop providing a selector (relying on
selector generation) or else specify "spec.manualSelector" until they are ready to do the former.
2016-02-09 07:55:40 +08:00
|
|
|
|
|
|
|
func newBool(val bool) *bool {
|
|
|
|
p := new(bool)
|
|
|
|
*p = val
|
|
|
|
return p
|
|
|
|
}
|