github.com/kubewharf/katalyst-core@v0.5.3/cmd/katalyst-controller/app/options/monitor.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  	cliflag "k8s.io/component-base/cli/flag"
    21  
    22  	"github.com/kubewharf/katalyst-core/pkg/config/controller"
    23  )
    24  
    25  // MonitorOptions holds the configurations for Monitor.
    26  type MonitorOptions struct {
    27  	// EnableCNRMonitor is a flag to enable CNR monitor controller
    28  	EnableCNRMonitor bool
    29  }
    30  
    31  func NewMonitorOptions() *MonitorOptions {
    32  	return &MonitorOptions{
    33  		EnableCNRMonitor: true,
    34  	}
    35  }
    36  
    37  // AddFlags adds flags  to the specified FlagSet.
    38  func (o *MonitorOptions) AddFlags(fss *cliflag.NamedFlagSets) {
    39  	fs := fss.FlagSet("monitor")
    40  
    41  	fs.BoolVar(&o.EnableCNRMonitor, "cnr-monitor-enable", o.EnableCNRMonitor,
    42  		"whether to enable the cnr controller")
    43  }
    44  
    45  // ApplyTo fills up config with options
    46  func (o *MonitorOptions) ApplyTo(c *controller.MonitorConfig) error {
    47  	c.EnableCNRMonitor = o.EnableCNRMonitor
    48  	return nil
    49  }
    50  
    51  func (o *MonitorOptions) Config() (*controller.MonitorConfig, error) {
    52  	c := &controller.MonitorConfig{}
    53  	if err := o.ApplyTo(c); err != nil {
    54  		return nil, err
    55  	}
    56  	return c, nil
    57  }