github.com/kubewharf/katalyst-core@v0.5.3/cmd/katalyst-controller/app/options/kcc.go (about) 1 /* 2 Copyright 2022 The Katalyst 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 options 18 19 import ( 20 "k8s.io/apimachinery/pkg/util/sets" 21 cliflag "k8s.io/component-base/cli/flag" 22 23 "github.com/kubewharf/katalyst-api/pkg/apis/config/v1alpha1" 24 "github.com/kubewharf/katalyst-core/pkg/config/controller" 25 ) 26 27 // KCCOptions holds the configurations for katalyst config. 28 type KCCOptions struct { 29 ValidAPIGroupSet []string 30 } 31 32 // NewKCCOptions creates a new Options with a default config. 33 func NewKCCOptions() *KCCOptions { 34 return &KCCOptions{ 35 ValidAPIGroupSet: []string{v1alpha1.SchemeGroupVersion.Group}, 36 } 37 } 38 39 // AddFlags adds flags to the specified FlagSet. 40 func (o *KCCOptions) AddFlags(fss *cliflag.NamedFlagSets) { 41 fs := fss.FlagSet("kcc") 42 43 fs.StringSliceVar(&o.ValidAPIGroupSet, "kcc-valid-api-group-set", o.ValidAPIGroupSet, "which Groups is allowed") 44 } 45 46 // ApplyTo fills up config with options 47 func (o *KCCOptions) ApplyTo(c *controller.KCCConfig) error { 48 c.ValidAPIGroupSet = sets.NewString(o.ValidAPIGroupSet...) 49 return nil 50 } 51 52 func (o *KCCOptions) Config() (*controller.KCCConfig, error) { 53 c := &controller.KCCConfig{} 54 if err := o.ApplyTo(c); err != nil { 55 return nil, err 56 } 57 return c, nil 58 }