...
1
16
17 package fuzzer
18
19 import (
20 "math"
21
22 fuzz "github.com/google/gofuzz"
23 runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
24 "k8s.io/kubernetes/pkg/apis/batch"
25 api "k8s.io/kubernetes/pkg/apis/core"
26 "k8s.io/utils/pointer"
27 )
28
29
30 var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
31 return []interface{}{
32 func(j *batch.Job, c fuzz.Continue) {
33 c.FuzzNoCustom(j)
34
35
36 if len(j.Labels) == 0 {
37 j.Labels = j.Spec.Template.Labels
38 }
39 },
40 func(j *batch.JobSpec, c fuzz.Continue) {
41 c.FuzzNoCustom(j)
42 completions := int32(c.Rand.Int31())
43 parallelism := int32(c.Rand.Int31())
44 backoffLimit := int32(c.Rand.Int31())
45 j.Completions = &completions
46 j.Parallelism = ¶llelism
47 j.BackoffLimit = &backoffLimit
48 j.ManualSelector = pointer.Bool(c.RandBool())
49 mode := batch.NonIndexedCompletion
50 if c.RandBool() {
51 mode = batch.IndexedCompletion
52 j.BackoffLimitPerIndex = pointer.Int32(c.Rand.Int31())
53 j.MaxFailedIndexes = pointer.Int32(c.Rand.Int31())
54 }
55 if c.RandBool() {
56 j.BackoffLimit = pointer.Int32(math.MaxInt32)
57 }
58 j.CompletionMode = &mode
59
60
61 j.Suspend = pointer.Bool(c.RandBool())
62 podReplacementPolicy := batch.TerminatingOrFailed
63 if c.RandBool() {
64 podReplacementPolicy = batch.Failed
65 }
66 j.PodReplacementPolicy = &podReplacementPolicy
67 if c.RandBool() {
68 c.Fuzz(j.ManagedBy)
69 }
70 },
71 func(sj *batch.CronJobSpec, c fuzz.Continue) {
72 c.FuzzNoCustom(sj)
73 suspend := c.RandBool()
74 sj.Suspend = &suspend
75 sds := int64(c.RandUint64())
76 sj.StartingDeadlineSeconds = &sds
77 sj.Schedule = c.RandString()
78 successfulJobsHistoryLimit := int32(c.Rand.Int31())
79 sj.SuccessfulJobsHistoryLimit = &successfulJobsHistoryLimit
80 failedJobsHistoryLimit := int32(c.Rand.Int31())
81 sj.FailedJobsHistoryLimit = &failedJobsHistoryLimit
82 },
83 func(cp *batch.ConcurrencyPolicy, c fuzz.Continue) {
84 policies := []batch.ConcurrencyPolicy{batch.AllowConcurrent, batch.ForbidConcurrent, batch.ReplaceConcurrent}
85 *cp = policies[c.Rand.Intn(len(policies))]
86 },
87 func(p *batch.PodFailurePolicyOnPodConditionsPattern, c fuzz.Continue) {
88 c.FuzzNoCustom(p)
89 if p.Status == "" {
90 p.Status = api.ConditionTrue
91 }
92 },
93 }
94 }
95
View as plain text