Skip to content

Commit 6e7bbdc

Browse files
astefanuttiopenshift-merge-robot
authored andcommitted
Expose structured configuration
1 parent 203e938 commit 6e7bbdc

File tree

6 files changed

+199
-141
lines changed

6 files changed

+199
-141
lines changed

Diff for: cmd/kar-controllers/app/options/options.go

+3-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
11
/*
2-
Copyright 2017 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-
/*
172
Copyright 2019, 2021 The Multi-Cluster App Dispatcher Authors.
183
194
Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2813
See the License for the specific language governing permissions and
2914
limitations under the License.
3015
*/
16+
3117
package options
3218

3319
import (
@@ -41,7 +27,6 @@ import (
4127
type ServerOption struct {
4228
Master string
4329
Kubeconfig string
44-
SchedulerName string
4530
Dispatcher bool
4631
AgentConfigs string
4732
SecurePort int
@@ -68,11 +53,10 @@ func (s *ServerOption) AddFlags(fs *flag.FlagSet) {
6853
// Set defaults via environment variables
6954
s.loadDefaultsFromEnvVars()
7055

71-
fs.StringVar(&s.Master, "scheduler", s.SchedulerName, "scheduler name for placing pods")
7256
fs.StringVar(&s.Master, "master", s.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig)")
7357
fs.StringVar(&s.Kubeconfig, "kubeconfig", s.Kubeconfig, "Path to kubeconfig file with authorization and master location information.")
74-
fs.BoolVar(&s.Dispatcher, "dispatcher", s.Dispatcher, "set dispather mode(true) or agent mode(false)")
75-
fs.StringVar(&s.AgentConfigs, "agentconfigs", s.AgentConfigs, "Paths to agent config file:deploymentName separted by commas(,)")
58+
fs.BoolVar(&s.Dispatcher, "dispatcher", s.Dispatcher, "set dispatcher mode(true) or agent mode(false)")
59+
fs.StringVar(&s.AgentConfigs, "agentconfigs", s.AgentConfigs, "Comma-separated paths to agent config file:deploymentName")
7660
fs.BoolVar(&s.DynamicPriority, "dynamicpriority", s.DynamicPriority, "If true, set controller to use dynamic priority. If false, set controller to use static priority. Default is false.")
7761
fs.BoolVar(&s.Preemption, "preemption", s.Preemption, "Set controller to allow preemption if set to true. Note: when set to true, the Kubernetes Scheduler must be configured to enable preemption. Default is false.")
7862
fs.IntVar(&s.BackoffTime, "backofftime", s.BackoffTime, "Number of seconds a job will go away for, if it can not be scheduled. Default is 20.")

Diff for: cmd/kar-controllers/app/server.go

+24-23
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
11
/*
2-
Copyright 2017 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-
/*
172
Copyright 2019, 2021 The Multi-Cluster App Dispatcher Authors.
183
194
Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,18 +13,23 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2813
See the License for the specific language governing permissions and
2914
limitations under the License.
3015
*/
16+
3117
package app
3218

3319
import (
20+
"net/http"
21+
"strings"
22+
23+
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
24+
3425
"k8s.io/client-go/rest"
3526
"k8s.io/client-go/tools/clientcmd"
36-
"net/http"
27+
"k8s.io/utils/pointer"
3728

3829
"github.com/project-codeflare/multi-cluster-app-dispatcher/cmd/kar-controllers/app/options"
30+
"github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/config"
3931
"github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/controller/queuejob"
4032
"github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/health"
41-
42-
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
4333
)
4434

4535
func buildConfig(master, kubeconfig string) (*rest.Config, error) {
@@ -50,17 +40,29 @@ func buildConfig(master, kubeconfig string) (*rest.Config, error) {
5040
}
5141

5242
func Run(opt *options.ServerOption) error {
53-
config, err := buildConfig(opt.Master, opt.Kubeconfig)
43+
restConfig, err := buildConfig(opt.Master, opt.Kubeconfig)
5444
if err != nil {
5545
return err
5646
}
5747

5848
neverStop := make(chan struct{})
5949

60-
config.QPS = 100.0
61-
config.Burst = 200.0
50+
restConfig.QPS = 100.0
51+
restConfig.Burst = 200.0
52+
53+
mcadConfig := &config.MCADConfiguration{
54+
DynamicPriority: pointer.Bool(opt.DynamicPriority),
55+
Preemption: pointer.Bool(opt.Preemption),
56+
BackoffTime: pointer.Int32(int32(opt.BackoffTime)),
57+
HeadOfLineHoldingTime: pointer.Int32(int32(opt.HeadOfLineHoldingTime)),
58+
QuotaEnabled: &opt.QuotaEnabled,
59+
}
60+
extConfig := &config.MCADConfigurationExtended{
61+
Dispatcher: pointer.Bool(opt.Dispatcher),
62+
AgentConfigs: strings.Split(opt.AgentConfigs, ","),
63+
}
6264

63-
jobctrl := queuejob.NewJobController(config, opt)
65+
jobctrl := queuejob.NewJobController(restConfig, mcadConfig, extConfig)
6466
if jobctrl == nil {
6567
return nil
6668
}
@@ -86,4 +88,3 @@ func listenHealthProbe(opt *options.ServerOption) error {
8688

8789
return nil
8890
}
89-

Diff for: pkg/config/config.go

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Copyright 2023 The Multi-Cluster App Dispatcher 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 config
18+
19+
// MCADConfiguration defines the core MCAD configuration.
20+
type MCADConfiguration struct {
21+
// dynamicPriority sets the controller to use dynamic priority.
22+
// If false, it sets the controller to use static priority.
23+
// It defaults to false.
24+
// +optional
25+
DynamicPriority *bool `json:"dynamicPriority,omitempty"`
26+
27+
// preemption sets the controller to allow preemption.
28+
// Note: when set to true, the Kubernetes scheduler must be configured
29+
// to enable preemption. It defaults to false.
30+
// +optional
31+
Preemption *bool `json:"preemption,omitempty"`
32+
33+
// backoffTime defines the duration, in seconds, a job will go away,
34+
// if it can not be scheduled.
35+
// +optional
36+
BackoffTime *int32 `json:"backoffTime,omitempty"`
37+
38+
// headOfLineHoldingTime defines the duration in seconds a job can stay at the
39+
// Head Of Line without being bumped.
40+
// It defaults to 0.
41+
// +optional
42+
HeadOfLineHoldingTime *int32 `json:"headOfLineHoldingTime,omitempty"`
43+
44+
// quotaEnabled sets whether quota management is enabled.
45+
// It defaults to false.
46+
// +optional
47+
QuotaEnabled *bool `json:"quotaEnabled,omitempty"`
48+
}
49+
50+
// MCADConfigurationExtended defines the extended MCAD configuration, e.g.,
51+
// for experimental features.
52+
type MCADConfigurationExtended struct {
53+
// dispatcher sets the controller in dispatcher mode, of in agent mode.
54+
// It defaults to false.
55+
// +optional
56+
Dispatcher *bool `json:"dispatcher,omitempty"`
57+
58+
// agentConfigs contains paths to agent config file
59+
AgentConfigs []string `json:"agentConfigs,omitempty"`
60+
}

Diff for: pkg/config/support.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright 2023 The Multi-Cluster App Dispatcher 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 config
18+
19+
func (c *MCADConfiguration) IsQuotaEnabled() bool {
20+
return isTrue(c.QuotaEnabled)
21+
}
22+
23+
func (c *MCADConfiguration) HasPreemption() bool {
24+
return isTrue(c.Preemption)
25+
}
26+
27+
func (c *MCADConfiguration) HasDynamicPriority() bool {
28+
return isTrue(c.DynamicPriority)
29+
}
30+
31+
func (c *MCADConfiguration) BackoffTimeOrDefault(val int32) int32 {
32+
if c.BackoffTime == nil {
33+
return val
34+
}
35+
return *c.BackoffTime
36+
}
37+
38+
func (e *MCADConfigurationExtended) IsDispatcher() bool {
39+
return isTrue(e.Dispatcher)
40+
}
41+
42+
func isTrue(v *bool) bool {
43+
return v != nil && *v
44+
}

0 commit comments

Comments
 (0)