Skip to content

Commit

Permalink
Allow users to customize webhook-port and webhook-cert-dir (Azure#3442)
Browse files Browse the repository at this point in the history
Signed-off-by: Vince Prignano <vince@prigna.com>
  • Loading branch information
vincepri committed Oct 19, 2023
1 parent 4d6a142 commit c490de2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions v2/cmd/controller/app/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
type Flags struct {
MetricsAddr string
HealthAddr string
WebhookPort int
WebhookCertDir string
EnableLeaderElection bool
EnableCRDManagement bool
CRDPatterns string // This is a ; delimited string containing a collection of patterns
Expand All @@ -28,6 +30,8 @@ func (f Flags) String() string {
"MetricsAddr: %s, HealthAddr: %s, Webhook=Port: %d, WebhookCertDir: %s, EnableLeaderElection: %t, EnableCRDManagement: %t, CRDPatterns: %s, PreUpgradeCheck: %t",
f.MetricsAddr,
f.HealthAddr,
f.WebhookPort,
f.WebhookCertDir,
f.EnableLeaderElection,
f.EnableCRDManagement,
f.CRDPatterns,
Expand All @@ -41,6 +45,8 @@ func ParseFlags(args []string) (Flags, error) {

var metricsAddr string
var healthAddr string
var webhookPort int
var webhookCertDir string
var enableLeaderElection bool
var enableCRDmanagement bool
var crdPatterns string
Expand All @@ -49,6 +55,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.")
flagSet.IntVar(&webhookPort, "webhook-port", 9443, "The port the webhook endpoint binds to.")
flagSet.StringVar(&webhookCertDir, "webhook-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.BoolVar(&enableCRDmanagement, "enable-crd-management", true,
Expand All @@ -62,6 +70,8 @@ func ParseFlags(args []string) (Flags, error) {
return Flags{
MetricsAddr: metricsAddr,
HealthAddr: healthAddr,
WebhookPort: webhookPort,
WebhookCertDir: webhookCertDir,
EnableLeaderElection: enableLeaderElection,
EnableCRDManagement: enableCRDmanagement,
CRDPatterns: crdPatterns,
Expand Down
6 changes: 4 additions & 2 deletions v2/cmd/controller/app/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/webhook"

Expand Down Expand Up @@ -125,8 +124,11 @@ func SetupControllerManager(ctx context.Context, setupLog logr.Logger, flgs Flag
LeaderElectionID: "controllers-leader-election-azinfra-generated",
Port: 9443,
HealthProbeBindAddress: flgs.HealthAddr,
WebhookServer: webhook.NewServer(webhook.Options{
Port: flgs.WebhookPort,
CertDir: flgs.WebhookCertDir,
}),
})

if err != nil {
setupLog.Error(err, "unable to create manager")
os.Exit(1)
Expand Down

0 comments on commit c490de2

Please sign in to comment.