Skip to content

Commit 1cbe82a

Browse files
committed
Make local webhook port configurable
Will be helpful when running multiple operators locally
1 parent 7e1d7f6 commit 1cbe82a

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
@@ -336,6 +336,7 @@ SKIP_CERT ?=false
336336
run-with-webhook: export METRICS_PORT?=8080
337337
run-with-webhook: export HEALTH_PORT?=8081
338338
run-with-webhook: export PPROF_PORT?=8082
339+
run-with-webhook: export WEBHOOK_PORT?=9443
339340
run-with-webhook: manifests generate fmt vet ## Run a controller from your host.
340341
/bin/bash hack/run_with_local_webhook.sh
341342

hack/run_with_local_webhook.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ trap cleanup SIGINT SIGTERM
1414
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)}
17+
WEBHOOK_PORT=${WEBHOOK_PORT:-${WEBHOOK_PORT}}
1718

18-
#Open 9443
19-
sudo firewall-cmd --zone=libvirt --add-port=9443/tcp || :
19+
#Open ${WEBHOOK_PORT}
20+
sudo firewall-cmd --zone=libvirt --add-port=${WEBHOOK_PORT}/tcp || :
2021
sudo firewall-cmd --runtime-to-permanent || :
2122

2223
# Generate the certs and the ca bundle
@@ -47,7 +48,7 @@ webhooks:
4748
- v1
4849
clientConfig:
4950
caBundle: ${CA_BUNDLE}
50-
url: https://${CRC_IP}:9443/validate-designate-openstack-org-v1beta1-designate
51+
url: https://${CRC_IP}:${WEBHOOK_PORT}/validate-designate-openstack-org-v1beta1-designate
5152
failurePolicy: Fail
5253
matchPolicy: Equivalent
5354
name: vdesignate.kb.io
@@ -75,7 +76,7 @@ webhooks:
7576
- v1
7677
clientConfig:
7778
caBundle: ${CA_BUNDLE}
78-
url: https://${CRC_IP}:9443/mutate-designate-openstack-org-v1beta1-designate
79+
url: https://${CRC_IP}:${WEBHOOK_PORT}/mutate-designate-openstack-org-v1beta1-designate
7980
failurePolicy: Fail
8081
matchPolicy: Equivalent
8182
name: mdesignate.kb.io
@@ -131,4 +132,4 @@ else
131132
oc scale --replicas=0 -n openstack-operators deploy/designate-operator-controller-manager
132133
fi
133134

134-
go run ./main.go -metrics-bind-address ":${METRICS_PORT}" -health-probe-bind-address ":${HEALTH_PORT}" -pprof-bind-address ":${PPROF_PORT}"
135+
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
@@ -74,11 +74,13 @@ func main() {
7474
var enableLeaderElection bool
7575
var probeAddr string
7676
var pprofBindAddress string
77+
var webhookPort int
7778
var enableHTTP2 bool
7879
flag.BoolVar(&enableHTTP2, "enable-http2", enableHTTP2, "If HTTP/2 should be enabled for the metrics and webhook servers.")
7980
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
8081
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
8182
flag.StringVar(&pprofBindAddress, "pprof-bind-address", "", "The address the pprof endpoint binds to. Set to empty to disable pprof.")
83+
flag.IntVar(&webhookPort, "webhook-bind-address", 9443, "The port the webhook server binds to.")
8284
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
8385
"Enable leader election for controller manager. "+
8486
"Enabling this will ensure there is only one active controller manager.")
@@ -108,7 +110,7 @@ func main() {
108110
PprofBindAddress: pprofBindAddress,
109111
WebhookServer: webhook.NewServer(
110112
webhook.Options{
111-
Port: 9443,
113+
Port: webhookPort,
112114
TLSOpts: []func(config *tls.Config){disableHTTP2},
113115
}),
114116
}

0 commit comments

Comments
 (0)