Skip to content

Commit

Permalink
Allow to customize webhook server port and cert dir
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 18, 2023
1 parent bd80948 commit 44cee9a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
10 changes: 6 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ var (
)

func init() {

_ = kscheme.AddToScheme(scheme)
_ = azurev1alpha1.AddToScheme(scheme)
_ = azurev1beta1.AddToScheme(scheme)
Expand All @@ -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()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -140,5 +143,4 @@ func main() {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}

}
8 changes: 8 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
CRDPatterns string // This is a ; delimited string containing a collection of patterns
PreUpgradeCheck bool
Expand All @@ -39,13 +41,17 @@ 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

// 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.")
Expand All @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions v2/cmd/controller/app/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 44cee9a

Please sign in to comment.