Skip to content

Commit 5d5b024

Browse files
authored
Merge pull request #316 from defo89/webhook-disable-env
🌱 add webhook flags
2 parents 21b04e6 + 19635b4 commit 5d5b024

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

main.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"sigs.k8s.io/controller-runtime/pkg/cache"
3535
"sigs.k8s.io/controller-runtime/pkg/healthz"
3636
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
37+
"sigs.k8s.io/controller-runtime/pkg/webhook"
3738

3839
"sigs.k8s.io/cluster-api-ipam-provider-in-cluster/api/v1alpha1"
3940
"sigs.k8s.io/cluster-api-ipam-provider-in-cluster/api/v1alpha2"
@@ -65,6 +66,10 @@ func main() {
6566
probeAddr string
6667
watchNamespace string
6768
watchFilter string
69+
webhookPort int
70+
webhookCertDir string
71+
webhookCertName string
72+
webhookKeyName string
6873
)
6974
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
7075
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
@@ -74,6 +79,10 @@ func main() {
7479
flag.StringVar(&watchNamespace, "namespace", "",
7580
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.")
7681
flag.StringVar(&watchFilter, "watch-filter", "", "")
82+
flag.IntVar(&webhookPort, "webhook-port", 9443, "Webhook Server port.")
83+
flag.StringVar(&webhookCertDir, "webhook-cert-dir", "/tmp/k8s-webhook-server/serving-certs/", "Webhook cert dir.")
84+
flag.StringVar(&webhookCertName, "webhook-cert-name", "tls.crt", "Webhook cert name.")
85+
flag.StringVar(&webhookKeyName, "webhook-key-name", "tls.key", "Webhook key name.")
7786
flag.Parse()
7887

7988
// klog.Background will automatically use the right logger.
@@ -89,6 +98,14 @@ func main() {
8998
HealthProbeBindAddress: probeAddr,
9099
LeaderElection: enableLeaderElection,
91100
LeaderElectionID: "7bb7acb4.ipam.cluster.x-k8s.io",
101+
WebhookServer: webhook.NewServer(
102+
webhook.Options{
103+
Port: webhookPort,
104+
CertDir: webhookCertDir,
105+
CertName: webhookCertName,
106+
KeyName: webhookKeyName,
107+
},
108+
),
92109
}
93110

94111
if watchNamespace != "" {
@@ -137,9 +154,11 @@ func main() {
137154
os.Exit(1)
138155
}
139156

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)
157+
if webhookPort != 0 {
158+
if err := (&webhooks.InClusterIPPool{Client: mgr.GetClient()}).SetupWebhookWithManager(mgr); err != nil {
159+
setupLog.Error(err, "unable to create webhook", "webhook", "InClusterIPPool")
160+
os.Exit(1)
161+
}
143162
}
144163
//+kubebuilder:scaffold:builder
145164

0 commit comments

Comments
 (0)