From af455627040a4c21bd480091b4ca5d818579d5e1 Mon Sep 17 00:00:00 2001 From: David T <107210217+tekicode@users.noreply.github.com> Date: Mon, 2 Oct 2023 21:16:03 -0700 Subject: [PATCH] refactor flags into parseFlags() due to lint limit --- main.go | 53 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/main.go b/main.go index 2a62109..289e958 100644 --- a/main.go +++ b/main.go @@ -58,25 +58,27 @@ const ( other label = "other" ) -func main() { - config := struct { - KubeConfig string - Namespace string - StatefulSetLabel string - Label string - ClusterDomain string - ConfigMapName string - ConfigMapGeneratedName string - FileName string - Port int - Scheme string - InternalAddr string - AllowOnlyReadyReplicas bool - AllowDynamicScaling bool - AnnotatePodsOnChange bool - ScaleTimeout time.Duration - }{} +type CmdConfig struct { + KubeConfig string + Namespace string + StatefulSetLabel string + Label string + ClusterDomain string + ConfigMapName string + ConfigMapGeneratedName string + FileName string + Port int + Scheme string + InternalAddr string + AllowOnlyReadyReplicas bool + AllowDynamicScaling bool + AnnotatePodsOnChange bool + ScaleTimeout time.Duration +} +func parseFlags() CmdConfig { + + var config CmdConfig flag.StringVar(&config.KubeConfig, "kubeconfig", "", "Path to kubeconfig") flag.StringVar(&config.Namespace, "namespace", "default", "The namespace to watch") flag.StringVar(&config.StatefulSetLabel, "statefulset-label", "", "[DEPRECATED] The label StatefulSets must have to be watched by the controller") @@ -94,19 +96,26 @@ func main() { flag.DurationVar(&config.ScaleTimeout, "scale-timeout", defaultScaleTimeout, "A timeout to wait for receivers to really start after they report healthy") flag.Parse() + return config +} + +func main() { logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) logger = log.WithPrefix(logger, "ts", log.DefaultTimestampUTC) logger = log.WithPrefix(logger, "caller", log.DefaultCaller) - var controllerLabel string + config := parseFlags() + + var tmpControllerLabel string if len(config.StatefulSetLabel) > 0 { + tmpControllerLabel = config.StatefulSetLabel + level.Warn(logger).Log("msg", "The --statefulset-label flag is deprecated. Please see the manual page for updates.") - controllerLabel = config.StatefulSetLabel } else { - controllerLabel = config.Label + tmpControllerLabel = config.Label } - labelKey, labelValue := splitLabel(controllerLabel) + labelKey, labelValue := splitLabel(tmpControllerLabel) konfig, err := clientcmd.BuildConfigFromFlags("", config.KubeConfig) if err != nil {