github.com/kubewharf/katalyst-core@v0.5.3/cmd/katalyst-controller/app/options/overcommit.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 "time" 21 22 cliflag "k8s.io/component-base/cli/flag" 23 24 "github.com/kubewharf/katalyst-core/pkg/config/controller" 25 ) 26 27 const ( 28 defaultNodeOvercommitSyncWorkers = 1 29 defaultNodeOvercommitReconcilePeriod = 30 * time.Minute 30 ) 31 32 // OvercommitOptions holds the configurations for overcommit. 33 type OvercommitOptions struct { 34 NodeOvercommitOptions 35 } 36 37 // NodeOvercommitOptions holds the configurations for nodeOvercommitConfig controller. 38 type NodeOvercommitOptions struct { 39 // numer of workers to sync overcommit config 40 SyncWorkers int 41 42 // time interval of reconcile overcommit config 43 ConfigReconcilePeriod time.Duration 44 } 45 46 // NewOvercommitOptions creates a new Options with a default config. 47 func NewOvercommitOptions() *OvercommitOptions { 48 return &OvercommitOptions{} 49 } 50 51 // AddFlags adds flags to the specified FlagSet 52 func (o *OvercommitOptions) AddFlags(fss *cliflag.NamedFlagSets) { 53 fs := fss.FlagSet("noc") 54 55 fs.IntVar(&o.SyncWorkers, "nodeovercommit-sync-workers", defaultNodeOvercommitSyncWorkers, "num of goroutines to sync nodeovercommitconfig") 56 fs.DurationVar(&o.ConfigReconcilePeriod, "nodeovercommit-reconcile-period", defaultNodeOvercommitReconcilePeriod, "Period for nodeovercommit controller to sync configs") 57 } 58 59 func (o *OvercommitOptions) ApplyTo(c *controller.OvercommitConfig) error { 60 c.Node.SyncWorkers = o.SyncWorkers 61 c.Node.ConfigReconcilePeriod = o.ConfigReconcilePeriod 62 return nil 63 } 64 65 func (o *OvercommitOptions) Config() (*controller.OvercommitConfig, error) { 66 c := &controller.OvercommitConfig{} 67 if err := o.ApplyTo(c); err != nil { 68 return nil, err 69 } 70 return c, nil 71 }