Skip to content

Expose structured configuration #630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions cmd/kar-controllers/app/options/options.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
/*
Copyright 2017 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Copyright 2019, 2021 The Multi-Cluster App Dispatcher Authors.

Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -28,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package options

import (
Expand All @@ -41,7 +27,6 @@ import (
type ServerOption struct {
Master string
Kubeconfig string
SchedulerName string
Dispatcher bool
AgentConfigs string
SecurePort int
Expand All @@ -68,11 +53,10 @@ func (s *ServerOption) AddFlags(fs *flag.FlagSet) {
// Set defaults via environment variables
s.loadDefaultsFromEnvVars()

fs.StringVar(&s.Master, "scheduler", s.SchedulerName, "scheduler name for placing pods")
fs.StringVar(&s.Master, "master", s.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig)")
fs.StringVar(&s.Kubeconfig, "kubeconfig", s.Kubeconfig, "Path to kubeconfig file with authorization and master location information.")
fs.BoolVar(&s.Dispatcher, "dispatcher", s.Dispatcher, "set dispather mode(true) or agent mode(false)")
fs.StringVar(&s.AgentConfigs, "agentconfigs", s.AgentConfigs, "Paths to agent config file:deploymentName separted by commas(,)")
fs.BoolVar(&s.Dispatcher, "dispatcher", s.Dispatcher, "set dispatcher mode(true) or agent mode(false)")
fs.StringVar(&s.AgentConfigs, "agentconfigs", s.AgentConfigs, "Comma-separated paths to agent config file:deploymentName")
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.")
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.")
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.")
Expand Down
47 changes: 24 additions & 23 deletions cmd/kar-controllers/app/server.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
/*
Copyright 2017 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Copyright 2019, 2021 The Multi-Cluster App Dispatcher Authors.

Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -28,18 +13,23 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package app

import (
"net/http"
"strings"

_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"

"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"net/http"
"k8s.io/utils/pointer"

"github.com/project-codeflare/multi-cluster-app-dispatcher/cmd/kar-controllers/app/options"
"github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/config"
"github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/controller/queuejob"
"github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/health"

_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
)

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

func Run(opt *options.ServerOption) error {
config, err := buildConfig(opt.Master, opt.Kubeconfig)
restConfig, err := buildConfig(opt.Master, opt.Kubeconfig)
if err != nil {
return err
}

neverStop := make(chan struct{})

config.QPS = 100.0
config.Burst = 200.0
restConfig.QPS = 100.0
restConfig.Burst = 200.0

mcadConfig := &config.MCADConfiguration{
DynamicPriority: pointer.Bool(opt.DynamicPriority),
Preemption: pointer.Bool(opt.Preemption),
BackoffTime: pointer.Int32(int32(opt.BackoffTime)),
HeadOfLineHoldingTime: pointer.Int32(int32(opt.HeadOfLineHoldingTime)),
QuotaEnabled: &opt.QuotaEnabled,
}
extConfig := &config.MCADConfigurationExtended{
Dispatcher: pointer.Bool(opt.Dispatcher),
AgentConfigs: strings.Split(opt.AgentConfigs, ","),
}

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

return nil
}

60 changes: 60 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
Copyright 2023 The Multi-Cluster App Dispatcher Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package config

// MCADConfiguration defines the core MCAD configuration.
type MCADConfiguration struct {
// dynamicPriority sets the controller to use dynamic priority.
// If false, it sets the controller to use static priority.
// It defaults to false.
// +optional
DynamicPriority *bool `json:"dynamicPriority,omitempty"`

// preemption sets the controller to allow preemption.
// Note: when set to true, the Kubernetes scheduler must be configured
// to enable preemption. It defaults to false.
// +optional
Preemption *bool `json:"preemption,omitempty"`

// backoffTime defines the duration, in seconds, a job will go away,
// if it can not be scheduled.
// +optional
BackoffTime *int32 `json:"backoffTime,omitempty"`

// headOfLineHoldingTime defines the duration in seconds a job can stay at the
// Head Of Line without being bumped.
// It defaults to 0.
// +optional
HeadOfLineHoldingTime *int32 `json:"headOfLineHoldingTime,omitempty"`

// quotaEnabled sets whether quota management is enabled.
// It defaults to false.
// +optional
QuotaEnabled *bool `json:"quotaEnabled,omitempty"`
}

// MCADConfigurationExtended defines the extended MCAD configuration, e.g.,
// for experimental features.
type MCADConfigurationExtended struct {
// dispatcher sets the controller in dispatcher mode, of in agent mode.
// It defaults to false.
// +optional
Dispatcher *bool `json:"dispatcher,omitempty"`

// agentConfigs contains paths to agent config file
AgentConfigs []string `json:"agentConfigs,omitempty"`
}
44 changes: 44 additions & 0 deletions pkg/config/support.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2023 The Multi-Cluster App Dispatcher Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package config

func (c *MCADConfiguration) IsQuotaEnabled() bool {
return isTrue(c.QuotaEnabled)
}

func (c *MCADConfiguration) HasPreemption() bool {
return isTrue(c.Preemption)
}

func (c *MCADConfiguration) HasDynamicPriority() bool {
return isTrue(c.DynamicPriority)
}

func (c *MCADConfiguration) BackoffTimeOrDefault(val int32) int32 {
if c.BackoffTime == nil {
return val
}
return *c.BackoffTime
}

func (e *MCADConfigurationExtended) IsDispatcher() bool {
return isTrue(e.Dispatcher)
}

func isTrue(v *bool) bool {
return v != nil && *v
}
Loading