defaults.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // RecommendedDefaultNodeLifecycleControllerConfiguration defaults a pointer to a
  21. // NodeLifecycleControllerConfiguration 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 RecommendedDefaultNodeLifecycleControllerConfiguration(obj *kubectrlmgrconfigv1alpha1.NodeLifecycleControllerConfiguration) {
  30. zero := metav1.Duration{}
  31. if obj.PodEvictionTimeout == zero {
  32. obj.PodEvictionTimeout = metav1.Duration{Duration: 5 * time.Minute}
  33. }
  34. if obj.NodeMonitorGracePeriod == zero {
  35. obj.NodeMonitorGracePeriod = metav1.Duration{Duration: 40 * time.Second}
  36. }
  37. if obj.NodeStartupGracePeriod == zero {
  38. obj.NodeStartupGracePeriod = metav1.Duration{Duration: 60 * time.Second}
  39. }
  40. if obj.EnableTaintManager == nil {
  41. obj.EnableTaintManager = utilpointer.BoolPtr(true)
  42. }
  43. }