Skip to content

Commit

Permalink
Add --metrics-addr argument to controller
Browse files Browse the repository at this point in the history
We want to be able to override the bind address of the metrics server.
Omitting the argument preserves the original behaviour for backwards
compatibility.
  • Loading branch information
honza committed Nov 29, 2023
1 parent 4677f06 commit c1a55de
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func setupChecks(mgr ctrl.Manager) error {
return nil
}

func runController(watchNamespace string, imageServer imagehandler.ImageHandler, envInputs *env.EnvInputs) error {
func runController(watchNamespace string, imageServer imagehandler.ImageHandler, envInputs *env.EnvInputs, metricsBindAddr string) error {
excludeInfraEnv, err := labels.NewRequirement(infraEnvLabel, selection.DoesNotExist, nil)
if err != nil {
setupLog.Error(err, "cannot create an infraenv label filter")
Expand All @@ -89,10 +89,11 @@ func runController(watchNamespace string, imageServer imagehandler.ImageHandler,
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Port: 0, // Add flag with default of 9443 when adding webhooks
Namespace: watchNamespace,
Cache: cacheOptions,
Scheme: scheme,
Port: 0, // Add flag with default of 9443 when adding webhooks
Namespace: watchNamespace,
Cache: cacheOptions,
MetricsBindAddress: metricsBindAddr,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down Expand Up @@ -123,6 +124,7 @@ func runController(watchNamespace string, imageServer imagehandler.ImageHandler,

func main() {
var watchNamespace string
var metricsBindAddr string
var devLogging bool
var imagesBindAddr string
var imagesPublishAddr string
Expand All @@ -133,6 +135,8 @@ func main() {
// namespace.
flag.StringVar(&watchNamespace, "namespace", os.Getenv("WATCH_NAMESPACE"),
"Namespace that the controller watches to reconcile preprovisioningimage resources.")
flag.StringVar(&metricsBindAddr, "metrics-addr", "",
"The address the metric endpoint binds to.")
flag.StringVar(&imagesBindAddr, "images-bind-addr", ":8084",
"The address the images endpoint binds to.")
flag.StringVar(&imagesPublishAddr, "images-publish-addr", "http://127.0.0.1:8084",
Expand Down Expand Up @@ -172,7 +176,7 @@ func main() {
}
}()

if err := runController(watchNamespace, imageServer, envInputs); err != nil {
if err := runController(watchNamespace, imageServer, envInputs, metricsBindAddr); err != nil {
setupLog.Error(err, "problem running controller")
os.Exit(1)
}
Expand Down

0 comments on commit c1a55de

Please sign in to comment.