forked from kubewharf/katalyst-core
67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
/*
|
|
Copyright 2022 The Katalyst 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 options
|
|
|
|
import (
|
|
"k8s.io/apimachinery/pkg/util/errors"
|
|
cliflag "k8s.io/component-base/cli/flag"
|
|
|
|
controllerconfig "github.com/kubewharf/katalyst-core/pkg/config/controller"
|
|
)
|
|
|
|
type ControllersOptions struct {
|
|
*VPAOptions
|
|
*KCCOptions
|
|
*SPDOptions
|
|
*LifeCycleOptions
|
|
}
|
|
|
|
func NewControllersOptions() *ControllersOptions {
|
|
return &ControllersOptions{
|
|
VPAOptions: NewVPAOptions(),
|
|
KCCOptions: NewKCCOptions(),
|
|
SPDOptions: NewSPDOptions(),
|
|
LifeCycleOptions: NewLifeCycleOptions(),
|
|
}
|
|
}
|
|
|
|
func (o *ControllersOptions) AddFlags(fss *cliflag.NamedFlagSets) {
|
|
o.VPAOptions.AddFlags(fss)
|
|
o.KCCOptions.AddFlags(fss)
|
|
o.SPDOptions.AddFlags(fss)
|
|
o.LifeCycleOptions.AddFlags(fss)
|
|
}
|
|
|
|
// ApplyTo fills up config with options
|
|
func (o *ControllersOptions) ApplyTo(c *controllerconfig.ControllersConfiguration) error {
|
|
var errList []error
|
|
|
|
errList = append(errList, o.VPAOptions.ApplyTo(c.VPAConfig))
|
|
errList = append(errList, o.KCCOptions.ApplyTo(c.KCCConfig))
|
|
errList = append(errList, o.SPDOptions.ApplyTo(c.SPDConfig))
|
|
errList = append(errList, o.LifeCycleOptions.ApplyTo(c.LifeCycleConfig))
|
|
return errors.NewAggregate(errList)
|
|
}
|
|
|
|
func (o *ControllersOptions) Config() (*controllerconfig.ControllersConfiguration, error) {
|
|
c := controllerconfig.NewControllersConfiguration()
|
|
if err := o.ApplyTo(c); err != nil {
|
|
return nil, err
|
|
}
|
|
return c, nil
|
|
}
|