-
Notifications
You must be signed in to change notification settings - Fork 459
/
kubelet.go
225 lines (200 loc) · 8.39 KB
/
kubelet.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// Copyright (c) 2021 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package components
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
)
// ConfigurableKubeletCLIFlags is the set of configurable kubelet command line parameters.
type ConfigurableKubeletCLIFlags struct {
ImagePullProgressDeadline *metav1.Duration
}
// KubeletCLIFlagsFromCoreV1beta1KubeletConfig computes the ConfigurableKubeletCLIFlags based on the provided
// gardencorev1beta1.KubeletConfig.
func KubeletCLIFlagsFromCoreV1beta1KubeletConfig(kubeletConfig *gardencorev1beta1.KubeletConfig) ConfigurableKubeletCLIFlags {
var out ConfigurableKubeletCLIFlags
if kubeletConfig != nil {
out.ImagePullProgressDeadline = kubeletConfig.ImagePullProgressDeadline
}
return out
}
// ConfigurableKubeletConfigParameters is the set of configurable kubelet config parameters.
type ConfigurableKubeletConfigParameters struct {
ContainerLogMaxSize *string
ContainerLogMaxFiles *int32
CpuCFSQuota *bool
CpuManagerPolicy *string
EvictionHard map[string]string
EvictionMinimumReclaim map[string]string
EvictionSoft map[string]string
EvictionSoftGracePeriod map[string]string
EvictionPressureTransitionPeriod *metav1.Duration
EvictionMaxPodGracePeriod *int32
FailSwapOn *bool
FeatureGates map[string]bool
ImageGCHighThresholdPercent *int32
ImageGCLowThresholdPercent *int32
SeccompDefault *bool
SerializeImagePulls *bool
StreamingConnectionIdleTimeout *metav1.Duration
RegistryPullQPS *int32
RegistryBurst *int32
KubeReserved map[string]string
MaxPods *int32
PodPidsLimit *int64
ProtectKernelDefaults *bool
SystemReserved map[string]string
}
const (
// MemoryAvailable is a constant for the 'memory.available' eviction setting.
MemoryAvailable = "memory.available"
// ImageFSAvailable is a constant for the 'imagefs.available' eviction setting.
ImageFSAvailable = "imagefs.available"
// ImageFSInodesFree is a constant for the 'imagefs.inodesFree' eviction setting.
ImageFSInodesFree = "imagefs.inodesFree"
// NodeFSAvailable is a constant for the 'nodefs.available' eviction setting.
NodeFSAvailable = "nodefs.available"
// NodeFSInodesFree is a constant for the 'nodefs.inodesFree' eviction setting.
NodeFSInodesFree = "nodefs.inodesFree"
)
// KubeletConfigParametersFromCoreV1beta1KubeletConfig computes the ConfigurableKubeletConfigParameters based on the provided
// gardencorev1beta1.KubeletConfig.
func KubeletConfigParametersFromCoreV1beta1KubeletConfig(kubeletConfig *gardencorev1beta1.KubeletConfig) ConfigurableKubeletConfigParameters {
var out ConfigurableKubeletConfigParameters
if kubeletConfig != nil {
out.ContainerLogMaxFiles = kubeletConfig.ContainerLogMaxFiles
if val := kubeletConfig.ContainerLogMaxSize; val != nil {
out.ContainerLogMaxSize = pointer.String(val.String())
}
out.CpuCFSQuota = kubeletConfig.CPUCFSQuota
out.CpuManagerPolicy = kubeletConfig.CPUManagerPolicy
out.EvictionMaxPodGracePeriod = kubeletConfig.EvictionMaxPodGracePeriod
out.EvictionPressureTransitionPeriod = kubeletConfig.EvictionPressureTransitionPeriod
out.FailSwapOn = kubeletConfig.FailSwapOn
out.ImageGCHighThresholdPercent = kubeletConfig.ImageGCHighThresholdPercent
out.ImageGCLowThresholdPercent = kubeletConfig.ImageGCLowThresholdPercent
out.SeccompDefault = kubeletConfig.SeccompDefault
out.SerializeImagePulls = kubeletConfig.SerializeImagePulls
out.RegistryPullQPS = kubeletConfig.RegistryPullQPS
out.RegistryBurst = kubeletConfig.RegistryBurst
out.FeatureGates = kubeletConfig.FeatureGates
out.KubeReserved = reservedFromKubeletConfig(kubeletConfig.KubeReserved)
out.MaxPods = kubeletConfig.MaxPods
out.PodPidsLimit = kubeletConfig.PodPIDsLimit
out.ProtectKernelDefaults = kubeletConfig.ProtectKernelDefaults
out.StreamingConnectionIdleTimeout = kubeletConfig.StreamingConnectionIdleTimeout
out.SystemReserved = reservedFromKubeletConfig(kubeletConfig.SystemReserved)
if eviction := kubeletConfig.EvictionHard; eviction != nil {
if out.EvictionHard == nil {
out.EvictionHard = make(map[string]string)
}
if val := eviction.MemoryAvailable; val != nil {
out.EvictionHard[MemoryAvailable] = *val
}
if val := eviction.ImageFSAvailable; val != nil {
out.EvictionHard[ImageFSAvailable] = *val
}
if val := eviction.ImageFSInodesFree; val != nil {
out.EvictionHard[ImageFSInodesFree] = *val
}
if val := eviction.NodeFSAvailable; val != nil {
out.EvictionHard[NodeFSAvailable] = *val
}
if val := eviction.NodeFSInodesFree; val != nil {
out.EvictionHard[NodeFSInodesFree] = *val
}
}
if eviction := kubeletConfig.EvictionSoft; eviction != nil {
if out.EvictionSoft == nil {
out.EvictionSoft = make(map[string]string)
}
if val := eviction.MemoryAvailable; val != nil {
out.EvictionSoft[MemoryAvailable] = *val
}
if val := eviction.ImageFSAvailable; val != nil {
out.EvictionSoft[ImageFSAvailable] = *val
}
if val := eviction.ImageFSInodesFree; val != nil {
out.EvictionSoft[ImageFSInodesFree] = *val
}
if val := eviction.NodeFSAvailable; val != nil {
out.EvictionSoft[NodeFSAvailable] = *val
}
if val := eviction.NodeFSInodesFree; val != nil {
out.EvictionSoft[NodeFSInodesFree] = *val
}
}
if eviction := kubeletConfig.EvictionMinimumReclaim; eviction != nil {
if out.EvictionMinimumReclaim == nil {
out.EvictionMinimumReclaim = make(map[string]string)
}
if val := eviction.MemoryAvailable; val != nil {
out.EvictionMinimumReclaim[MemoryAvailable] = val.String()
}
if val := eviction.ImageFSAvailable; val != nil {
out.EvictionMinimumReclaim[ImageFSAvailable] = val.String()
}
if val := eviction.ImageFSInodesFree; val != nil {
out.EvictionMinimumReclaim[ImageFSInodesFree] = val.String()
}
if val := eviction.NodeFSAvailable; val != nil {
out.EvictionMinimumReclaim[NodeFSAvailable] = val.String()
}
if val := eviction.NodeFSInodesFree; val != nil {
out.EvictionMinimumReclaim[NodeFSInodesFree] = val.String()
}
}
if eviction := kubeletConfig.EvictionSoftGracePeriod; eviction != nil {
if out.EvictionSoftGracePeriod == nil {
out.EvictionSoftGracePeriod = make(map[string]string)
}
if val := eviction.MemoryAvailable; val != nil {
out.EvictionSoftGracePeriod[MemoryAvailable] = val.Duration.String()
}
if val := eviction.ImageFSAvailable; val != nil {
out.EvictionSoftGracePeriod[ImageFSAvailable] = val.Duration.String()
}
if val := eviction.ImageFSInodesFree; val != nil {
out.EvictionSoftGracePeriod[ImageFSInodesFree] = val.Duration.String()
}
if val := eviction.NodeFSAvailable; val != nil {
out.EvictionSoftGracePeriod[NodeFSAvailable] = val.Duration.String()
}
if val := eviction.NodeFSInodesFree; val != nil {
out.EvictionSoftGracePeriod[NodeFSInodesFree] = val.Duration.String()
}
}
}
return out
}
func reservedFromKubeletConfig(reserved *gardencorev1beta1.KubeletConfigReserved) map[string]string {
if reserved == nil {
return nil
}
out := make(map[string]string)
if cpu := reserved.CPU; cpu != nil {
out["cpu"] = cpu.String()
}
if memory := reserved.Memory; memory != nil {
out["memory"] = memory.String()
}
if ephemeralStorage := reserved.EphemeralStorage; ephemeralStorage != nil {
out["ephemeral-storage"] = ephemeralStorage.String()
}
if pid := reserved.PID; pid != nil {
out["pid"] = pid.String()
}
return out
}