44package api
55
66import (
7- "time"
8-
97 "github.com/NVIDIA/KAI-scheduler/pkg/scheduler/api/queue_info"
8+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
109)
1110
1211type Interface interface {
@@ -15,8 +14,8 @@ type Interface interface {
1514type UsageDBConfig struct {
1615 ClientType string `yaml:"clientType" json:"clientType"`
1716 ConnectionString string `yaml:"connectionString" json:"connectionString"`
18- ConnectionStringEnvVar string `yaml:"connectionStringEnvVar" json:"connectionStringEnvVar"`
19- UsageParams * UsageParams `yaml:"usageParams" json:"usageParams"`
17+ ConnectionStringEnvVar string `yaml:"connectionStringEnvVar,omitempty " json:"connectionStringEnvVar,omitempty "`
18+ UsageParams * UsageParams `yaml:"usageParams,omitempty " json:"usageParams,omitempty "`
2019}
2120
2221// GetUsageParams returns the usage params if set, and default params if not set.
@@ -29,23 +28,70 @@ func (c *UsageDBConfig) GetUsageParams() *UsageParams {
2928 return & up
3029}
3130
31+ func (c * UsageDBConfig ) DeepCopy () * UsageDBConfig {
32+ out := new (UsageDBConfig )
33+ out .ClientType = c .ClientType
34+ out .ConnectionString = c .ConnectionString
35+ out .ConnectionStringEnvVar = c .ConnectionStringEnvVar
36+ if c .UsageParams != nil {
37+ out .UsageParams = c .UsageParams .DeepCopy ()
38+ }
39+ return out
40+ }
41+
3242// UsageParams defines common params for all usage db clients. Some clients may not support all the params.
3343type UsageParams struct {
3444 // Half life period of the usage. If not set, or set to 0, the usage will not be decayed.
35- HalfLifePeriod * time .Duration `yaml:"halfLifePeriod" json:"halfLifePeriod"`
45+ HalfLifePeriod * metav1 .Duration `yaml:"halfLifePeriod,omitempty " json:"halfLifePeriod,omitempty "`
3646 // Window size of the usage. Default is 1 week.
37- WindowSize * time .Duration `yaml:"windowSize" json:"windowSize"`
47+ WindowSize * metav1 .Duration `yaml:"windowSize,omitempty " json:"windowSize,omitempty "`
3848 // Window type for time-series aggregation. If not set, defaults to sliding.
39- WindowType * WindowType `yaml:"windowType" json:"windowType"`
49+ WindowType * WindowType `yaml:"windowType,omitempty " json:"windowType,omitempty "`
4050 // A cron string used to determine when to reset resource usage for all queues.
41- TumblingWindowCronString string `yaml:"tumblingWindowCronString" json:"tumblingWindowCronString"`
51+ TumblingWindowCronString string `yaml:"tumblingWindowCronString,omitempty " json:"tumblingWindowCronString,omitempty "`
4252 // Fetch interval of the usage. Default is 1 minute.
43- FetchInterval * time .Duration `yaml:"fetchInterval" json:"fetchInterval"`
53+ FetchInterval * metav1 .Duration `yaml:"fetchInterval,omitempty " json:"fetchInterval,omitempty "`
4454 // Staleness period of the usage. Default is 5 minutes.
45- StalenessPeriod * time .Duration `yaml:"stalenessPeriod" json:"stalenessPeriod"`
55+ StalenessPeriod * metav1 .Duration `yaml:"stalenessPeriod,omitempty " json:"stalenessPeriod,omitempty "`
4656 // Wait timeout of the usage. Default is 1 minute.
47- WaitTimeout * time .Duration `yaml:"waitTimeout" json:"waitTimeout"`
57+ WaitTimeout * metav1 .Duration `yaml:"waitTimeout,omitempty " json:"waitTimeout,omitempty "`
4858
4959 // ExtraParams are extra parameters for the usage db client, which are client specific.
50- ExtraParams map [string ]string `yaml:"extraParams" json:"extraParams"`
60+ ExtraParams map [string ]string `yaml:"extraParams,omitempty" json:"extraParams,omitempty"`
61+ }
62+
63+ func (p * UsageParams ) DeepCopy () * UsageParams {
64+ out := new (UsageParams )
65+ if p .HalfLifePeriod != nil {
66+ duration := * p .HalfLifePeriod
67+ out .HalfLifePeriod = & duration
68+ }
69+ if p .WindowSize != nil {
70+ duration := * p .WindowSize
71+ out .WindowSize = & duration
72+ }
73+ if p .WindowType != nil {
74+ windowType := * p .WindowType
75+ out .WindowType = & windowType
76+ }
77+ out .TumblingWindowCronString = p .TumblingWindowCronString
78+ if p .FetchInterval != nil {
79+ duration := * p .FetchInterval
80+ out .FetchInterval = & duration
81+ }
82+ if p .StalenessPeriod != nil {
83+ duration := * p .StalenessPeriod
84+ out .StalenessPeriod = & duration
85+ }
86+ if p .WaitTimeout != nil {
87+ duration := * p .WaitTimeout
88+ out .WaitTimeout = & duration
89+ }
90+ if p .ExtraParams != nil {
91+ out .ExtraParams = make (map [string ]string , len (p .ExtraParams ))
92+ for k , v := range p .ExtraParams {
93+ out .ExtraParams [k ] = v
94+ }
95+ }
96+ return out
5197}
0 commit comments