From 47d7f6606ae70c7a31735e0bdd1c22f10e41af92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Th=C3=B6mmes?= Date: Wed, 9 Sep 2020 21:00:36 +0200 Subject: [PATCH] Refactor main functions to reuse helpers from package. --- cmd/mtbroker/filter/main.go | 21 ++------------------- cmd/mtbroker/ingress/main.go | 21 ++------------------- 2 files changed, 4 insertions(+), 38 deletions(-) diff --git a/cmd/mtbroker/filter/main.go b/cmd/mtbroker/filter/main.go index d61f5f42cb6..07b57982c14 100644 --- a/cmd/mtbroker/filter/main.go +++ b/cmd/mtbroker/filter/main.go @@ -17,14 +17,11 @@ package main import ( - "flag" "fmt" "log" - "time" "github.com/google/uuid" "github.com/kelseyhightower/envconfig" - "go.opencensus.io/stats/view" "go.uber.org/zap" broker "knative.dev/eventing/cmd/mtbroker" @@ -48,11 +45,6 @@ import ( eventinginformers "knative.dev/eventing/pkg/client/informers/externalversions" ) -var ( - masterURL = flag.String("master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.") - kubeconfig = flag.String("kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.") -) - const ( defaultMetricsPort = 9092 component = "mt_broker_filter" @@ -67,21 +59,12 @@ type envConfig struct { } func main() { - flag.Parse() - ctx := signals.NewContext() // Report stats on Go memory usage every 30 seconds. - msp := metrics.NewMemStatsAll() - msp.Start(ctx, 30*time.Second) - if err := view.Register(msp.DefaultViews()...); err != nil { - log.Fatalf("Error exporting go memstats view: %v", err) - } + sharedmain.MemStatsOrDie(ctx) - cfg, err := sharedmain.GetConfig(*masterURL, *kubeconfig) - if err != nil { - log.Fatal("Error building kubeconfig", err) - } + cfg := sharedmain.ParseAndGetConfigOrDie() var env envConfig if err := envconfig.Process("", &env); err != nil { diff --git a/cmd/mtbroker/ingress/main.go b/cmd/mtbroker/ingress/main.go index a5b9114a332..4c7d0a29c6c 100644 --- a/cmd/mtbroker/ingress/main.go +++ b/cmd/mtbroker/ingress/main.go @@ -17,17 +17,14 @@ package main import ( - "flag" "fmt" "log" - "time" // Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters). // _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" "github.com/google/uuid" "github.com/kelseyhightower/envconfig" - "go.opencensus.io/stats/view" "go.uber.org/zap" cmdbroker "knative.dev/eventing/cmd/mtbroker" @@ -50,11 +47,6 @@ import ( tracingconfig "knative.dev/pkg/tracing/config" ) -var ( - masterURL = flag.String("master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.") - kubeconfig = flag.String("kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.") -) - // TODO make these constants configurable (either as env variables, config map, or part of broker spec). // Issue: https://github.com/knative/eventing/issues/1777 const ( @@ -77,21 +69,12 @@ type envConfig struct { } func main() { - flag.Parse() - ctx := signals.NewContext() // Report stats on Go memory usage every 30 seconds. - msp := metrics.NewMemStatsAll() - msp.Start(ctx, 30*time.Second) - if err := view.Register(msp.DefaultViews()...); err != nil { - log.Fatalf("Error exporting go memstats view: %v", err) - } + sharedmain.MemStatsOrDie(ctx) - cfg, err := sharedmain.GetConfig(*masterURL, *kubeconfig) - if err != nil { - log.Fatal("Error building kubeconfig", err) - } + cfg := sharedmain.ParseAndGetConfigOrDie() var env envConfig if err := envconfig.Process("", &env); err != nil {