Skip to content

Commit

Permalink
Issue 509: Make metrics server port configurable
Browse files Browse the repository at this point in the history
Adds a flag to the controller to support configuring a non-default port for the
metrics collection.

This resolves an issue where running secretgen-controller with hostNetwork=true
may lead to port conflicts on the node.

Testing Done:
 - Built and ensured passing tests locally
 - Deployed in a Kind cluster and loaded Docker image onto cluster
 - Edited Deployment to add new container arg: -metrics-bind-address=:8093
 - Confirmed new secretgen-controller Pod logged the change:
    ... "msg":"Metrics server is starting to listen","addr":":8093"} ...

Signed-off-by: Doug Cook <[email protected]>
  • Loading branch information
Doug Cook committed Dec 7, 2023
1 parent a0e1378 commit 3b7dc33
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ var (
// Version of secretgen-controller is set via ldflags at build-time from most recent git tag
Version = "develop"

log = logf.Log.WithName("sg")
ctrlNamespace = ""
log = logf.Log.WithName("sg")
ctrlNamespace = ""
metricsBindAddress = ""
)

func main() {
flag.StringVar(&ctrlNamespace, "namespace", "", "Namespace to watch")
flag.StringVar(&metricsBindAddress, "metrics-bind-address", ":8080", "Address for metrics server. If 0, then metrics server doesnt listen on any port.")
flag.Parse()

logf.SetLogger(zap.New(zap.UseDevMode(false)))
Expand All @@ -56,7 +58,7 @@ func main() {
sgv1alpha1.AddToScheme(scheme.Scheme)
sg2v1alpha1.AddToScheme(scheme.Scheme)

mgr, err := manager.New(restConfig, manager.Options{Namespace: ctrlNamespace})
mgr, err := manager.New(restConfig, manager.Options{Namespace: ctrlNamespace, MetricsBindAddress: metricsBindAddress})
exitIfErr(entryLog, "unable to set up controller manager", err)

entryLog.Info("setting up controllers")
Expand Down

0 comments on commit 3b7dc33

Please sign in to comment.