defaults.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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: 5 * 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.TopologyManagerPolicy == "" {
  143. obj.TopologyManagerPolicy = kubeletconfigv1beta1.NoneTopologyManagerPolicy
  144. }
  145. if obj.RuntimeRequestTimeout == zeroDuration {
  146. obj.RuntimeRequestTimeout = metav1.Duration{Duration: 2 * time.Minute}
  147. }
  148. if obj.HairpinMode == "" {
  149. obj.HairpinMode = kubeletconfigv1beta1.PromiscuousBridge
  150. }
  151. if obj.MaxPods == 0 {
  152. obj.MaxPods = 110
  153. }
  154. // default nil or negative value to -1 (implies node allocatable pid limit)
  155. if obj.PodPidsLimit == nil || *obj.PodPidsLimit < int64(0) {
  156. temp := int64(-1)
  157. obj.PodPidsLimit = &temp
  158. }
  159. if obj.ResolverConfig == "" {
  160. obj.ResolverConfig = kubetypes.ResolvConfDefault
  161. }
  162. if obj.CPUCFSQuota == nil {
  163. obj.CPUCFSQuota = utilpointer.BoolPtr(true)
  164. }
  165. if obj.CPUCFSQuotaPeriod == nil {
  166. obj.CPUCFSQuotaPeriod = &metav1.Duration{Duration: 100 * time.Millisecond}
  167. }
  168. if obj.MaxOpenFiles == 0 {
  169. obj.MaxOpenFiles = 1000000
  170. }
  171. if obj.ContentType == "" {
  172. obj.ContentType = "application/vnd.kubernetes.protobuf"
  173. }
  174. if obj.KubeAPIQPS == nil {
  175. obj.KubeAPIQPS = utilpointer.Int32Ptr(5)
  176. }
  177. if obj.KubeAPIBurst == 0 {
  178. obj.KubeAPIBurst = 10
  179. }
  180. if obj.SerializeImagePulls == nil {
  181. obj.SerializeImagePulls = utilpointer.BoolPtr(true)
  182. }
  183. if obj.EvictionHard == nil {
  184. obj.EvictionHard = DefaultEvictionHard
  185. }
  186. if obj.EvictionPressureTransitionPeriod == zeroDuration {
  187. obj.EvictionPressureTransitionPeriod = metav1.Duration{Duration: 5 * time.Minute}
  188. }
  189. if obj.EnableControllerAttachDetach == nil {
  190. obj.EnableControllerAttachDetach = utilpointer.BoolPtr(true)
  191. }
  192. if obj.MakeIPTablesUtilChains == nil {
  193. obj.MakeIPTablesUtilChains = utilpointer.BoolPtr(true)
  194. }
  195. if obj.IPTablesMasqueradeBit == nil {
  196. obj.IPTablesMasqueradeBit = utilpointer.Int32Ptr(DefaultIPTablesMasqueradeBit)
  197. }
  198. if obj.IPTablesDropBit == nil {
  199. obj.IPTablesDropBit = utilpointer.Int32Ptr(DefaultIPTablesDropBit)
  200. }
  201. if obj.FailSwapOn == nil {
  202. obj.FailSwapOn = utilpointer.BoolPtr(true)
  203. }
  204. if obj.ContainerLogMaxSize == "" {
  205. obj.ContainerLogMaxSize = "10Mi"
  206. }
  207. if obj.ContainerLogMaxFiles == nil {
  208. obj.ContainerLogMaxFiles = utilpointer.Int32Ptr(5)
  209. }
  210. if obj.ConfigMapAndSecretChangeDetectionStrategy == "" {
  211. obj.ConfigMapAndSecretChangeDetectionStrategy = kubeletconfigv1beta1.WatchChangeDetectionStrategy
  212. }
  213. if obj.EnforceNodeAllocatable == nil {
  214. obj.EnforceNodeAllocatable = DefaultNodeAllocatableEnforcement
  215. }
  216. }