From acb8351e155974857ca3d4d52b26daeb61549fd5 Mon Sep 17 00:00:00 2001 From: Daniel Helfand Date: Thu, 21 Oct 2021 10:51:18 -0500 Subject: [PATCH] make metrics server port configurable (#404) --- cmd/controller/run.go | 14 ++++++++------ cmd/main.go | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cmd/controller/run.go b/cmd/controller/run.go index dcfcb8cb0..13ad42b46 100644 --- a/cmd/controller/run.go +++ b/cmd/controller/run.go @@ -35,11 +35,12 @@ const ( ) type Options struct { - Concurrency int - Namespace string - EnablePprof bool - APIRequestTimeout time.Duration - PackagingGloablNS string + Concurrency int + Namespace string + EnablePprof bool + APIRequestTimeout time.Duration + PackagingGloablNS string + MetricsBindAddress string } // Based on https://github.com/kubernetes-sigs/controller-runtime/blob/8f633b179e1c704a6e40440b528252f147a3362a/examples/builtins/main.go @@ -53,7 +54,8 @@ func Run(opts Options, runLog logr.Logger) error { restConfig.Timeout = opts.APIRequestTimeout } - mgr, err := manager.New(restConfig, manager.Options{Namespace: opts.Namespace, Scheme: kcconfig.Scheme}) + mgr, err := manager.New(restConfig, manager.Options{Namespace: opts.Namespace, + Scheme: kcconfig.Scheme, MetricsBindAddress: opts.MetricsBindAddress}) if err != nil { return fmt.Errorf("Setting up overall controller manager: %s", err) } diff --git a/cmd/main.go b/cmd/main.go index 87caf0ac7..2284dc27f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -25,6 +25,7 @@ func main() { flag.IntVar(&ctrlOpts.Concurrency, "concurrency", 10, "Max concurrent reconciles") flag.StringVar(&ctrlOpts.Namespace, "namespace", "", "Namespace to watch") flag.StringVar(&ctrlOpts.PackagingGloablNS, "packaging-global-namespace", "", "The namespace used for global packaging resources") + flag.StringVar(&ctrlOpts.MetricsBindAddress, "metrics-bind-address", ":8080", "Address for metrics server. If 0, then metrics server doesnt listen on any port.") flag.BoolVar(&ctrlOpts.EnablePprof, "dangerous-enable-pprof", false, "If set to true, enable pprof on "+controller.PprofListenAddr) flag.DurationVar(&ctrlOpts.APIRequestTimeout, "api-request-timeout", time.Duration(0), "HTTP timeout for Kubernetes API requests") flag.BoolVar(&runController, controllerinit.InternalControllerFlag, false, "[Internal] run the controller code")