Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to customize webhook server port and cert dir #3442

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion v2/cmd/controller/app/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ 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
}

func (f Flags) String() string {
return fmt.Sprintf(
"MetricsAddr: %s, HealthAddr: %s, EnableLeaderElection: %t, CRDPatterns: %s, PreUpgradeCheck: %t",
"MetricsAddr: %s, HealthAddr: %s, WebhookServerPort: %d, WebhookServerCertDir: %s, EnableLeaderElection: %t, CRDPatterns: %s, PreUpgradeCheck: %t",
f.MetricsAddr,
f.HealthAddr,
f.WebhookPort,
f.WebhookCertDir,
f.EnableLeaderElection,
f.CRDPatterns,
f.PreUpgradeCheck)
Expand All @@ -39,13 +43,17 @@ func ParseFlags(args []string) (Flags, error) {

var metricsAddr string
var healthAddr string
var webhookPort int
var webhookCertDir 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.")
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.StringVar(&crdPatterns, "crd-pattern", "", "Install these CRDs. CRDs already in the cluster will also always be upgraded.")
Expand All @@ -57,6 +65,8 @@ func ParseFlags(args []string) (Flags, error) {
return Flags{
MetricsAddr: metricsAddr,
HealthAddr: healthAddr,
WebhookPort: webhookPort,
WebhookCertDir: webhookCertDir,
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