github.com/kubewharf/katalyst-core@v0.5.3/pkg/util/qos/cpu_enhancement.go (about) 1 /* 2 Copyright 2022 The Katalyst Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package qos 18 19 import ( 20 "fmt" 21 "math" 22 "strconv" 23 24 v1 "k8s.io/api/core/v1" 25 26 "github.com/kubewharf/katalyst-api/pkg/consts" 27 "github.com/kubewharf/katalyst-core/pkg/config/generic" 28 ) 29 30 // GetPodCPUSuppressionToleranceRate parses cpu suppression tolerance rate for the given pod, 31 // and cpu suppression is only supported for reclaim pods. if the given is not nominated with 32 // cpu suppression, return max to indicate that it can be suppressed for any degree. 33 func GetPodCPUSuppressionToleranceRate(qosConf *generic.QoSConfiguration, pod *v1.Pod) (float64, error) { 34 qosLevel, _ := qosConf.GetQoSLevel(pod, map[string]string{}) 35 if qosLevel != consts.PodAnnotationQoSLevelReclaimedCores { 36 return 0, fmt.Errorf("qos level %s not support cpu suppression", qosLevel) 37 } 38 39 cpuEnhancement := qosConf.GetQoSEnhancementKVs(pod, map[string]string{}, consts.PodAnnotationCPUEnhancementKey) 40 suppressionToleranceRateStr, ok := cpuEnhancement[consts.PodAnnotationCPUEnhancementSuppressionToleranceRate] 41 if ok { 42 suppressionToleranceRate, err := strconv.ParseFloat(suppressionToleranceRateStr, 64) 43 if err != nil { 44 return 0, err 45 } 46 return suppressionToleranceRate, nil 47 } 48 49 return math.MaxFloat64, nil 50 }