From 44cee9a7e3205523f906299e975cbef7b944609c Mon Sep 17 00:00:00 2001 From: Vince Prignano Date: Wed, 18 Oct 2023 12:09:35 -0700 Subject: [PATCH] Allow to customize webhook server port and cert dir Signed-off-by: Vince Prignano --- main.go | 10 ++++++---- v2/cmd/controller/app/flags.go | 8 ++++++++ v2/cmd/controller/app/setup.go | 7 ++++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 307a5aa01d4..d623cf4999a 100644 --- a/main.go +++ b/main.go @@ -37,7 +37,6 @@ var ( ) func init() { - _ = kscheme.AddToScheme(scheme) _ = azurev1alpha1.AddToScheme(scheme) _ = azurev1beta1.AddToScheme(scheme) @@ -57,10 +56,14 @@ func init() { func main() { var metricsAddr string var enableLeaderElection bool + var webhookServerPort int + var webhookServerCertDir string var secretClient secrets.SecretClient flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.") flag.BoolVar(&enableLeaderElection, "enable-leader-election", false, "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.") + flag.IntVar(&webhookServerPort, "webhook-server-port", 9443, "The port the webhook endpoint binds to.") + flag.StringVar(&webhookServerCertDir, "webhook-server-cert-dir", "", "The directory the webhook server's certs are stored.") flag.Parse() @@ -96,10 +99,10 @@ func main() { BindAddress: metricsAddr, }, WebhookServer: webhook.NewServer(webhook.Options{ - Port: 9443, + Port: webhookServerPort, + CertDir: webhookServerCertDir, }), }) - if err != nil { setupLog.Error(err, "unable to start manager") os.Exit(1) @@ -140,5 +143,4 @@ func main() { setupLog.Error(err, "problem running manager") os.Exit(1) } - } diff --git a/v2/cmd/controller/app/flags.go b/v2/cmd/controller/app/flags.go index 7725866824e..61a1624201d 100644 --- a/v2/cmd/controller/app/flags.go +++ b/v2/cmd/controller/app/flags.go @@ -17,6 +17,8 @@ import ( type Flags struct { MetricsAddr string HealthAddr string + WebhookPort int + WebhookCertDir string EnableLeaderElection bool CRDPatterns string // This is a ; delimited string containing a collection of patterns PreUpgradeCheck bool @@ -39,6 +41,8 @@ func ParseFlags(args []string) (Flags, error) { var metricsAddr string var healthAddr string + var webhookServerPort int + var webhookServerCertDir string var enableLeaderElection bool var crdPatterns string var preUpgradeCheck bool @@ -46,6 +50,8 @@ func ParseFlags(args []string) (Flags, error) { // default here for 'MetricsAddr' is set to "0", which sets metrics to be disabled if 'metrics-addr' flag is omitted. flagSet.StringVar(&metricsAddr, "metrics-addr", "0", "The address the metric endpoint binds to.") flagSet.StringVar(&healthAddr, "health-addr", "", "The address the healthz endpoint binds to.") + flag.IntVar(&webhookServerPort, "webhook-server-port", 9443, "The port the webhook endpoint binds to.") + flag.StringVar(&webhookServerCertDir, "webhook-server-cert-dir", "", "The directory the webhook server's certs are stored.") flagSet.BoolVar(&enableLeaderElection, "enable-leader-election", false, "Enable leader election for controllers manager. Enabling this will ensure there is only one active controllers manager.") flagSet.StringVar(&crdPatterns, "crd-pattern", "", "Install these CRDs. CRDs already in the cluster will also always be upgraded.") @@ -57,6 +63,8 @@ func ParseFlags(args []string) (Flags, error) { return Flags{ MetricsAddr: metricsAddr, HealthAddr: healthAddr, + WebhookPort: webhookServerPort, + WebhookCertDir: webhookServerCertDir, EnableLeaderElection: enableLeaderElection, CRDPatterns: crdPatterns, PreUpgradeCheck: preUpgradeCheck, diff --git a/v2/cmd/controller/app/setup.go b/v2/cmd/controller/app/setup.go index d5012247040..55900e1b2ca 100644 --- a/v2/cmd/controller/app/setup.go +++ b/v2/cmd/controller/app/setup.go @@ -11,9 +11,10 @@ import ( "math/rand" "os" "regexp" + "time" + "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook" - "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" @@ -134,10 +135,10 @@ func SetupControllerManager(ctx context.Context, setupLog logr.Logger, flgs Flag BindAddress: flgs.MetricsAddr, }, WebhookServer: webhook.NewServer(webhook.Options{ - Port: 9443, + Port: flgs.WebhookPort, + CertDir: flgs.WebhookCertDir, }), }) - if err != nil { setupLog.Error(err, "unable to create manager") os.Exit(1)