volcano.sh/volcano@v1.9.0/pkg/scheduler/framework/arguments.go (about) 1 /* 2 Copyright 2019 The Kubernetes 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 framework 18 19 import ( 20 "k8s.io/klog/v2" 21 22 "volcano.sh/volcano/pkg/scheduler/conf" 23 ) 24 25 // Arguments map 26 type Arguments map[string]interface{} 27 28 // GetInt get the integer value from string 29 func (a Arguments) GetInt(ptr *int, key string) { 30 if ptr == nil { 31 return 32 } 33 34 argv, ok := a[key] 35 if !ok { 36 return 37 } 38 39 value, ok := argv.(int) 40 if !ok { 41 klog.Warningf("Could not parse argument: %v for key %s to int", argv, key) 42 return 43 } 44 45 *ptr = value 46 } 47 48 // GetFloat64 get the float64 value from string 49 func (a Arguments) GetFloat64(ptr *float64, key string) { 50 if ptr == nil { 51 return 52 } 53 54 argv, ok := a[key] 55 if !ok { 56 return 57 } 58 59 value, ok := argv.(float64) 60 if !ok { 61 if intVal, ok := argv.(int); ok { 62 *ptr = float64(intVal) 63 return 64 } 65 klog.Warningf("Could not parse argument: %v for key %s to float64", argv, key) 66 return 67 } 68 69 *ptr = value 70 } 71 72 // GetBool get the bool value from string 73 func (a Arguments) GetBool(ptr *bool, key string) { 74 if ptr == nil { 75 return 76 } 77 78 argv, ok := a[key] 79 if !ok { 80 return 81 } 82 83 value, ok := argv.(bool) 84 if !ok { 85 klog.Warningf("Could not parse argument: %v for key %s to bool", argv, key) 86 return 87 } 88 89 *ptr = value 90 } 91 92 // GetArgOfActionFromConf return argument of action reading from configuration of schedule 93 func GetArgOfActionFromConf(configurations []conf.Configuration, actionName string) Arguments { 94 for _, c := range configurations { 95 if c.Name == actionName { 96 return c.Arguments 97 } 98 } 99 100 return nil 101 }