Skip to content

Commit 505d03f

Browse files
committed
Make local webhook port configurable
Will be helpful when running multiple operators locally
1 parent e98cf89 commit 505d03f

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,16 @@ build: generate fmt vet ## Build manager binary.
143143

144144
.PHONY: run
145145
run: export METRICS_PORT?=8080
146+
run: export WEBHOOK_PORT?=9443
146147
run: export HEALTH_PORT?=8081
148+
run: export WEBHOOK_PORT?=9443
147149
run: export PPROF_PORT?=8082
150+
run: export WEBHOOK_PORT?=9443
148151
run: export OPERATOR_TEMPLATES=./templates/
149152
run: export ENABLE_WEBHOOKS?=false
150153
run: manifests generate fmt vet ## Run a controller from your host.
151154
/bin/bash hack/clean_local_webhook.sh
152-
go run ./main.go -metrics-bind-address ":$(METRICS_PORT)" -health-probe-bind-address ":$(HEALTH_PORT)" -pprof-bind-address ":$(PPROF_PORT)"
155+
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)"
153156

154157
.PHONY: docker-build
155158
docker-build: test ## Build docker image with the manager.
@@ -376,8 +379,11 @@ gowork: ## Generate go.work file
376379
SKIP_CERT ?=false
377380
.PHONY: run-with-webhook
378381
run-with-webhook: export METRICS_PORT?=8080
382+
run-with-webhook: export WEBHOOK_PORT?=9443
379383
run-with-webhook: export HEALTH_PORT?=8081
384+
run-with-webhook: export WEBHOOK_PORT?=9443
380385
run-with-webhook: export PPROF_PORT?=8082
386+
run-with-webhook: export WEBHOOK_PORT?=9443
381387
run-with-webhook: manifests generate fmt vet ## Run a controller from your host.
382388
/bin/bash hack/run_with_local_webhook.sh
383389

hack/run_with_local_webhook.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ 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-
sudo firewall-cmd --zone=${FIREWALL_ZONE} --add-port=9443/tcp
20+
#Open ${WEBHOOK_PORT}
21+
sudo firewall-cmd --zone=${FIREWALL_ZONE} --add-port=${WEBHOOK_PORT}/tcp
2122
sudo firewall-cmd --runtime-to-permanent
2223

2324
# Generate the certs and the ca bundle
@@ -48,7 +49,7 @@ webhooks:
4849
- v1
4950
clientConfig:
5051
caBundle: ${CA_BUNDLE}
51-
url: https://${CRC_IP}:9443/validate-mariadb-openstack-org-v1beta1-mariadb
52+
url: https://${CRC_IP}:${WEBHOOK_PORT}/validate-mariadb-openstack-org-v1beta1-mariadb
5253
failurePolicy: Fail
5354
matchPolicy: Equivalent
5455
name: vmariadb.kb.io
@@ -70,7 +71,7 @@ webhooks:
7071
- v1
7172
clientConfig:
7273
caBundle: ${CA_BUNDLE}
73-
url: https://${CRC_IP}:9443/validate-mariadb-openstack-org-v1beta1-galera
74+
url: https://${CRC_IP}:${WEBHOOK_PORT}/validate-mariadb-openstack-org-v1beta1-galera
7475
failurePolicy: Fail
7576
matchPolicy: Equivalent
7677
name: vgalera.kb.io
@@ -98,7 +99,7 @@ webhooks:
9899
- v1
99100
clientConfig:
100101
caBundle: ${CA_BUNDLE}
101-
url: https://${CRC_IP}:9443/mutate-mariadb-openstack-org-v1beta1-mariadb
102+
url: https://${CRC_IP}:${WEBHOOK_PORT}/mutate-mariadb-openstack-org-v1beta1-mariadb
102103
failurePolicy: Fail
103104
matchPolicy: Equivalent
104105
name: mmariadb.kb.io
@@ -120,7 +121,7 @@ webhooks:
120121
- v1
121122
clientConfig:
122123
caBundle: ${CA_BUNDLE}
123-
url: https://${CRC_IP}:9443/mutate-mariadb-openstack-org-v1beta1-galera
124+
url: https://${CRC_IP}:${WEBHOOK_PORT}/mutate-mariadb-openstack-org-v1beta1-galera
124125
failurePolicy: Fail
125126
matchPolicy: Equivalent
126127
name: mgalera.kb.io
@@ -176,4 +177,4 @@ else
176177
oc scale --replicas=0 -n openstack-operators deploy/mariadb-operator-controller-manager
177178
fi
178179

179-
go run ./main.go -metrics-bind-address ":${METRICS_PORT}" -health-probe-bind-address ":${HEALTH_PORT}" -pprof-bind-address ":${PPROF_PORT}"
180+
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
@@ -62,11 +62,13 @@ func main() {
6262
var enableLeaderElection bool
6363
var probeAddr string
6464
var pprofBindAddress string
65+
var webhookPort int
6566
var enableHTTP2 bool
6667
flag.BoolVar(&enableHTTP2, "enable-http2", enableHTTP2, "If HTTP/2 should be enabled for the metrics and webhook servers.")
6768
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
6869
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
6970
flag.StringVar(&pprofBindAddress, "pprof-bind-address", "", "The address the pprof endpoint binds to. Set to empty to disable pprof.")
71+
flag.IntVar(&webhookPort, "webhook-bind-address", 9443, "The port the webhook server binds to.")
7072
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
7173
"Enable leader election for controller manager. "+
7274
"Enabling this will ensure there is only one active controller manager.")
@@ -96,7 +98,7 @@ func main() {
9698
PprofBindAddress: pprofBindAddress,
9799
WebhookServer: webhook.NewServer(
98100
webhook.Options{
99-
Port: 9443,
101+
Port: webhookPort,
100102
TLSOpts: []func(config *tls.Config){disableHTTP2},
101103
}),
102104
}

0 commit comments

Comments
 (0)