@@ -2,6 +2,7 @@ package kubeletconfig
2
2
3
3
import (
4
4
"encoding/json"
5
+ "strconv"
5
6
"time"
6
7
7
8
corev1 "k8s.io/api/core/v1"
@@ -27,35 +28,29 @@ const (
27
28
// 4. Reserved CPUs
28
29
// 5. Memory manager policy
29
30
// Please avoid specifying them and use the relevant API to configure these parameters.
30
- experimentalKubeletSnippetAnnotation = "kubeletconfig.experimental"
31
- cpuManagerPolicyStatic = "static"
32
- cpuManagerPolicyOptionFullPCPUsOnly = "full-pcpus-only"
33
- memoryManagerPolicyStatic = "Static"
34
- defaultKubeReservedMemory = "500Mi"
35
- defaultSystemReservedMemory = "500Mi"
36
- defaultHardEvictionThresholdMemory = "100Mi"
37
- defaultHardEvictionThresholdNodefs = "10%"
38
- defaultHardEvictionThresholdImagefs = "15%"
39
- defaultHardEvictionThresholdNodefsInodesFree = "5%"
40
- evictionHardMemoryAvailable = "memory.available"
41
- evictionHardNodefsAvaialble = "nodefs.available"
42
- evictionHardImagefsAvailable = "imagefs.available"
43
- evictionHardNodefsInodesFree = "nodefs.inodesFree"
31
+ experimentalKubeletSnippetAnnotation = "kubeletconfig.experimental"
32
+ cpuManagerPolicyStatic = "static"
33
+ cpuManagerPolicyOptionFullPCPUsOnly = "full-pcpus-only"
34
+ cpuManagerPolicyOptionPreferAlignCPUsByUncoreCache = "prefer-align-cpus-by-uncorecache"
35
+ memoryManagerPolicyStatic = "Static"
36
+ defaultKubeReservedMemory = "500Mi"
37
+ defaultSystemReservedMemory = "500Mi"
38
+ defaultHardEvictionThresholdMemory = "100Mi"
39
+ defaultHardEvictionThresholdNodefs = "10%"
40
+ defaultHardEvictionThresholdImagefs = "15%"
41
+ defaultHardEvictionThresholdNodefsInodesFree = "5%"
42
+ evictionHardMemoryAvailable = "memory.available"
43
+ evictionHardNodefsAvaialble = "nodefs.available"
44
+ evictionHardImagefsAvailable = "imagefs.available"
45
+ evictionHardNodefsInodesFree = "nodefs.inodesFree"
44
46
)
45
47
46
48
// New returns new KubeletConfig object for performance sensetive workflows
47
49
func New (profile * performancev2.PerformanceProfile , opts * components.KubeletConfigOptions ) (* machineconfigv1.KubeletConfig , error ) {
48
50
name := components .GetComponentName (profile .Name , components .ComponentNamePrefix )
49
- kubeletConfig := & kubeletconfigv1beta1.KubeletConfiguration {}
50
- if v , ok := profile .Annotations [experimentalKubeletSnippetAnnotation ]; ok {
51
- if err := json .Unmarshal ([]byte (v ), kubeletConfig ); err != nil {
52
- return nil , err
53
- }
54
- }
55
-
56
- kubeletConfig .TypeMeta = metav1.TypeMeta {
57
- APIVersion : kubeletconfigv1beta1 .SchemeGroupVersion .String (),
58
- Kind : "KubeletConfiguration" ,
51
+ kubeletConfig , err := NewKubeletConfigFromExperimentalAnnotation (profile )
52
+ if err != nil {
53
+ return nil , err
59
54
}
60
55
61
56
kubeletConfig .CPUManagerPolicy = cpuManagerPolicyStatic
@@ -193,3 +188,37 @@ func addStringToQuantity(q *resource.Quantity, value string) error {
193
188
194
189
return nil
195
190
}
191
+
192
+ func NewKubeletConfigFromExperimentalAnnotation (profile * performancev2.PerformanceProfile ) (* kubeletconfigv1beta1.KubeletConfiguration , error ) {
193
+ kubeletConfig := & kubeletconfigv1beta1.KubeletConfiguration {}
194
+ kubeletConfig .TypeMeta = metav1.TypeMeta {
195
+ APIVersion : kubeletconfigv1beta1 .SchemeGroupVersion .String (),
196
+ Kind : "KubeletConfiguration" ,
197
+ }
198
+
199
+ if v , ok := profile .Annotations [experimentalKubeletSnippetAnnotation ]; ok {
200
+ if err := json .Unmarshal ([]byte (v ), kubeletConfig ); err != nil {
201
+ return nil , err
202
+ }
203
+ }
204
+ return kubeletConfig , nil
205
+ }
206
+
207
+ func HasExperimentalOptionLLCEnabled (profile * performancev2.PerformanceProfile ) bool {
208
+ if profile == nil {
209
+ return false
210
+ }
211
+ kubeletConfig , err := NewKubeletConfigFromExperimentalAnnotation (profile )
212
+ if err != nil {
213
+ return false
214
+ }
215
+ val , ok := kubeletConfig .CPUManagerPolicyOptions [cpuManagerPolicyOptionPreferAlignCPUsByUncoreCache ]
216
+ if ! ok {
217
+ return false
218
+ }
219
+ v , err := strconv .ParseBool (val )
220
+ if err != nil {
221
+ return false
222
+ }
223
+ return v
224
+ }
0 commit comments