defaults.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. Copyright 2016 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 v1
  14. import (
  15. "k8s.io/kubernetes/pkg/runtime"
  16. )
  17. func addDefaultingFuncs(scheme *runtime.Scheme) error {
  18. return scheme.AddDefaultingFuncs(
  19. SetDefaults_Job,
  20. )
  21. }
  22. func SetDefaults_Job(obj *Job) {
  23. // For a non-parallel job, you can leave both `.spec.completions` and
  24. // `.spec.parallelism` unset. When both are unset, both are defaulted to 1.
  25. if obj.Spec.Completions == nil && obj.Spec.Parallelism == nil {
  26. obj.Spec.Completions = new(int32)
  27. *obj.Spec.Completions = 1
  28. obj.Spec.Parallelism = new(int32)
  29. *obj.Spec.Parallelism = 1
  30. }
  31. if obj.Spec.Parallelism == nil {
  32. obj.Spec.Parallelism = new(int32)
  33. *obj.Spec.Parallelism = 1
  34. }
  35. }