Skip to content

Commit 483c9ae

Browse files
Merge pull request #285 from karelyatin/custom_webhook_port
Make local webhook port configurable
2 parents 7896446 + 77e127f commit 483c9ae

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ SKIP_CERT ?=false
372372
run-with-webhook: export METRICS_PORT?=8080
373373
run-with-webhook: export HEALTH_PORT?=8081
374374
run-with-webhook: export PPROF_PORT?=8082
375+
run-with-webhook: export WEBHOOK_PORT?=9443
375376
run-with-webhook: manifests generate fmt vet ## Run a controller from your host.
376377
/bin/bash hack/run_with_local_webhook.sh
377378

hack/run_with_local_webhook.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ TMPDIR=${TMPDIR:-"/tmp/k8s-webhook-server/serving-certs"}
1515
SKIP_CERT=${SKIP_CERT:-false}
1616
CRC_IP=${CRC_IP:-$(/sbin/ip -o -4 addr list crc | awk '{print $4}' | cut -d/ -f1)}
1717
FIREWALL_ZONE=${FIREWALL_ZONE:-"libvirt"}
18+
WEBHOOK_PORT=${WEBHOOK_PORT:-${WEBHOOK_PORT}}
1819

19-
#Open 9443
20+
#Open ${WEBHOOK_PORT}
2021
if command -v firewall-cmd &> /dev/null; then
21-
sudo firewall-cmd --zone=${FIREWALL_ZONE} --add-port=9443/tcp
22+
sudo firewall-cmd --zone=${FIREWALL_ZONE} --add-port=${WEBHOOK_PORT}/tcp
2223
sudo firewall-cmd --runtime-to-permanent
2324
fi
2425

@@ -50,7 +51,7 @@ webhooks:
5051
- v1
5152
clientConfig:
5253
caBundle: ${CA_BUNDLE}
53-
url: https://${CRC_IP}:9443/validate-barbican-openstack-org-v1beta1-barbican
54+
url: https://${CRC_IP}:${WEBHOOK_PORT}/validate-barbican-openstack-org-v1beta1-barbican
5455
failurePolicy: Fail
5556
matchPolicy: Equivalent
5657
name: vbarbican.kb.io
@@ -78,7 +79,7 @@ webhooks:
7879
- v1
7980
clientConfig:
8081
caBundle: ${CA_BUNDLE}
81-
url: https://${CRC_IP}:9443/mutate-barbican-openstack-org-v1beta1-barbican
82+
url: https://${CRC_IP}:${WEBHOOK_PORT}/mutate-barbican-openstack-org-v1beta1-barbican
8283
failurePolicy: Fail
8384
matchPolicy: Equivalent
8485
name: mbarbican.kb.io
@@ -134,4 +135,4 @@ else
134135
oc scale --replicas=0 -n openstack-operators deploy/barbican-operator-controller-manager
135136
fi
136137

137-
go run ./main.go -metrics-bind-address ":${METRICS_PORT}" -health-probe-bind-address ":${HEALTH_PORT}" -pprof-bind-address ":${PPROF_PORT}"
138+
go run ./main.go -metrics-bind-address ":${METRICS_PORT}" -health-probe-bind-address ":${HEALTH_PORT}" -pprof-bind-address ":${PPROF_PORT}" -webhook-bind-address "${WEBHOOK_PORT}"

main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ func main() {
7272
var enableLeaderElection bool
7373
var probeAddr string
7474
var pprofBindAddress string
75+
var webhookPort int
7576
var enableHTTP2 bool
7677
flag.BoolVar(&enableHTTP2, "enable-http2", enableHTTP2, "If HTTP/2 should be enabled for the metrics and webhook servers.")
7778
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8085", "The address the metric endpoint binds to.")
7879
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8086", "The address the probe endpoint binds to.")
7980
flag.StringVar(&pprofBindAddress, "pprof-bind-address", "", "The address the pprof endpoint binds to. Set to empty to disable pprof.")
81+
flag.IntVar(&webhookPort, "webhook-bind-address", 9443, "The port the webhook server binds to.")
8082
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
8183
"Enable leader election for controller manager. "+
8284
"Enabling this will ensure there is only one active controller manager.")
@@ -106,7 +108,7 @@ func main() {
106108
PprofBindAddress: pprofBindAddress,
107109
WebhookServer: webhook.NewServer(
108110
webhook.Options{
109-
Port: 9443,
111+
Port: webhookPort,
110112
TLSOpts: []func(config *tls.Config){disableHTTP2},
111113
}),
112114
}

0 commit comments

Comments
 (0)