-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugin_config.go
74 lines (63 loc) · 2.81 KB
/
plugin_config.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
package gang
import (
"fmt"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
fwkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
)
type PluginConfig struct {
// GangAnnotationPrefix is the prefix of all gang annotations.
// This configuration is required; if not set, the plugin will return an error during its initialization.
GangAnnotationPrefix string `json:"gangAnnotationPrefix"`
// SchedulerName is the name of the scheduler.
// This field is optional; if not set, the default scheduler name will be used.
SchedulerName string `json:"schedulerName,omitempty"`
// GangScheduleTimeoutSecondsLimit is the maximum timeout in seconds for gang scheduling.
// If the timeout configured in the pod annotation exceeds this limit, the timeout will be set to this limit.
// This field is optional; if not set, 100 will be used as a default value.
GangScheduleTimeoutSecondsLimit int `json:"gangScheduleTimeoutSecondLimit,omitempty"`
// GangScheduleDefaultTimeoutSeconds is the default timeout in seconds,
// which will be used if the timeout is not set in the pod annotation.
// This field is optional; if not set, 30 will be used as a default value.
GangScheduleDefaultTimeoutSeconds int `json:"gangScheduleDefaultTimeoutSecond,omitempty"`
// GangScheduleTimeoutJitterSeconds is the jitter in seconds for timeout.
// This field is optional; if not set, 30 will be used as a default value.
GangScheduleTimeoutJitterSeconds int `json:"gangScheduleTimeoutJitterSecond,omitempty"`
}
type ScheduleTimeoutConfig struct {
DefaultSeconds int
LimitSeconds int
JitterSeconds int
}
func DecodePluginConfig(configuration runtime.Object) (*PluginConfig, error) {
config := &PluginConfig{}
if err := fwkruntime.DecodeInto(configuration, &config); err != nil {
return nil, fmt.Errorf("failed to decode into %s PluginConfig", PluginName)
}
if config.GangAnnotationPrefix == "" {
return nil, fmt.Errorf("gangAnnotationPrefix is a required configuration")
}
config.fillEmptyFields()
return config, nil
}
func (config *PluginConfig) TimeoutConfig() ScheduleTimeoutConfig {
return ScheduleTimeoutConfig{
DefaultSeconds: config.GangScheduleDefaultTimeoutSeconds,
LimitSeconds: config.GangScheduleTimeoutSecondsLimit,
JitterSeconds: config.GangScheduleTimeoutJitterSeconds,
}
}
func (config *PluginConfig) fillEmptyFields() {
if config.SchedulerName == "" {
config.SchedulerName = corev1.DefaultSchedulerName
}
if config.GangScheduleTimeoutSecondsLimit <= 0 {
config.GangScheduleTimeoutSecondsLimit = GangScheduleTimeoutSecondsLimitDefault
}
if config.GangScheduleDefaultTimeoutSeconds <= 0 {
config.GangScheduleDefaultTimeoutSeconds = GangScheduleTimeoutSecondsDefault
}
if config.GangScheduleTimeoutJitterSeconds <= 0 {
config.GangScheduleTimeoutJitterSeconds = GangScheduleTimeoutJitterSecondsDefault
}
}