Skip to content

Commit 96da8a6

Browse files
miyunariclaude
andauthored
fix: make OLM webhook CSV patch version-independent and non-duplicative (#210)
Follow-up to #209. - Target the ClusterServiceVersion by kind only, both in the post-generation webhook patch and in the manifests patch component. The CSV name embeds VERSION, so a hard-coded `model-validation-operator.v1.0.0` target would silently stop matching after a version bump. - Replace the full hand-copied webhookdefinitions override with a minimal JSON6902 patch. Operator SDK already derives rules, selectors, failure policy and deploymentName from config/webhook; only containerPort, targetPort and serviceName need correcting. A `test` op guards against patching the wrong entry if webhooks are added or reordered. - Drop the webhook patch from the manifests component, since `operator-sdk generate bundle` regenerates webhookdefinitions anyway. `make bundle` produces webhook definitions identical to the committed bundles, and `make bundle-kubernetes VERSION=1.0.1` now yields a correctly patched model-validation-operator.v1.0.1 CSV. Signed-off-by: Nina Bongartz <pninak@web.de> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 555bb59 commit 96da8a6

3 files changed

Lines changed: 21 additions & 39 deletions

File tree

‎Makefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ generate-bundle: manifests kustomize operator-sdk ## Generate and validate one O
358358
cd config/overlays/$(BUNDLE_IMAGE_OVERLAY) && $(KUSTOMIZE) edit set image controller=$(IMG)
359359
mkdir -p $(BUNDLE_DIR)
360360
cd $(BUNDLE_DIR) && cp ../../PROJECT . && $(KUSTOMIZE) build ../../config/overlays/$(BUNDLE_OVERLAY) | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS) --output-dir . --kustomize-dir ../../config/manifests && rm PROJECT
361-
# Reapply webhook definitions after Operator SDK regenerates them from webhook manifests.
361+
# Correct the port and service wiring of the webhook definitions Operator SDK derived from config/webhook.
362+
# The CSV is targeted by kind only so the patch keeps applying when VERSION changes.
362363
@set -eu; \
363364
patch_dir="$(BUNDLE_DIR)/.webhook-patch"; \
364365
csv="$(BUNDLE_DIR)/manifests/model-validation-operator.clusterserviceversion.yaml"; \
@@ -376,7 +377,6 @@ generate-bundle: manifests kustomize operator-sdk ## Generate and validate one O
376377
' group: operators.coreos.com' \
377378
' version: v1alpha1' \
378379
' kind: ClusterServiceVersion' \
379-
' name: model-validation-operator.v1.0.0' \
380380
> "$$patch_dir/kustomization.yaml"; \
381381
$(KUSTOMIZE) build "$$patch_dir" > "$$csv.tmp"; \
382382
mv "$$csv.tmp" "$$csv"; \

‎config/manifests/patches/kustomization.yaml‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,3 @@ patches:
77
group: operators.coreos.com
88
version: v1alpha1
99
kind: ClusterServiceVersion
10-
name: model-validation-operator.v1.0.0
11-
- path: webhook_definitions.yaml
12-
target:
13-
group: operators.coreos.com
14-
version: v1alpha1
15-
kind: ClusterServiceVersion
16-
name: model-validation-operator.v1.0.0
Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
1-
apiVersion: operators.coreos.com/v1alpha1
2-
kind: ClusterServiceVersion
3-
metadata:
4-
name: model-validation-operator.v1.0.0
5-
spec:
6-
webhookdefinitions:
7-
- admissionReviewVersions:
8-
- v1
9-
containerPort: 9443
10-
deploymentName: model-validation-controller-manager
11-
failurePolicy: Fail
12-
generateName: pods.validation.ml.sigstore.dev
13-
objectSelector:
14-
matchExpressions:
15-
- key: validation.ml.sigstore.dev/ml
16-
operator: Exists
17-
rules:
18-
- apiGroups:
19-
- ""
20-
apiVersions:
21-
- v1
22-
operations:
23-
- CREATE
24-
- UPDATE
25-
resources:
26-
- pods
27-
serviceName: model-validation-webhook
28-
sideEffects: None
29-
type: MutatingAdmissionWebhook
30-
webhookPath: /mutate-v1-pod
1+
# JSON6902 patch applied to the generated CSV by `make generate-bundle`, after
2+
# `operator-sdk generate bundle` derives spec.webhookdefinitions from the
3+
# MutatingWebhookConfiguration in config/webhook. Operator SDK already gets the
4+
# rules, selectors, failure policy and deployment name right; only the port
5+
# and service wiring need correcting, so nothing else is duplicated here.
6+
#
7+
# The `test` op makes generation fail loudly if a webhook is added or
8+
# reordered, instead of silently patching the wrong entry.
9+
- op: test
10+
path: /spec/webhookdefinitions/0/generateName
11+
value: pods.validation.ml.sigstore.dev
12+
- op: replace
13+
path: /spec/webhookdefinitions/0/containerPort
14+
value: 9443
15+
- op: remove
16+
path: /spec/webhookdefinitions/0/targetPort
17+
- op: add
18+
path: /spec/webhookdefinitions/0/serviceName
19+
value: model-validation-webhook

0 commit comments

Comments
 (0)