fuzzer.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. Copyright 2017 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package fuzzer
  14. import (
  15. fuzz "github.com/google/gofuzz"
  16. runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
  17. api "k8s.io/kubernetes/pkg/apis/core"
  18. "k8s.io/kubernetes/pkg/apis/storage"
  19. )
  20. // Funcs returns the fuzzer functions for the storage api group.
  21. var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
  22. return []interface{}{
  23. func(obj *storage.StorageClass, c fuzz.Continue) {
  24. c.FuzzNoCustom(obj) // fuzz self without calling this function again
  25. reclamationPolicies := []api.PersistentVolumeReclaimPolicy{api.PersistentVolumeReclaimDelete, api.PersistentVolumeReclaimRetain}
  26. obj.ReclaimPolicy = &reclamationPolicies[c.Rand.Intn(len(reclamationPolicies))]
  27. bindingModes := []storage.VolumeBindingMode{storage.VolumeBindingImmediate, storage.VolumeBindingWaitForFirstConsumer}
  28. obj.VolumeBindingMode = &bindingModes[c.Rand.Intn(len(bindingModes))]
  29. },
  30. func(obj *storage.CSIDriver, c fuzz.Continue) {
  31. c.FuzzNoCustom(obj) // fuzz self without calling this function again
  32. // match defaulting
  33. if obj.Spec.AttachRequired == nil {
  34. obj.Spec.AttachRequired = new(bool)
  35. *(obj.Spec.AttachRequired) = true
  36. }
  37. if obj.Spec.PodInfoOnMount == nil {
  38. obj.Spec.PodInfoOnMount = new(bool)
  39. *(obj.Spec.PodInfoOnMount) = false
  40. }
  41. },
  42. }
  43. }