Skip to content

Commit

Permalink
refactor flags into parseFlags() due to lint limit
Browse files Browse the repository at this point in the history
  • Loading branch information
tekicode committed Oct 3, 2023
1 parent 519d41c commit af45562
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Check failure on line 82 in main.go

View workflow job for this annotation

GitHub Actions / Lint (ubuntu-latest)

expressions should not be cuddled with declarations or returns (wsl)
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")
Expand All @@ -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 {
Expand Down

0 comments on commit af45562

Please sign in to comment.