defaults.go 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. Copyright 2019 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 v1alpha1
  14. import (
  15. "time"
  16. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  17. kubectrlmgrconfigv1alpha1 "k8s.io/kube-controller-manager/config/v1alpha1"
  18. utilpointer "k8s.io/utils/pointer"
  19. )
  20. // RecommendedDefaultPersistentVolumeBinderControllerConfiguration defaults a pointer to a
  21. // PersistentVolumeBinderControllerConfiguration struct. This will set the recommended default
  22. // values, but they may be subject to change between API versions. This function
  23. // is intentionally not registered in the scheme as a "normal" `SetDefaults_Foo`
  24. // function to allow consumers of this type to set whatever defaults for their
  25. // embedded configs. Forcing consumers to use these defaults would be problematic
  26. // as defaulting in the scheme is done as part of the conversion, and there would
  27. // be no easy way to opt-out. Instead, if you want to use this defaulting method
  28. // run it in your wrapper struct of this type in its `SetDefaults_` method.
  29. func RecommendedDefaultPersistentVolumeBinderControllerConfiguration(obj *kubectrlmgrconfigv1alpha1.PersistentVolumeBinderControllerConfiguration) {
  30. zero := metav1.Duration{}
  31. if obj.PVClaimBinderSyncPeriod == zero {
  32. obj.PVClaimBinderSyncPeriod = metav1.Duration{Duration: 15 * time.Second}
  33. }
  34. // Use the default VolumeConfiguration options.
  35. RecommendedDefaultVolumeConfiguration(&obj.VolumeConfiguration)
  36. }
  37. // RecommendedDefaultVolumeConfiguration defaults a pointer to a VolumeConfiguration
  38. // struct. This will set the recommended default values, but they may be subject to
  39. // change between API versions. This function is intentionally not registered in the
  40. // scheme as a "normal" `SetDefaults_Foo` function to allow consumers of this type to
  41. // set whatever defaults for their embedded configs. Forcing consumers to use these
  42. // defaults would be problematic as defaulting in the scheme is done as part of the
  43. // conversion, and there would be no easy way to opt-out. Instead, if you want to use
  44. // this defaulting method run it in your wrapper struct of this type in its `SetDefaults_` method.
  45. func RecommendedDefaultVolumeConfiguration(obj *kubectrlmgrconfigv1alpha1.VolumeConfiguration) {
  46. if obj.EnableHostPathProvisioning == nil {
  47. obj.EnableHostPathProvisioning = utilpointer.BoolPtr(false)
  48. }
  49. if obj.EnableDynamicProvisioning == nil {
  50. obj.EnableDynamicProvisioning = utilpointer.BoolPtr(true)
  51. }
  52. if obj.FlexVolumePluginDir == "" {
  53. obj.FlexVolumePluginDir = "/usr/libexec/kubernetes/kubelet-plugins/volume/exec/"
  54. }
  55. // Use the default PersistentVolumeRecyclerConfiguration options.
  56. RecommendedDefaultPersistentVolumeRecyclerConfiguration(&obj.PersistentVolumeRecyclerConfiguration)
  57. }
  58. // RecommendedDefaultPersistentVolumeRecyclerConfiguration defaults a pointer to a
  59. // PersistentVolumeRecyclerConfiguration struct. This will set the recommended default
  60. // values, but they may be subject to change between API versions. This function
  61. // is intentionally not registered in the scheme as a "normal" `SetDefaults_Foo`
  62. // function to allow consumers of this type to set whatever defaults for their
  63. // embedded configs. Forcing consumers to use these defaults would be problematic
  64. // as defaulting in the scheme is done as part of the conversion, and there would
  65. // be no easy way to opt-out. Instead, if you want to use this defaulting method
  66. // run it in your wrapper struct of this type in its `SetDefaults_` method.
  67. func RecommendedDefaultPersistentVolumeRecyclerConfiguration(obj *kubectrlmgrconfigv1alpha1.PersistentVolumeRecyclerConfiguration) {
  68. if obj.MaximumRetry == 0 {
  69. obj.MaximumRetry = 3
  70. }
  71. if obj.MinimumTimeoutNFS == 0 {
  72. obj.MinimumTimeoutNFS = 300
  73. }
  74. if obj.IncrementTimeoutNFS == 0 {
  75. obj.IncrementTimeoutNFS = 30
  76. }
  77. if obj.MinimumTimeoutHostPath == 0 {
  78. obj.MinimumTimeoutHostPath = 60
  79. }
  80. if obj.IncrementTimeoutHostPath == 0 {
  81. obj.IncrementTimeoutHostPath = 30
  82. }
  83. }