Skip to content

Commit f784e54

Browse files
committed
Enable conversion webhook plumbing for openstack-operator CRDs
Add conversion webhook and cert-manager CA-injection kustomize patches for all openstack-operator CRDs (OpenStackControlPlane, Dataplane*, OpenStackVersion, OpenStackClient, OpenStackBackupConfig, OpenStackAssistant). The infrastructure stays dormant while each CRD has a single served version; it activates automatically once a second version is added. config/crd/patches/: - webhook_in_<crd>.yaml: sets spec.conversion.strategy: Webhook on each CRD, pointing clientConfig at openstack-operator-webhook-service. Namespace is {{ .OperatorNamespace }}, resolved at deploy time. - cainjection_in_<crd>.yaml: stamps cert-manager.io/inject-ca-from with the openstack-operator serving cert so caBundle is populated. config/crd/kustomization.yaml: enable all webhook + CA-injection patches and kustomizeconfig.yaml (needed for the CA-injection substitution to work correctly across kustomize bases). bindata/crds/crds.yaml: rebuilt from config/crd with the new patches. openstack_controller.go applyCRDs: pass OperatorNamespace in the render data so the {{ .OperatorNamespace }} template variable in crds.yaml is resolved to the actual operator namespace at runtime. Jira: OSPRH-30210 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Signed-off-by: Martin Schuppert <mschuppert@redhat.com> Add GitHub workflow to check CRD webhook coverage Validates that any new CRD in config/crd/bases/ has matching webhook and CA-injection patches referenced in kustomization.yaml. Runs on PRs that touch CRD files or patches.
1 parent 1602b76 commit f784e54

20 files changed

Lines changed: 393 additions & 6 deletions
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Check CRD Webhook Coverage
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'config/crd/bases/**'
7+
- 'config/crd/patches/**'
8+
- 'config/crd/kustomization.yaml'
9+
10+
jobs:
11+
check-webhook-patches:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Check all CRDs have conversion webhook patches
17+
run: |
18+
set -e
19+
20+
echo "Checking that all openstack-operator CRDs have webhook + CA-injection patches..."
21+
22+
MISSING_PATCHES=0
23+
24+
# Check each CRD in config/crd/bases/
25+
for crd_file in config/crd/bases/*.yaml; do
26+
# Skip if not a file or if it's the commented-out openstacks.yaml
27+
[[ ! -f "$crd_file" ]] && continue
28+
basename=$(basename "$crd_file")
29+
[[ "$basename" == "operator.openstack.org_openstacks.yaml" ]] && continue
30+
31+
# Extract CRD name (e.g., "core.openstack.org_openstackcontrolplanes")
32+
crd_name="${basename%.yaml}"
33+
34+
# Check for webhook patch
35+
webhook_patch="config/crd/patches/webhook_in_${crd_name}.yaml"
36+
if [[ ! -f "$webhook_patch" ]]; then
37+
echo "ERROR: Missing webhook patch for $basename"
38+
echo " Expected: $webhook_patch"
39+
MISSING_PATCHES=1
40+
fi
41+
42+
# Check for CA injection patch
43+
cainjection_patch="config/crd/patches/cainjection_in_${crd_name}.yaml"
44+
if [[ ! -f "$cainjection_patch" ]]; then
45+
echo "ERROR: Missing CA injection patch for $basename"
46+
echo " Expected: $cainjection_patch"
47+
MISSING_PATCHES=1
48+
fi
49+
50+
# Check that patches are referenced in kustomization.yaml
51+
if ! grep -q "path: patches/webhook_in_${crd_name}.yaml" config/crd/kustomization.yaml; then
52+
echo "ERROR: Webhook patch for $basename not referenced in kustomization.yaml"
53+
MISSING_PATCHES=1
54+
fi
55+
56+
if ! grep -q "path: patches/cainjection_in_${crd_name}.yaml" config/crd/kustomization.yaml; then
57+
echo "ERROR: CA injection patch for $basename not referenced in kustomization.yaml"
58+
MISSING_PATCHES=1
59+
fi
60+
done
61+
62+
if [[ $MISSING_PATCHES -eq 1 ]]; then
63+
echo ""
64+
echo "One or more CRDs are missing conversion webhook patches."
65+
echo "For each CRD in config/crd/bases/, you must create:"
66+
echo " 1. config/crd/patches/webhook_in_<crd>.yaml"
67+
echo " 2. config/crd/patches/cainjection_in_<crd>.yaml"
68+
echo " 3. Reference both in config/crd/kustomization.yaml"
69+
echo ""
70+
echo "See existing patches for examples."
71+
exit 1
72+
fi
73+
74+
echo "✓ All CRDs have conversion webhook patches"

‎bindata/crds/crds.yaml‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@ apiVersion: apiextensions.k8s.io/v1
22
kind: CustomResourceDefinition
33
metadata:
44
annotations:
5+
cert-manager.io/inject-ca-from: '{{ .OperatorNamespace }}/openstack-operator-serving-cert'
56
controller-gen.kubebuilder.io/version: v0.18.0
67
name: openstackassistants.assistant.openstack.org
78
spec:
9+
conversion:
10+
strategy: Webhook
11+
webhook:
12+
clientConfig:
13+
service:
14+
name: openstack-operator-webhook-service
15+
namespace: '{{ .OperatorNamespace }}'
16+
path: /convert
17+
conversionReviewVersions:
18+
- v1
819
group: assistant.openstack.org
920
names:
1021
kind: OpenStackAssistant
@@ -471,13 +482,24 @@ apiVersion: apiextensions.k8s.io/v1
471482
kind: CustomResourceDefinition
472483
metadata:
473484
annotations:
485+
cert-manager.io/inject-ca-from: '{{ .OperatorNamespace }}/openstack-operator-serving-cert'
474486
controller-gen.kubebuilder.io/version: v0.18.0
475487
labels:
476488
backup.openstack.org/category: controlplane
477489
backup.openstack.org/restore: "true"
478490
backup.openstack.org/restore-order: "20"
479491
name: openstackbackupconfigs.backup.openstack.org
480492
spec:
493+
conversion:
494+
strategy: Webhook
495+
webhook:
496+
clientConfig:
497+
service:
498+
name: openstack-operator-webhook-service
499+
namespace: '{{ .OperatorNamespace }}'
500+
path: /convert
501+
conversionReviewVersions:
502+
- v1
481503
group: backup.openstack.org
482504
names:
483505
kind: OpenStackBackupConfig
@@ -740,9 +762,20 @@ apiVersion: apiextensions.k8s.io/v1
740762
kind: CustomResourceDefinition
741763
metadata:
742764
annotations:
765+
cert-manager.io/inject-ca-from: '{{ .OperatorNamespace }}/openstack-operator-serving-cert'
743766
controller-gen.kubebuilder.io/version: v0.18.0
744767
name: openstackclients.client.openstack.org
745768
spec:
769+
conversion:
770+
strategy: Webhook
771+
webhook:
772+
clientConfig:
773+
service:
774+
name: openstack-operator-webhook-service
775+
namespace: '{{ .OperatorNamespace }}'
776+
path: /convert
777+
conversionReviewVersions:
778+
- v1
746779
group: client.openstack.org
747780
names:
748781
kind: OpenStackClient
@@ -1032,13 +1065,24 @@ apiVersion: apiextensions.k8s.io/v1
10321065
kind: CustomResourceDefinition
10331066
metadata:
10341067
annotations:
1068+
cert-manager.io/inject-ca-from: '{{ .OperatorNamespace }}/openstack-operator-serving-cert'
10351069
controller-gen.kubebuilder.io/version: v0.18.0
10361070
labels:
10371071
backup.openstack.org/category: controlplane
10381072
backup.openstack.org/restore: "true"
10391073
backup.openstack.org/restore-order: "30"
10401074
name: openstackcontrolplanes.core.openstack.org
10411075
spec:
1076+
conversion:
1077+
strategy: Webhook
1078+
webhook:
1079+
clientConfig:
1080+
service:
1081+
name: openstack-operator-webhook-service
1082+
namespace: '{{ .OperatorNamespace }}'
1083+
path: /convert
1084+
conversionReviewVersions:
1085+
- v1
10421086
group: core.openstack.org
10431087
names:
10441088
kind: OpenStackControlPlane
@@ -20630,9 +20674,20 @@ apiVersion: apiextensions.k8s.io/v1
2063020674
kind: CustomResourceDefinition
2063120675
metadata:
2063220676
annotations:
20677+
cert-manager.io/inject-ca-from: '{{ .OperatorNamespace }}/openstack-operator-serving-cert'
2063320678
controller-gen.kubebuilder.io/version: v0.18.0
2063420679
name: openstackdataplanedeployments.dataplane.openstack.org
2063520680
spec:
20681+
conversion:
20682+
strategy: Webhook
20683+
webhook:
20684+
clientConfig:
20685+
service:
20686+
name: openstack-operator-webhook-service
20687+
namespace: '{{ .OperatorNamespace }}'
20688+
path: /convert
20689+
conversionReviewVersions:
20690+
- v1
2063620691
group: dataplane.openstack.org
2063720692
names:
2063820693
kind: OpenStackDataPlaneDeployment
@@ -20938,13 +20993,24 @@ apiVersion: apiextensions.k8s.io/v1
2093820993
kind: CustomResourceDefinition
2093920994
metadata:
2094020995
annotations:
20996+
cert-manager.io/inject-ca-from: '{{ .OperatorNamespace }}/openstack-operator-serving-cert'
2094120997
controller-gen.kubebuilder.io/version: v0.18.0
2094220998
labels:
2094320999
backup.openstack.org/category: dataplane
2094421000
backup.openstack.org/restore: "true"
2094521001
backup.openstack.org/restore-order: "60"
2094621002
name: openstackdataplanenodesets.dataplane.openstack.org
2094721003
spec:
21004+
conversion:
21005+
strategy: Webhook
21006+
webhook:
21007+
clientConfig:
21008+
service:
21009+
name: openstack-operator-webhook-service
21010+
namespace: '{{ .OperatorNamespace }}'
21011+
path: /convert
21012+
conversionReviewVersions:
21013+
- v1
2094821014
group: dataplane.openstack.org
2094921015
names:
2095021016
kind: OpenStackDataPlaneNodeSet
@@ -22585,13 +22651,24 @@ apiVersion: apiextensions.k8s.io/v1
2258522651
kind: CustomResourceDefinition
2258622652
metadata:
2258722653
annotations:
22654+
cert-manager.io/inject-ca-from: '{{ .OperatorNamespace }}/openstack-operator-serving-cert'
2258822655
controller-gen.kubebuilder.io/version: v0.18.0
2258922656
labels:
2259022657
backup.openstack.org/category: dataplane
2259122658
backup.openstack.org/restore: "true"
2259222659
backup.openstack.org/restore-order: "40"
2259322660
name: openstackdataplaneservices.dataplane.openstack.org
2259422661
spec:
22662+
conversion:
22663+
strategy: Webhook
22664+
webhook:
22665+
clientConfig:
22666+
service:
22667+
name: openstack-operator-webhook-service
22668+
namespace: '{{ .OperatorNamespace }}'
22669+
path: /convert
22670+
conversionReviewVersions:
22671+
- v1
2259522672
group: dataplane.openstack.org
2259622673
names:
2259722674
kind: OpenStackDataPlaneService
@@ -22897,13 +22974,24 @@ apiVersion: apiextensions.k8s.io/v1
2289722974
kind: CustomResourceDefinition
2289822975
metadata:
2289922976
annotations:
22977+
cert-manager.io/inject-ca-from: '{{ .OperatorNamespace }}/openstack-operator-serving-cert'
2290022978
controller-gen.kubebuilder.io/version: v0.18.0
2290122979
labels:
2290222980
backup.openstack.org/category: controlplane
2290322981
backup.openstack.org/restore: "true"
2290422982
backup.openstack.org/restore-order: "20"
2290522983
name: openstackversions.core.openstack.org
2290622984
spec:
22985+
conversion:
22986+
strategy: Webhook
22987+
webhook:
22988+
clientConfig:
22989+
service:
22990+
name: openstack-operator-webhook-service
22991+
namespace: '{{ .OperatorNamespace }}'
22992+
path: /convert
22993+
conversionReviewVersions:
22994+
- v1
2290722995
group: core.openstack.org
2290822996
names:
2290922997
kind: OpenStackVersion

‎config/crd/kustomization.yaml‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,27 @@ resources:
1414
# +kubebuilder:scaffold:crdkustomizeresource
1515

1616
patches:
17-
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
18-
# patches here are for enabling the conversion webhook for each CRD
17+
# [WEBHOOK] patches for enabling the conversion webhook for each CRD
18+
- path: patches/webhook_in_core.openstack.org_openstackcontrolplanes.yaml
19+
- path: patches/webhook_in_dataplane.openstack.org_openstackdataplanenodesets.yaml
20+
- path: patches/webhook_in_dataplane.openstack.org_openstackdataplaneservices.yaml
21+
- path: patches/webhook_in_dataplane.openstack.org_openstackdataplanedeployments.yaml
22+
- path: patches/webhook_in_core.openstack.org_openstackversions.yaml
23+
- path: patches/webhook_in_client.openstack.org_openstackclients.yaml
24+
- path: patches/webhook_in_backup.openstack.org_openstackbackupconfigs.yaml
25+
- path: patches/webhook_in_assistant.openstack.org_openstackassistants.yaml
1926
# +kubebuilder:scaffold:crdkustomizewebhookpatch
2027

21-
# [WEBHOOK] To enable webhook, uncomment the following section
22-
# the following config is for teaching kustomize how to do kustomization for CRDs.
23-
#configurations:
24-
#- kustomizeconfig.yaml
28+
# [CERTMANAGER] patches for enabling the CA injection for each CRD
29+
- path: patches/cainjection_in_core.openstack.org_openstackcontrolplanes.yaml
30+
- path: patches/cainjection_in_dataplane.openstack.org_openstackdataplanenodesets.yaml
31+
- path: patches/cainjection_in_dataplane.openstack.org_openstackdataplaneservices.yaml
32+
- path: patches/cainjection_in_dataplane.openstack.org_openstackdataplanedeployments.yaml
33+
- path: patches/cainjection_in_core.openstack.org_openstackversions.yaml
34+
- path: patches/cainjection_in_client.openstack.org_openstackclients.yaml
35+
- path: patches/cainjection_in_backup.openstack.org_openstackbackupconfigs.yaml
36+
- path: patches/cainjection_in_assistant.openstack.org_openstackassistants.yaml
37+
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
38+
39+
configurations:
40+
- kustomizeconfig.yaml
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Adds the cert-manager CA-injection annotation to the openstackassistants.assistant.openstack.org CRD so
2+
# the conversion webhook's clientConfig.caBundle is populated at deploy time.
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: openstackassistants.assistant.openstack.org
7+
annotations:
8+
cert-manager.io/inject-ca-from: '{{ .OperatorNamespace }}/openstack-operator-serving-cert'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Adds the cert-manager CA-injection annotation to the openstackbackupconfigs.backup.openstack.org CRD so
2+
# the conversion webhook's clientConfig.caBundle is populated at deploy time.
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: openstackbackupconfigs.backup.openstack.org
7+
annotations:
8+
cert-manager.io/inject-ca-from: '{{ .OperatorNamespace }}/openstack-operator-serving-cert'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Adds the cert-manager CA-injection annotation to the openstackclients.client.openstack.org CRD so
2+
# the conversion webhook's clientConfig.caBundle is populated at deploy time.
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: openstackclients.client.openstack.org
7+
annotations:
8+
cert-manager.io/inject-ca-from: '{{ .OperatorNamespace }}/openstack-operator-serving-cert'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Adds the cert-manager CA-injection annotation to the openstackcontrolplanes.core.openstack.org CRD so
2+
# the conversion webhook's clientConfig.caBundle is populated at deploy time.
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: openstackcontrolplanes.core.openstack.org
7+
annotations:
8+
cert-manager.io/inject-ca-from: '{{ .OperatorNamespace }}/openstack-operator-serving-cert'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Adds the cert-manager CA-injection annotation to the openstackversions.core.openstack.org CRD so
2+
# the conversion webhook's clientConfig.caBundle is populated at deploy time.
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: openstackversions.core.openstack.org
7+
annotations:
8+
cert-manager.io/inject-ca-from: '{{ .OperatorNamespace }}/openstack-operator-serving-cert'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Adds the cert-manager CA-injection annotation to the openstackdataplanedeployments.dataplane.openstack.org CRD so
2+
# the conversion webhook's clientConfig.caBundle is populated at deploy time.
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: openstackdataplanedeployments.dataplane.openstack.org
7+
annotations:
8+
cert-manager.io/inject-ca-from: '{{ .OperatorNamespace }}/openstack-operator-serving-cert'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Adds the cert-manager CA-injection annotation to the openstackdataplanenodesets.dataplane.openstack.org CRD so
2+
# the conversion webhook's clientConfig.caBundle is populated at deploy time.
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: openstackdataplanenodesets.dataplane.openstack.org
7+
annotations:
8+
cert-manager.io/inject-ca-from: '{{ .OperatorNamespace }}/openstack-operator-serving-cert'

0 commit comments

Comments
 (0)