Skip to content

Commit fc6011b

Browse files
Make local webhook port configurable
Will be helpful when running multiple operators locally
1 parent 6137a31 commit fc6011b

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ SKIP_CERT ?=false
485485
run-with-webhook: export METRICS_PORT?=33080
486486
run-with-webhook: export HEALTH_PORT?=33081
487487
run-with-webhook: export PPROF_PORT?=8082
488+
run-with-webhook: export WEBHOOK_PORT?=9443
488489
run-with-webhook: export RELATED_IMAGE_WATCHER_API_IMAGE_URL_DEFAULT=${WATCHER_API_CI_IMAGE}
489490
run-with-webhook: export RELATED_IMAGE_WATCHER_DECISION_ENGINE_IMAGE_URL_DEFAULT=${WATCHER_DECISION_ENGINE_CI_IMAGE}
490491
run-with-webhook: export RELATED_IMAGE_WATCHER_APPLIER_IMAGE_URL_DEFAULT=${WATCHER_APPLIER_CI_IMAGE}

hack/run_with_local_webhook.sh

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ 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
SKIP_FIREWALL=${SKIP_FIREWALL:-false}
1920

2021
if [ "$SKIP_FIREWALL" = false ] ; then
21-
#Open 9443
22-
sudo firewall-cmd --zone=${FIREWALL_ZONE} --add-port=9443/tcp
22+
#Open ${WEBHOOK_PORT}
23+
sudo firewall-cmd --zone=${FIREWALL_ZONE} --add-port=${WEBHOOK_PORT}/tcp
2324
sudo firewall-cmd --runtime-to-permanent
2425
fi
2526

@@ -51,7 +52,7 @@ webhooks:
5152
- v1
5253
clientConfig:
5354
caBundle: ${CA_BUNDLE}
54-
url: https://${CRC_IP}:9443/validate-watcher-openstack-org-v1beta1-watcher
55+
url: https://${CRC_IP}:${WEBHOOK_PORT}/validate-watcher-openstack-org-v1beta1-watcher
5556
failurePolicy: Fail
5657
matchPolicy: Equivalent
5758
name: vwatcher.kb.io
@@ -79,7 +80,7 @@ webhooks:
7980
- v1
8081
clientConfig:
8182
caBundle: ${CA_BUNDLE}
82-
url: https://${CRC_IP}:9443/mutate-watcher-openstack-org-v1beta1-watcher
83+
url: https://${CRC_IP}:${WEBHOOK_PORT}/mutate-watcher-openstack-org-v1beta1-watcher
8384
failurePolicy: Fail
8485
matchPolicy: Equivalent
8586
name: mwatcher.kb.io
@@ -107,7 +108,7 @@ webhooks:
107108
- v1
108109
clientConfig:
109110
caBundle: ${CA_BUNDLE}
110-
url: https://${CRC_IP}:9443/validate-watcher-openstack-org-v1beta1-watcherapi
111+
url: https://${CRC_IP}:${WEBHOOK_PORT}/validate-watcher-openstack-org-v1beta1-watcherapi
111112
failurePolicy: Fail
112113
matchPolicy: Equivalent
113114
name: vwatcherapi.kb.io
@@ -135,7 +136,7 @@ webhooks:
135136
- v1
136137
clientConfig:
137138
caBundle: ${CA_BUNDLE}
138-
url: https://${CRC_IP}:9443/mutate-watcher-openstack-org-v1beta1-watcherapi
139+
url: https://${CRC_IP}:${WEBHOOK_PORT}/mutate-watcher-openstack-org-v1beta1-watcherapi
139140
failurePolicy: Fail
140141
matchPolicy: Equivalent
141142
name: mwatcherapi.kb.io
@@ -163,7 +164,7 @@ webhooks:
163164
- v1
164165
clientConfig:
165166
caBundle: ${CA_BUNDLE}
166-
url: https://${CRC_IP}:9443/validate-watcher-openstack-org-v1beta1-watcherdecisionengine
167+
url: https://${CRC_IP}:${WEBHOOK_PORT}/validate-watcher-openstack-org-v1beta1-watcherdecisionengine
167168
failurePolicy: Fail
168169
matchPolicy: Equivalent
169170
name: vwatcherdecisionengine.kb.io
@@ -191,7 +192,7 @@ webhooks:
191192
- v1
192193
clientConfig:
193194
caBundle: ${CA_BUNDLE}
194-
url: https://${CRC_IP}:9443/mutate-watcher-openstack-org-v1beta1-watcherdecisionengine
195+
url: https://${CRC_IP}:${WEBHOOK_PORT}/mutate-watcher-openstack-org-v1beta1-watcherdecisionengine
195196
failurePolicy: Fail
196197
matchPolicy: Equivalent
197198
name: mwatcherdecisionengine.kb.io
@@ -219,7 +220,7 @@ webhooks:
219220
- v1
220221
clientConfig:
221222
caBundle: ${CA_BUNDLE}
222-
url: https://${CRC_IP}:9443/validate-watcher-openstack-org-v1beta1-watcherapplier
223+
url: https://${CRC_IP}:${WEBHOOK_PORT}/validate-watcher-openstack-org-v1beta1-watcherapplier
223224
failurePolicy: Fail
224225
matchPolicy: Equivalent
225226
name: vwatcherapplier.kb.io
@@ -247,7 +248,7 @@ webhooks:
247248
- v1
248249
clientConfig:
249250
caBundle: ${CA_BUNDLE}
250-
url: https://${CRC_IP}:9443/mutate-watcher-openstack-org-v1beta1-watcherapplier
251+
url: https://${CRC_IP}:${WEBHOOK_PORT}/mutate-watcher-openstack-org-v1beta1-watcherapplier
251252
failurePolicy: Fail
252253
matchPolicy: Equivalent
253254
name: mwatcherapplier.kb.io
@@ -292,4 +293,4 @@ if [ -n "${CSV_NAME}" ]; then
292293
oc patch "${CSV_NAME}" -n openstack-operators --type=json -p="[{'op': 'replace', 'path': '/spec/webhookdefinitions', 'value': []}]"
293294
fi
294295

295-
go run ./main.go -metrics-bind-address ":${METRICS_PORT}" -health-probe-bind-address ":${HEALTH_PORT}" -pprof-bind-address ":${PPROF_PORT}"
296+
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ func main() {
7373
var enableLeaderElection bool
7474
var probeAddr string
7575
var pprofBindAddress string
76+
var webhookPort int
7677
var secureMetrics bool
7778
var enableHTTP2 bool
7879
flag.StringVar(&metricsAddr, "metrics-bind-address", ":33080", "The address the metric endpoint binds to.")
7980
flag.StringVar(&probeAddr, "health-probe-bind-address", ":33081", "The address the probe endpoint binds to.")
8081
flag.StringVar(&pprofBindAddress, "pprof-bind-address", "", "The address the pprof endpoint binds to. Set to empty to disable pprof.")
82+
flag.IntVar(&webhookPort, "webhook-bind-address", 9443, "The port the webhook server binds to.")
8183
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
8284
"Enable leader election for controller manager. "+
8385
"Enabling this will ensure there is only one active controller manager.")
@@ -110,6 +112,7 @@ func main() {
110112
}
111113

112114
webhookServer := webhook.NewServer(webhook.Options{
115+
Port: webhookPort,
113116
TLSOpts: tlsOpts,
114117
})
115118

0 commit comments

Comments
 (0)