defaults.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. Copyright 2015 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 v1beta1
  14. import (
  15. "time"
  16. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  17. kruntime "k8s.io/apimachinery/pkg/runtime"
  18. kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
  19. // TODO: Cut references to k8s.io/kubernetes, eventually there should be none from this package
  20. "k8s.io/kubernetes/pkg/kubelet/qos"
  21. kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
  22. "k8s.io/kubernetes/pkg/master/ports"
  23. utilpointer "k8s.io/utils/pointer"
  24. )
  25. const (
  26. // TODO: Move these constants to k8s.io/kubelet/config/v1beta1 instead?
  27. DefaultIPTablesMasqueradeBit = 14
  28. DefaultIPTablesDropBit = 15
  29. )
  30. var (
  31. zeroDuration = metav1.Duration{}
  32. // TODO: Move these constants to k8s.io/kubelet/config/v1beta1 instead?
  33. // Refer to [Node Allocatable](https://git.k8s.io/community/contributors/design-proposals/node/node-allocatable.md) doc for more information.
  34. DefaultNodeAllocatableEnforcement = []string{"pods"}
  35. )
  36. func addDefaultingFuncs(scheme *kruntime.Scheme) error {
  37. return RegisterDefaults(scheme)
  38. }
  39. func SetDefaults_KubeletConfiguration(obj *kubeletconfigv1beta1.KubeletConfiguration) {
  40. if obj.SyncFrequency == zeroDuration {
  41. obj.SyncFrequency = metav1.Duration{Duration: 1 * time.Minute}
  42. }
  43. if obj.FileCheckFrequency == zeroDuration {
  44. obj.FileCheckFrequency = metav1.Duration{Duration: 20 * time.Second}
  45. }
  46. if obj.HTTPCheckFrequency == zeroDuration {
  47. obj.HTTPCheckFrequency = metav1.Duration{Duration: 20 * time.Second}
  48. }
  49. if obj.Address == "" {
  50. obj.Address = "0.0.0.0"
  51. }
  52. if obj.Port == 0 {
  53. obj.Port = ports.KubeletPort
  54. }
  55. if obj.Authentication.Anonymous.Enabled == nil {
  56. obj.Authentication.Anonymous.Enabled = utilpointer.BoolPtr(false)
  57. }
  58. if obj.Authentication.Webhook.Enabled == nil {
  59. obj.Authentication.Webhook.Enabled = utilpointer.BoolPtr(true)
  60. }
  61. if obj.Authentication.Webhook.CacheTTL == zeroDuration {
  62. obj.Authentication.Webhook.CacheTTL = metav1.Duration{Duration: 2 * time.Minute}
  63. }
  64. if obj.Authorization.Mode == "" {
  65. obj.Authorization.Mode = kubeletconfigv1beta1.KubeletAuthorizationModeWebhook
  66. }
  67. if obj.Authorization.Webhook.CacheAuthorizedTTL == zeroDuration {
  68. obj.Authorization.Webhook.CacheAuthorizedTTL = metav1.Duration{Duration: 5 * time.Minute}
  69. }
  70. if obj.Authorization.Webhook.CacheUnauthorizedTTL == zeroDuration {
  71. obj.Authorization.Webhook.CacheUnauthorizedTTL = metav1.Duration{Duration: 30 * time.Second}
  72. }
  73. if obj.RegistryPullQPS == nil {
  74. obj.RegistryPullQPS = utilpointer.Int32Ptr(5)
  75. }
  76. if obj.RegistryBurst == 0 {
  77. obj.RegistryBurst = 10
  78. }
  79. if obj.EventRecordQPS == nil {
  80. obj.EventRecordQPS = utilpointer.Int32Ptr(5)
  81. }
  82. if obj.EventBurst == 0 {
  83. obj.EventBurst = 10
  84. }
  85. if obj.EnableDebuggingHandlers == nil {
  86. obj.EnableDebuggingHandlers = utilpointer.BoolPtr(true)
  87. }
  88. if obj.HealthzPort == nil {
  89. obj.HealthzPort = utilpointer.Int32Ptr(10248)
  90. }
  91. if obj.HealthzBindAddress == "" {
  92. obj.HealthzBindAddress = "127.0.0.1"
  93. }
  94. if obj.OOMScoreAdj == nil {
  95. obj.OOMScoreAdj = utilpointer.Int32Ptr(int32(qos.KubeletOOMScoreAdj))
  96. }
  97. if obj.StreamingConnectionIdleTimeout == zeroDuration {
  98. obj.StreamingConnectionIdleTimeout = metav1.Duration{Duration: 4 * time.Hour}
  99. }
  100. if obj.NodeStatusReportFrequency == zeroDuration {
  101. // For backward compatibility, NodeStatusReportFrequency's default value is
  102. // set to NodeStatusUpdateFrequency if NodeStatusUpdateFrequency is set
  103. // explicitly.
  104. if obj.NodeStatusUpdateFrequency == zeroDuration {
  105. obj.NodeStatusReportFrequency = metav1.Duration{Duration: time.Minute}
  106. } else {
  107. obj.NodeStatusReportFrequency = obj.NodeStatusUpdateFrequency
  108. }
  109. }
  110. if obj.NodeStatusUpdateFrequency == zeroDuration {
  111. obj.NodeStatusUpdateFrequency = metav1.Duration{Duration: 10 * time.Second}
  112. }
  113. if obj.NodeLeaseDurationSeconds == 0 {
  114. obj.NodeLeaseDurationSeconds = 40
  115. }
  116. if obj.ImageMinimumGCAge == zeroDuration {
  117. obj.ImageMinimumGCAge = metav1.Duration{Duration: 2 * time.Minute}
  118. }
  119. if obj.ImageGCHighThresholdPercent == nil {
  120. // default is below docker's default dm.min_free_space of 90%
  121. obj.ImageGCHighThresholdPercent = utilpointer.Int32Ptr(85)
  122. }
  123. if obj.ImageGCLowThresholdPercent == nil {
  124. obj.ImageGCLowThresholdPercent = utilpointer.Int32Ptr(80)
  125. }
  126. if obj.VolumeStatsAggPeriod == zeroDuration {
  127. obj.VolumeStatsAggPeriod = metav1.Duration{Duration: time.Minute}
  128. }
  129. if obj.CgroupsPerQOS == nil {
  130. obj.CgroupsPerQOS = utilpointer.BoolPtr(true)
  131. }
  132. if obj.CgroupDriver == "" {
  133. obj.CgroupDriver = "cgroupfs"
  134. }
  135. if obj.CPUManagerPolicy == "" {
  136. obj.CPUManagerPolicy = "none"
  137. }
  138. if obj.CPUManagerReconcilePeriod == zeroDuration {
  139. // Keep the same as default NodeStatusUpdateFrequency
  140. obj.CPUManagerReconcilePeriod = metav1.Duration{Duration: 10 * time.Second}
  141. }
  142. if obj.RuntimeRequestTimeout == zeroDuration {
  143. obj.RuntimeRequestTimeout = metav1.Duration{Duration: 2 * time.Minute}
  144. }
  145. if obj.HairpinMode == "" {
  146. obj.HairpinMode = kubeletconfigv1beta1.PromiscuousBridge
  147. }
  148. if obj.MaxPods == 0 {
  149. obj.MaxPods = 110
  150. }
  151. // default nil or negative value to -1 (implies node allocatable pid limit)
  152. if obj.PodPidsLimit == nil || *obj.PodPidsLimit < int64(0) {
  153. temp := int64(-1)
  154. obj.PodPidsLimit = &temp
  155. }
  156. if obj.ResolverConfig == "" {
  157. obj.ResolverConfig = kubetypes.ResolvConfDefault
  158. }
  159. if obj.CPUCFSQuota == nil {
  160. obj.CPUCFSQuota = utilpointer.BoolPtr(true)
  161. }
  162. if obj.CPUCFSQuotaPeriod == nil {
  163. obj.CPUCFSQuotaPeriod = &metav1.Duration{Duration: 100 * time.Millisecond}
  164. }
  165. if obj.MaxOpenFiles == 0 {
  166. obj.MaxOpenFiles = 1000000
  167. }
  168. if obj.ContentType == "" {
  169. obj.ContentType = "application/vnd.kubernetes.protobuf"
  170. }
  171. if obj.KubeAPIQPS == nil {
  172. obj.KubeAPIQPS = utilpointer.Int32Ptr(5)
  173. }
  174. if obj.KubeAPIBurst == 0 {
  175. obj.KubeAPIBurst = 10
  176. }
  177. if obj.SerializeImagePulls == nil {
  178. obj.SerializeImagePulls = utilpointer.BoolPtr(true)
  179. }
  180. if obj.EvictionHard == nil {
  181. obj.EvictionHard = DefaultEvictionHard
  182. }
  183. if obj.EvictionPressureTransitionPeriod == zeroDuration {
  184. obj.EvictionPressureTransitionPeriod = metav1.Duration{Duration: 5 * time.Minute}
  185. }
  186. if obj.EnableControllerAttachDetach == nil {
  187. obj.EnableControllerAttachDetach = utilpointer.BoolPtr(true)
  188. }
  189. if obj.MakeIPTablesUtilChains == nil {
  190. obj.MakeIPTablesUtilChains = utilpointer.BoolPtr(true)
  191. }
  192. if obj.IPTablesMasqueradeBit == nil {
  193. obj.IPTablesMasqueradeBit = utilpointer.Int32Ptr(DefaultIPTablesMasqueradeBit)
  194. }
  195. if obj.IPTablesDropBit == nil {
  196. obj.IPTablesDropBit = utilpointer.Int32Ptr(DefaultIPTablesDropBit)
  197. }
  198. if obj.FailSwapOn == nil {
  199. obj.FailSwapOn = utilpointer.BoolPtr(true)
  200. }
  201. if obj.ContainerLogMaxSize == "" {
  202. obj.ContainerLogMaxSize = "10Mi"
  203. }
  204. if obj.ContainerLogMaxFiles == nil {
  205. obj.ContainerLogMaxFiles = utilpointer.Int32Ptr(5)
  206. }
  207. if obj.ConfigMapAndSecretChangeDetectionStrategy == "" {
  208. obj.ConfigMapAndSecretChangeDetectionStrategy = kubeletconfigv1beta1.WatchChangeDetectionStrategy
  209. }
  210. if obj.EnforceNodeAllocatable == nil {
  211. obj.EnforceNodeAllocatable = DefaultNodeAllocatableEnforcement
  212. }
  213. }