Skip to content

Commit

Permalink
Refactor main functions to reuse helpers from package. (#4021)
Browse files Browse the repository at this point in the history
  • Loading branch information
markusthoemmes authored Sep 9, 2020
1 parent 146ddcc commit 8e63db0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 38 deletions.
21 changes: 2 additions & 19 deletions cmd/mtbroker/filter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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 {
Expand Down
21 changes: 2 additions & 19 deletions cmd/mtbroker/ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand All @@ -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 {
Expand Down

0 comments on commit 8e63db0

Please sign in to comment.