github.com/spotahome/redis-operator@v1.2.4/cmd/utils/flags.go (about)

     1  package utils
     2  
     3  import (
     4  	"flag"
     5  	"path/filepath"
     6  
     7  	"github.com/spotahome/redis-operator/operator/redisfailover"
     8  	"k8s.io/client-go/util/homedir"
     9  )
    10  
    11  // CMDFlags are the flags used by the cmd
    12  // TODO: improve flags.
    13  type CMDFlags struct {
    14  	KubeConfig          string
    15  	Development         bool
    16  	ListenAddr          string
    17  	MetricsPath         string
    18  	K8sQueriesPerSecond int
    19  	K8sQueriesBurstable int
    20  	Concurrency         int
    21  	LogLevel            string
    22  }
    23  
    24  // Init initializes and parse the flags
    25  func (c *CMDFlags) Init() {
    26  	kubehome := filepath.Join(homedir.HomeDir(), ".kube", "config")
    27  	// register flags
    28  	flag.StringVar(&c.KubeConfig, "kubeconfig", kubehome, "kubernetes configuration path, only used when development mode enabled")
    29  	flag.BoolVar(&c.Development, "development", false, "development flag will allow to run the operator outside a kubernetes cluster")
    30  	flag.StringVar(&c.ListenAddr, "listen-address", ":9710", "Address to listen on for metrics.")
    31  	flag.StringVar(&c.MetricsPath, "metrics-path", "/metrics", "Path to serve the metrics.")
    32  	flag.IntVar(&c.K8sQueriesPerSecond, "k8s-cli-qps-limit", 100, "Number of allowed queries per second by kubernetes client without client side throttling")
    33  	flag.IntVar(&c.K8sQueriesBurstable, "k8s-cli-burstable-limit", 100, "Number of allowed burst requests by kubernetes client without client side throttling")
    34  	// default is 3 for conccurency because kooper also defines 3 as default
    35  	// reference: https://github.com/spotahome/kooper/blob/master/controller/controller.go#L89
    36  	flag.IntVar(&c.Concurrency, "concurrency", 3, "Number of conccurent workers meant to process events")
    37  	flag.StringVar(&c.LogLevel, "log-level", "info", "set log level")
    38  	// Parse flags
    39  	flag.Parse()
    40  }
    41  
    42  // ToRedisOperatorConfig convert the flags to redisfailover config
    43  func (c *CMDFlags) ToRedisOperatorConfig() redisfailover.Config {
    44  	return redisfailover.Config{
    45  		ListenAddress: c.ListenAddr,
    46  		MetricsPath:   c.MetricsPath,
    47  		Concurrency:   c.Concurrency,
    48  	}
    49  }