Skip to content

Commit c7f96fb

Browse files
committed
Added deepcopy functions
1 parent 30483ae commit c7f96fb

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

pkg/scheduler/cache/usagedb/api/interface.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package api
55

66
import (
7+
"maps"
78
"time"
89

910
"github.com/NVIDIA/KAI-scheduler/pkg/scheduler/api/queue_info"
@@ -19,6 +20,15 @@ type UsageDBConfig struct {
1920
UsageParams *UsageParams `yaml:"usageParams" json:"usageParams"`
2021
}
2122

23+
func (c *UsageDBConfig) DeepCopy() *UsageDBConfig {
24+
return &UsageDBConfig{
25+
ClientType: c.ClientType,
26+
ConnectionString: c.ConnectionString,
27+
ConnectionStringEnvVar: c.ConnectionStringEnvVar,
28+
UsageParams: c.UsageParams.DeepCopy(),
29+
}
30+
}
31+
2232
// GetUsageParams returns the usage params if set, and default params if not set.
2333
func (c *UsageDBConfig) GetUsageParams() *UsageParams {
2434
up := UsageParams{}
@@ -43,3 +53,13 @@ type UsageParams struct {
4353
// ExtraParams are extra parameters for the usage db client, which are client specific.
4454
ExtraParams map[string]string `yaml:"extraParams" json:"extraParams"`
4555
}
56+
57+
func (up *UsageParams) DeepCopy() *UsageParams {
58+
return &UsageParams{
59+
HalfLifePeriod: up.HalfLifePeriod,
60+
WindowSize: up.WindowSize,
61+
WindowType: up.WindowType,
62+
TumblingWindowCronString: up.TumblingWindowCronString,
63+
ExtraParams: maps.Clone(up.ExtraParams),
64+
}
65+
}

pkg/scheduler/conf/scheduler_conf.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ limitations under the License.
2020
package conf
2121

2222
import (
23+
"maps"
24+
"slices"
2325
"time"
2426

2527
"k8s.io/apimachinery/pkg/labels"
@@ -59,33 +61,76 @@ type SchedulerConfiguration struct {
5961
UsageDBConfig *usagedbapi.UsageDBConfig `yaml:"usageDBConfig,omitempty" json:"usageDBConfig,omitempty"`
6062
}
6163

64+
func (s *SchedulerConfiguration) DeepCopy() *SchedulerConfiguration {
65+
copy := SchedulerConfiguration{
66+
Actions: s.Actions,
67+
Tiers: slices.Clone(s.Tiers),
68+
QueueDepthPerAction: maps.Clone(s.QueueDepthPerAction),
69+
UsageDBConfig: s.UsageDBConfig.DeepCopy(),
70+
}
71+
72+
return &copy
73+
}
74+
6275
// Tier defines plugin tier
6376
type Tier struct {
6477
Plugins []PluginOption `yaml:"plugins" json:"plugins"`
6578
}
6679

80+
func (t *Tier) DeepCopy() *Tier {
81+
copy := Tier{
82+
Plugins: make([]PluginOption, len(t.Plugins)),
83+
}
84+
for i, plugin := range t.Plugins {
85+
copy.Plugins[i] = *plugin.DeepCopy()
86+
}
87+
return &copy
88+
}
89+
6790
// PluginOption defines the options of plugin
6891
type PluginOption struct {
6992
// The name of Plugin
7093
Name string `yaml:"name" json:"name"`
94+
7195
// JobOrderDisabled defines whether jobOrderFn is disabled
96+
// Deprecated: To disable, don't set this plugin in the config
7297
JobOrderDisabled bool `yaml:"disableJobOrder" json:"disableJobOrder"`
7398
// TaskOrderDisabled defines whether taskOrderFn is disabled
7499
TaskOrderDisabled bool `yaml:"disableTaskOrder" json:"disableTaskOrder"`
100+
// Deprecated: To disable, don't set this plugin in the config
75101
// PreemptableDisabled defines whether preemptableFn is disabled
76102
PreemptableDisabled bool `yaml:"disablePreemptable" json:"disablePreemptable"`
77103
// ReclaimableDisabled defines whether reclaimableFn is disabled
104+
// Deprecated: To disable, don't set this plugin in the config
78105
ReclaimableDisabled bool `yaml:"disableReclaimable" json:"disableReclaimable"`
79106
// QueueOrderDisabled defines whether queueOrderFn is disabled
80107
QueueOrderDisabled bool `yaml:"disableQueueOrder" json:"disableQueueOrder"`
108+
// Deprecated: To disable, don't set this plugin in the config
81109
// PredicateDisabled defines whether predicateFn is disabled
82110
PredicateDisabled bool `yaml:"disablePredicate" json:"disablePredicate"`
83111
// NodeOrderDisabled defines whether NodeOrderFn is disabled
112+
// Deprecated: To disable, don't set this plugin in the config
84113
NodeOrderDisabled bool `yaml:"disableNodeOrder" json:"disableNodeOrder"`
114+
85115
// Arguments defines the different arguments that can be given to different plugins
86116
Arguments map[string]string `yaml:"arguments" json:"arguments"`
87117
}
88118

119+
func (p *PluginOption) DeepCopy() *PluginOption {
120+
copy := PluginOption{
121+
Name: p.Name,
122+
Arguments: maps.Clone(p.Arguments),
123+
}
124+
copy.JobOrderDisabled = p.JobOrderDisabled
125+
copy.TaskOrderDisabled = p.TaskOrderDisabled
126+
copy.PreemptableDisabled = p.PreemptableDisabled
127+
copy.ReclaimableDisabled = p.ReclaimableDisabled
128+
copy.QueueOrderDisabled = p.QueueOrderDisabled
129+
copy.PredicateDisabled = p.PredicateDisabled
130+
copy.NodeOrderDisabled = p.NodeOrderDisabled
131+
return &copy
132+
}
133+
89134
type SchedulingNodePoolParams struct {
90135
NodePoolLabelKey string
91136
NodePoolLabelValue string

0 commit comments

Comments
 (0)