1 /* 2 Copyright 2018 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package v1alpha1 18 19 import ( 20 "time" 21 22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 utilpointer "k8s.io/utils/pointer" 24 ) 25 26 // RecommendedDefaultLeaderElectionConfiguration defaults a pointer to a 27 // LeaderElectionConfiguration struct. This will set the recommended default 28 // values, but they may be subject to change between API versions. This function 29 // is intentionally not registered in the scheme as a "normal" `SetDefaults_Foo` 30 // function to allow consumers of this type to set whatever defaults for their 31 // embedded configs. Forcing consumers to use these defaults would be problematic 32 // as defaulting in the scheme is done as part of the conversion, and there would 33 // be no easy way to opt-out. Instead, if you want to use this defaulting method 34 // run it in your wrapper struct of this type in its `SetDefaults_` method. 35 func RecommendedDefaultLeaderElectionConfiguration(obj *LeaderElectionConfiguration) { 36 zero := metav1.Duration{} 37 if obj.LeaseDuration == zero { 38 obj.LeaseDuration = metav1.Duration{Duration: 15 * time.Second} 39 } 40 if obj.RenewDeadline == zero { 41 obj.RenewDeadline = metav1.Duration{Duration: 10 * time.Second} 42 } 43 if obj.RetryPeriod == zero { 44 obj.RetryPeriod = metav1.Duration{Duration: 2 * time.Second} 45 } 46 if obj.ResourceLock == "" { 47 // TODO(#80289): Figure out how to migrate to LeaseLock at this point. 48 // This will most probably require going through EndpointsLease first. 49 obj.ResourceLock = EndpointsResourceLock 50 } 51 if obj.LeaderElect == nil { 52 obj.LeaderElect = utilpointer.BoolPtr(true) 53 } 54 } 55 56 // RecommendedDefaultClientConnectionConfiguration defaults a pointer to a 57 // ClientConnectionConfiguration struct. This will set the recommended default 58 // values, but they may be subject to change between API versions. This function 59 // is intentionally not registered in the scheme as a "normal" `SetDefaults_Foo` 60 // function to allow consumers of this type to set whatever defaults for their 61 // embedded configs. Forcing consumers to use these defaults would be problematic 62 // as defaulting in the scheme is done as part of the conversion, and there would 63 // be no easy way to opt-out. Instead, if you want to use this defaulting method 64 // run it in your wrapper struct of this type in its `SetDefaults_` method. 65 func RecommendedDefaultClientConnectionConfiguration(obj *ClientConnectionConfiguration) { 66 if len(obj.ContentType) == 0 { 67 obj.ContentType = "application/vnd.kubernetes.protobuf" 68 } 69 if obj.QPS == 0.0 { 70 obj.QPS = 50.0 71 } 72 if obj.Burst == 0 { 73 obj.Burst = 100 74 } 75 } 76 77 // RecommendedDebuggingConfiguration defaults profiling and debugging configuration. 78 // This will set the recommended default 79 // values, but they may be subject to change between API versions. This function 80 // is intentionally not registered in the scheme as a "normal" `SetDefaults_Foo` 81 // function to allow consumers of this type to set whatever defaults for their 82 // embedded configs. Forcing consumers to use these defaults would be problematic 83 // as defaulting in the scheme is done as part of the conversion, and there would 84 // be no easy way to opt-out. Instead, if you want to use this defaulting method 85 // run it in your wrapper struct of this type in its `SetDefaults_` method. 86 func RecommendedDebuggingConfiguration(obj *DebuggingConfiguration) { 87 if obj.EnableProfiling == nil { 88 obj.EnableProfiling = utilpointer.BoolPtr(true) // profile debugging is cheap to have exposed and standard on kube binaries 89 } 90 } 91 92 // NewRecommendedDebuggingConfiguration returns the current recommended DebuggingConfiguration. 93 // This may change between releases as recommendations shift. 94 func NewRecommendedDebuggingConfiguration() *DebuggingConfiguration { 95 ret := &DebuggingConfiguration{} 96 RecommendedDebuggingConfiguration(ret) 97 return ret 98 } 99