Skip to content

Commit 7df4a4a

Browse files
committed
chore: add wenhook flags and allow disabling them
1 parent 423d068 commit 7df4a4a

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

main.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"flag"
2222
"os"
2323

24+
"sigs.k8s.io/controller-runtime/pkg/webhook"
25+
2426
//+kubebuilder:scaffold:imports
2527
"k8s.io/apimachinery/pkg/runtime"
2628
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@@ -65,6 +67,10 @@ func main() {
6567
probeAddr string
6668
watchNamespace string
6769
watchFilter string
70+
webhookPort int
71+
webhookCertDir string
72+
webhookCertName string
73+
webhookKeyName string
6874
)
6975
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
7076
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
@@ -74,6 +80,10 @@ func main() {
7480
flag.StringVar(&watchNamespace, "namespace", "",
7581
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.")
7682
flag.StringVar(&watchFilter, "watch-filter", "", "")
83+
flag.IntVar(&webhookPort, "webhook-port", 9443, "Webhook Server port.")
84+
flag.StringVar(&webhookCertDir, "webhook-cert-dir", "/tmp/k8s-webhook-server/serving-certs/", "Webhook cert dir.")
85+
flag.StringVar(&webhookCertName, "webhook-cert-name", "tls.crt", "Webhook cert name.")
86+
flag.StringVar(&webhookKeyName, "webhook-key-name", "tls.key", "Webhook key name.")
7787
flag.Parse()
7888

7989
// klog.Background will automatically use the right logger.
@@ -89,6 +99,14 @@ func main() {
8999
HealthProbeBindAddress: probeAddr,
90100
LeaderElection: enableLeaderElection,
91101
LeaderElectionID: "7bb7acb4.ipam.cluster.x-k8s.io",
102+
WebhookServer: webhook.NewServer(
103+
webhook.Options{
104+
Port: webhookPort,
105+
CertDir: webhookCertDir,
106+
CertName: webhookCertName,
107+
KeyName: webhookKeyName,
108+
},
109+
),
92110
}
93111

94112
if watchNamespace != "" {
@@ -137,9 +155,11 @@ func main() {
137155
os.Exit(1)
138156
}
139157

140-
if err := (&webhooks.InClusterIPPool{Client: mgr.GetClient()}).SetupWebhookWithManager(mgr); err != nil {
141-
setupLog.Error(err, "unable to create webhook", "webhook", "InClusterIPPool")
142-
os.Exit(1)
158+
if webhookPort != 0 {
159+
if err := (&webhooks.InClusterIPPool{Client: mgr.GetClient()}).SetupWebhookWithManager(mgr); err != nil {
160+
setupLog.Error(err, "unable to create webhook", "webhook", "InClusterIPPool")
161+
os.Exit(1)
162+
}
143163
}
144164
//+kubebuilder:scaffold:builder
145165

0 commit comments

Comments
 (0)