github.com/kubewharf/katalyst-core@v0.5.3/pkg/util/overcommit/overcommit.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 overcommit 18 19 import ( 20 "strconv" 21 22 "k8s.io/klog/v2" 23 ) 24 25 func OvercommitRatioValidate( 26 nodeAnnotation map[string]string, 27 setOvercommitKey, realtimeOvercommitKey string, 28 ) (float64, error) { 29 // overcommit is not allowed if overcommitRatio is not set by user 30 setOvercommitVal, ok := nodeAnnotation[setOvercommitKey] 31 if !ok { 32 return 1.0, nil 33 } 34 35 overcommitRatio, err := strconv.ParseFloat(setOvercommitVal, 64) 36 if err != nil { 37 return 1.0, err 38 } 39 40 realtimeOvercommitVal, ok := nodeAnnotation[realtimeOvercommitKey] 41 if ok { 42 realtimeOvercommitRatio, err := strconv.ParseFloat(realtimeOvercommitVal, 64) 43 if err != nil { 44 klog.Errorf("realtime overcommit %s validate fail: %v", realtimeOvercommitVal, err) 45 } 46 if realtimeOvercommitRatio < overcommitRatio { 47 overcommitRatio = realtimeOvercommitRatio 48 } 49 } 50 51 if overcommitRatio < 1.0 { 52 klog.Warningf("overcommitRatio should be greater than 1") 53 return 1.0, nil 54 } 55 56 return overcommitRatio, nil 57 }