defaults.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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 v1alpha1
  14. import (
  15. "path/filepath"
  16. "runtime"
  17. "time"
  18. "k8s.io/kubernetes/pkg/api"
  19. "k8s.io/kubernetes/pkg/api/unversioned"
  20. "k8s.io/kubernetes/pkg/kubelet/qos"
  21. kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
  22. "k8s.io/kubernetes/pkg/master/ports"
  23. kruntime "k8s.io/kubernetes/pkg/runtime"
  24. )
  25. const (
  26. defaultRootDir = "/var/lib/kubelet"
  27. // When these values are updated, also update test/e2e/framework/util.go
  28. defaultPodInfraContainerImageName = "gcr.io/google_containers/pause"
  29. defaultPodInfraContainerImageVersion = "3.0"
  30. defaultPodInfraContainerImage = defaultPodInfraContainerImageName +
  31. "-" + runtime.GOARCH + ":" +
  32. defaultPodInfraContainerImageVersion
  33. // From pkg/kubelet/rkt/rkt.go to avoid circular import
  34. defaultRktAPIServiceEndpoint = "localhost:15441"
  35. AutoDetectCloudProvider = "auto-detect"
  36. defaultIPTablesMasqueradeBit = 14
  37. defaultIPTablesDropBit = 15
  38. )
  39. var zeroDuration = unversioned.Duration{}
  40. func addDefaultingFuncs(scheme *kruntime.Scheme) error {
  41. return scheme.AddDefaultingFuncs(
  42. SetDefaults_KubeProxyConfiguration,
  43. SetDefaults_KubeSchedulerConfiguration,
  44. SetDefaults_LeaderElectionConfiguration,
  45. SetDefaults_KubeletConfiguration,
  46. )
  47. }
  48. func SetDefaults_KubeProxyConfiguration(obj *KubeProxyConfiguration) {
  49. if obj.BindAddress == "" {
  50. obj.BindAddress = "0.0.0.0"
  51. }
  52. if obj.HealthzPort == 0 {
  53. obj.HealthzPort = 10249
  54. }
  55. if obj.HealthzBindAddress == "" {
  56. obj.HealthzBindAddress = "127.0.0.1"
  57. }
  58. if obj.OOMScoreAdj == nil {
  59. temp := int32(qos.KubeProxyOOMScoreAdj)
  60. obj.OOMScoreAdj = &temp
  61. }
  62. if obj.ResourceContainer == "" {
  63. obj.ResourceContainer = "/kube-proxy"
  64. }
  65. if obj.IPTablesSyncPeriod.Duration == 0 {
  66. obj.IPTablesSyncPeriod = unversioned.Duration{Duration: 30 * time.Second}
  67. }
  68. zero := unversioned.Duration{}
  69. if obj.UDPIdleTimeout == zero {
  70. obj.UDPIdleTimeout = unversioned.Duration{Duration: 250 * time.Millisecond}
  71. }
  72. // If ConntrackMax is set, respect it.
  73. if obj.ConntrackMax == 0 {
  74. // If ConntrackMax is *not* set, use per-core scaling.
  75. if obj.ConntrackMaxPerCore == 0 {
  76. obj.ConntrackMaxPerCore = 32 * 1024
  77. }
  78. }
  79. if obj.IPTablesMasqueradeBit == nil {
  80. temp := int32(14)
  81. obj.IPTablesMasqueradeBit = &temp
  82. }
  83. if obj.ConntrackTCPEstablishedTimeout == zero {
  84. obj.ConntrackTCPEstablishedTimeout = unversioned.Duration{Duration: 24 * time.Hour} // 1 day (1/5 default)
  85. }
  86. }
  87. func SetDefaults_KubeSchedulerConfiguration(obj *KubeSchedulerConfiguration) {
  88. if obj.Port == 0 {
  89. obj.Port = ports.SchedulerPort
  90. }
  91. if obj.Address == "" {
  92. obj.Address = "0.0.0.0"
  93. }
  94. if obj.AlgorithmProvider == "" {
  95. obj.AlgorithmProvider = "DefaultProvider"
  96. }
  97. if obj.ContentType == "" {
  98. obj.ContentType = "application/vnd.kubernetes.protobuf"
  99. }
  100. if obj.KubeAPIQPS == 0 {
  101. obj.KubeAPIQPS = 50.0
  102. }
  103. if obj.KubeAPIBurst == 0 {
  104. obj.KubeAPIBurst = 100
  105. }
  106. if obj.SchedulerName == "" {
  107. obj.SchedulerName = api.DefaultSchedulerName
  108. }
  109. if obj.HardPodAffinitySymmetricWeight == 0 {
  110. obj.HardPodAffinitySymmetricWeight = api.DefaultHardPodAffinitySymmetricWeight
  111. }
  112. if obj.FailureDomains == "" {
  113. obj.FailureDomains = api.DefaultFailureDomains
  114. }
  115. }
  116. func SetDefaults_LeaderElectionConfiguration(obj *LeaderElectionConfiguration) {
  117. zero := unversioned.Duration{}
  118. if obj.LeaseDuration == zero {
  119. obj.LeaseDuration = unversioned.Duration{Duration: 15 * time.Second}
  120. }
  121. if obj.RenewDeadline == zero {
  122. obj.RenewDeadline = unversioned.Duration{Duration: 10 * time.Second}
  123. }
  124. if obj.RetryPeriod == zero {
  125. obj.RetryPeriod = unversioned.Duration{Duration: 2 * time.Second}
  126. }
  127. }
  128. func SetDefaults_KubeletConfiguration(obj *KubeletConfiguration) {
  129. if obj.Address == "" {
  130. obj.Address = "0.0.0.0"
  131. }
  132. if obj.CloudProvider == "" {
  133. obj.CloudProvider = AutoDetectCloudProvider
  134. }
  135. if obj.CAdvisorPort == 0 {
  136. obj.CAdvisorPort = 4194
  137. }
  138. if obj.VolumeStatsAggPeriod == zeroDuration {
  139. obj.VolumeStatsAggPeriod = unversioned.Duration{Duration: time.Minute}
  140. }
  141. if obj.CertDirectory == "" {
  142. obj.CertDirectory = "/var/run/kubernetes"
  143. }
  144. if obj.ConfigureCBR0 == nil {
  145. obj.ConfigureCBR0 = boolVar(false)
  146. }
  147. if obj.CgroupsPerQOS == nil {
  148. obj.CgroupsPerQOS = boolVar(false)
  149. }
  150. if obj.ContainerRuntime == "" {
  151. obj.ContainerRuntime = "docker"
  152. }
  153. if obj.RuntimeRequestTimeout == zeroDuration {
  154. obj.RuntimeRequestTimeout = unversioned.Duration{Duration: 2 * time.Minute}
  155. }
  156. if obj.CPUCFSQuota == nil {
  157. obj.CPUCFSQuota = boolVar(true)
  158. }
  159. if obj.DockerExecHandlerName == "" {
  160. obj.DockerExecHandlerName = "native"
  161. }
  162. if obj.DockerEndpoint == "" {
  163. obj.DockerEndpoint = "unix:///var/run/docker.sock"
  164. }
  165. if obj.EventBurst == 0 {
  166. obj.EventBurst = 10
  167. }
  168. if obj.EventRecordQPS == nil {
  169. temp := int32(5)
  170. obj.EventRecordQPS = &temp
  171. }
  172. if obj.EnableControllerAttachDetach == nil {
  173. obj.EnableControllerAttachDetach = boolVar(true)
  174. }
  175. if obj.EnableDebuggingHandlers == nil {
  176. obj.EnableDebuggingHandlers = boolVar(true)
  177. }
  178. if obj.EnableServer == nil {
  179. obj.EnableServer = boolVar(true)
  180. }
  181. if obj.FileCheckFrequency == zeroDuration {
  182. obj.FileCheckFrequency = unversioned.Duration{Duration: 20 * time.Second}
  183. }
  184. if obj.HealthzBindAddress == "" {
  185. obj.HealthzBindAddress = "127.0.0.1"
  186. }
  187. if obj.HealthzPort == 0 {
  188. obj.HealthzPort = 10248
  189. }
  190. if obj.HostNetworkSources == nil {
  191. obj.HostNetworkSources = []string{kubetypes.AllSource}
  192. }
  193. if obj.HostPIDSources == nil {
  194. obj.HostPIDSources = []string{kubetypes.AllSource}
  195. }
  196. if obj.HostIPCSources == nil {
  197. obj.HostIPCSources = []string{kubetypes.AllSource}
  198. }
  199. if obj.HTTPCheckFrequency == zeroDuration {
  200. obj.HTTPCheckFrequency = unversioned.Duration{Duration: 20 * time.Second}
  201. }
  202. if obj.ImageMinimumGCAge == zeroDuration {
  203. obj.ImageMinimumGCAge = unversioned.Duration{Duration: 2 * time.Minute}
  204. }
  205. if obj.ImageGCHighThresholdPercent == nil {
  206. temp := int32(90)
  207. obj.ImageGCHighThresholdPercent = &temp
  208. }
  209. if obj.ImageGCLowThresholdPercent == nil {
  210. temp := int32(80)
  211. obj.ImageGCLowThresholdPercent = &temp
  212. }
  213. if obj.LowDiskSpaceThresholdMB == 0 {
  214. obj.LowDiskSpaceThresholdMB = 256
  215. }
  216. if obj.MasterServiceNamespace == "" {
  217. obj.MasterServiceNamespace = api.NamespaceDefault
  218. }
  219. if obj.MaxContainerCount == nil {
  220. temp := int32(-1)
  221. obj.MaxContainerCount = &temp
  222. }
  223. if obj.MaxPerPodContainerCount == 0 {
  224. obj.MaxPerPodContainerCount = 1
  225. }
  226. if obj.MaxOpenFiles == 0 {
  227. obj.MaxOpenFiles = 1000000
  228. }
  229. if obj.MaxPods == 0 {
  230. obj.MaxPods = 110
  231. }
  232. if obj.MinimumGCAge == zeroDuration {
  233. obj.MinimumGCAge = unversioned.Duration{Duration: 0}
  234. }
  235. if obj.NetworkPluginDir == "" {
  236. obj.NetworkPluginDir = "/usr/libexec/kubernetes/kubelet-plugins/net/exec/"
  237. }
  238. if obj.NonMasqueradeCIDR == "" {
  239. obj.NonMasqueradeCIDR = "10.0.0.0/8"
  240. }
  241. if obj.VolumePluginDir == "" {
  242. obj.VolumePluginDir = "/usr/libexec/kubernetes/kubelet-plugins/volume/exec/"
  243. }
  244. if obj.NodeStatusUpdateFrequency == zeroDuration {
  245. obj.NodeStatusUpdateFrequency = unversioned.Duration{Duration: 10 * time.Second}
  246. }
  247. if obj.OOMScoreAdj == nil {
  248. temp := int32(qos.KubeletOOMScoreAdj)
  249. obj.OOMScoreAdj = &temp
  250. }
  251. if obj.PodInfraContainerImage == "" {
  252. obj.PodInfraContainerImage = defaultPodInfraContainerImage
  253. }
  254. if obj.Port == 0 {
  255. obj.Port = ports.KubeletPort
  256. }
  257. if obj.ReadOnlyPort == 0 {
  258. obj.ReadOnlyPort = ports.KubeletReadOnlyPort
  259. }
  260. if obj.RegisterNode == nil {
  261. obj.RegisterNode = boolVar(true)
  262. }
  263. if obj.RegisterSchedulable == nil {
  264. obj.RegisterSchedulable = boolVar(true)
  265. }
  266. if obj.RegistryBurst == 0 {
  267. obj.RegistryBurst = 10
  268. }
  269. if obj.RegistryPullQPS == nil {
  270. temp := int32(5)
  271. obj.RegistryPullQPS = &temp
  272. }
  273. if obj.ResolverConfig == "" {
  274. obj.ResolverConfig = kubetypes.ResolvConfDefault
  275. }
  276. if obj.RktAPIEndpoint == "" {
  277. obj.RktAPIEndpoint = defaultRktAPIServiceEndpoint
  278. }
  279. if obj.RootDirectory == "" {
  280. obj.RootDirectory = defaultRootDir
  281. }
  282. if obj.SerializeImagePulls == nil {
  283. obj.SerializeImagePulls = boolVar(true)
  284. }
  285. if obj.SeccompProfileRoot == "" {
  286. filepath.Join(defaultRootDir, "seccomp")
  287. }
  288. if obj.StreamingConnectionIdleTimeout == zeroDuration {
  289. obj.StreamingConnectionIdleTimeout = unversioned.Duration{Duration: 4 * time.Hour}
  290. }
  291. if obj.SyncFrequency == zeroDuration {
  292. obj.SyncFrequency = unversioned.Duration{Duration: 1 * time.Minute}
  293. }
  294. if obj.ReconcileCIDR == nil {
  295. obj.ReconcileCIDR = boolVar(true)
  296. }
  297. if obj.ContentType == "" {
  298. obj.ContentType = "application/vnd.kubernetes.protobuf"
  299. }
  300. if obj.KubeAPIQPS == nil {
  301. temp := int32(5)
  302. obj.KubeAPIQPS = &temp
  303. }
  304. if obj.KubeAPIBurst == 0 {
  305. obj.KubeAPIBurst = 10
  306. }
  307. if obj.OutOfDiskTransitionFrequency == zeroDuration {
  308. obj.OutOfDiskTransitionFrequency = unversioned.Duration{Duration: 5 * time.Minute}
  309. }
  310. if string(obj.HairpinMode) == "" {
  311. obj.HairpinMode = PromiscuousBridge
  312. }
  313. if obj.EvictionHard == nil {
  314. temp := "memory.available<100Mi"
  315. obj.EvictionHard = &temp
  316. }
  317. if obj.EvictionPressureTransitionPeriod == zeroDuration {
  318. obj.EvictionPressureTransitionPeriod = unversioned.Duration{Duration: 5 * time.Minute}
  319. }
  320. if obj.SystemReserved == nil {
  321. obj.SystemReserved = make(map[string]string)
  322. }
  323. if obj.KubeReserved == nil {
  324. obj.KubeReserved = make(map[string]string)
  325. }
  326. if obj.MakeIPTablesUtilChains == nil {
  327. obj.MakeIPTablesUtilChains = boolVar(true)
  328. }
  329. if obj.IPTablesMasqueradeBit == nil {
  330. temp := int32(defaultIPTablesMasqueradeBit)
  331. obj.IPTablesMasqueradeBit = &temp
  332. }
  333. if obj.IPTablesDropBit == nil {
  334. temp := int32(defaultIPTablesDropBit)
  335. obj.IPTablesDropBit = &temp
  336. }
  337. }
  338. func boolVar(b bool) *bool {
  339. return &b
  340. }
  341. var (
  342. defaultCfg = KubeletConfiguration{}
  343. )