Skip to content

Commit ac268d7

Browse files
feat: improve UX and maintainability by auto-uncommenting webhook blocks
This change enhances the user experience by automatically uncommenting webhook-related code blocks during scaffolding. It also improves maintainability by eliminating the need to manually uncomment code when running end-to-end tests for examples and mocks.
1 parent e812c0c commit ac268d7

File tree

18 files changed

+756
-784
lines changed

18 files changed

+756
-784
lines changed

.github/workflows/test-e2e-samples.yml

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ jobs:
3939

4040
- name: Prepare project-v4
4141
run: |
42+
# Enable [METRICS-WITH-CERTS] by uncommenting the lines in kustomization.yaml
4243
KUSTOMIZATION_FILE_PATH="testdata/project-v4/config/default/kustomization.yaml"
43-
sed -i '25s/^#//' $KUSTOMIZATION_FILE_PATH
4444
sed -i '47,49s/^#//' $KUSTOMIZATION_FILE_PATH
45-
# Uncomment all cert-manager injections
46-
sed -i '59,234s/^#//' $KUSTOMIZATION_FILE_PATH
47-
sed -i '236,251s/^#//' $KUSTOMIZATION_FILE_PATH
45+
sed -i '60,118s/^#//' $KUSTOMIZATION_FILE_PATH
4846
cd testdata/project-v4/
4947
go mod tidy
5048
@@ -81,17 +79,6 @@ jobs:
8179

8280
- name: Prepare project-v4-with-plugins
8381
run: |
84-
KUSTOMIZATION_FILE_PATH="testdata/project-v4-with-plugins/config/default/kustomization.yaml"
85-
sed -i '25s/^#//' $KUSTOMIZATION_FILE_PATH
86-
# Uncomment only ValidatingWebhookConfiguration
87-
# from cert-manager replaces; we are leaving defaulting uncommented
88-
# since this sample has no defaulting webhooks
89-
sed -i '59,77s/^#//' $KUSTOMIZATION_FILE_PATH
90-
sed -i '90,107s/^#//' $KUSTOMIZATION_FILE_PATH
91-
sed -i '120,186s/^#//' $KUSTOMIZATION_FILE_PATH
92-
# Uncomment only --conversion webhooks CA injection
93-
sed -i '219,234s/^#//' $KUSTOMIZATION_FILE_PATH
94-
sed -i '236,251s/^#//' $KUSTOMIZATION_FILE_PATH
9582
cd testdata/project-v4-with-plugins/
9683
go mod tidy
9784
@@ -128,13 +115,6 @@ jobs:
128115

129116
- name: Prepare project-v4-multigroup
130117
run: |
131-
KUSTOMIZATION_FILE_PATH="testdata/project-v4-multigroup/config/default/kustomization.yaml"
132-
sed -i '25s/^#//' $KUSTOMIZATION_FILE_PATH
133-
# Uncomment all cert-manager injections for webhooks only
134-
sed -i '59,77s/^#//' $KUSTOMIZATION_FILE_PATH
135-
sed -i '90,107s/^#//' $KUSTOMIZATION_FILE_PATH
136-
sed -i '120,234s/^#//' $KUSTOMIZATION_FILE_PATH
137-
sed -i '236,251s/^#//' $KUSTOMIZATION_FILE_PATH
138118
cd testdata/project-v4-multigroup
139119
go mod tidy
140120

docs/book/src/cronjob-tutorial/testdata/project/config/default/kustomization.yaml

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ replacements:
116116
delimiter: '.'
117117
index: 1
118118
create: true
119-
119+
#
120120
- source: # Uncomment the following block if you have any webhook
121121
kind: Service
122122
version: v1
@@ -135,25 +135,26 @@ replacements:
135135
delimiter: '.'
136136
index: 0
137137
create: true
138-
- source:
139-
kind: Service
140-
version: v1
141-
name: webhook-service
142-
fieldPath: .metadata.namespace # Namespace of the service
143-
targets:
144-
- select:
145-
kind: Certificate
146-
group: cert-manager.io
147-
version: v1
148-
name: serving-cert
149-
fieldPaths:
150-
- .spec.dnsNames.0
151-
- .spec.dnsNames.1
152-
options:
153-
delimiter: '.'
154-
index: 1
155-
create: true
156138

139+
# - source:
140+
# kind: Service
141+
# version: v1
142+
# name: webhook-service
143+
# fieldPath: .metadata.namespace # Namespace of the service
144+
# targets:
145+
# - select:
146+
# kind: Certificate
147+
# group: cert-manager.io
148+
# version: v1
149+
# name: serving-cert
150+
# fieldPaths:
151+
# - .spec.dnsNames.0
152+
# - .spec.dnsNames.1
153+
# options:
154+
# delimiter: '.'
155+
# index: 1
156+
# create: true
157+
#
157158
- source: # Uncomment the following block if you have a ValidatingWebhook (--programmatic-validation)
158159
kind: Certificate
159160
group: cert-manager.io
@@ -169,22 +170,23 @@ replacements:
169170
delimiter: '/'
170171
index: 0
171172
create: true
172-
- source:
173-
kind: Certificate
174-
group: cert-manager.io
175-
version: v1
176-
name: serving-cert
177-
fieldPath: .metadata.name
178-
targets:
179-
- select:
180-
kind: ValidatingWebhookConfiguration
181-
fieldPaths:
182-
- .metadata.annotations.[cert-manager.io/inject-ca-from]
183-
options:
184-
delimiter: '/'
185-
index: 1
186-
create: true
187173

174+
# - source:
175+
# kind: Certificate
176+
# group: cert-manager.io
177+
# version: v1
178+
# name: serving-cert
179+
# fieldPath: .metadata.name
180+
# targets:
181+
# - select:
182+
# kind: ValidatingWebhookConfiguration
183+
# fieldPaths:
184+
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
185+
# options:
186+
# delimiter: '/'
187+
# index: 1
188+
# create: true
189+
#
188190
- source: # Uncomment the following block if you have a DefaultingWebhook (--defaulting )
189191
kind: Certificate
190192
group: cert-manager.io
@@ -200,21 +202,22 @@ replacements:
200202
delimiter: '/'
201203
index: 0
202204
create: true
203-
- source:
204-
kind: Certificate
205-
group: cert-manager.io
206-
version: v1
207-
name: serving-cert
208-
fieldPath: .metadata.name
209-
targets:
210-
- select:
211-
kind: MutatingWebhookConfiguration
212-
fieldPaths:
213-
- .metadata.annotations.[cert-manager.io/inject-ca-from]
214-
options:
215-
delimiter: '/'
216-
index: 1
217-
create: true
205+
206+
# - source:
207+
# kind: Certificate
208+
# group: cert-manager.io
209+
# version: v1
210+
# name: serving-cert
211+
# fieldPath: .metadata.name
212+
# targets:
213+
# - select:
214+
# kind: MutatingWebhookConfiguration
215+
# fieldPaths:
216+
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
217+
# options:
218+
# delimiter: '/'
219+
# index: 1
220+
# create: true
218221
#
219222
# - source: # Uncomment the following block if you have a ConversionWebhook (--conversion)
220223
# kind: Certificate

docs/book/src/cronjob-tutorial/testdata/project/dist/install.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4253,8 +4253,8 @@ metadata:
42534253
namespace: project-system
42544254
spec:
42554255
dnsNames:
4256-
- project-webhook-service.project-system.svc
4257-
- project-webhook-service.project-system.svc.cluster.local
4256+
- project-webhook-service.SERVICE_NAMESPACE.svc
4257+
- project-webhook-service.SERVICE_NAMESPACE.svc.cluster.local
42584258
issuerRef:
42594259
kind: Issuer
42604260
name: project-selfsigned-issuer
@@ -4309,7 +4309,7 @@ apiVersion: admissionregistration.k8s.io/v1
43094309
kind: MutatingWebhookConfiguration
43104310
metadata:
43114311
annotations:
4312-
cert-manager.io/inject-ca-from: project-system/project-serving-cert
4312+
cert-manager.io/inject-ca-from: project-system
43134313
name: project-mutating-webhook-configuration
43144314
webhooks:
43154315
- admissionReviewVersions:
@@ -4337,7 +4337,7 @@ apiVersion: admissionregistration.k8s.io/v1
43374337
kind: ValidatingWebhookConfiguration
43384338
metadata:
43394339
annotations:
4340-
cert-manager.io/inject-ca-from: project-system/project-serving-cert
4340+
cert-manager.io/inject-ca-from: project-system
43414341
name: project-validating-webhook-configuration
43424342
webhooks:
43434343
- admissionReviewVersions:

docs/book/src/multiversion-tutorial/testdata/project/config/default/kustomization.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ replacements:
116116
delimiter: '.'
117117
index: 1
118118
create: true
119-
119+
#
120120
- source: # Uncomment the following block if you have any webhook
121121
kind: Service
122122
version: v1
@@ -135,6 +135,7 @@ replacements:
135135
delimiter: '.'
136136
index: 0
137137
create: true
138+
138139
- source:
139140
kind: Service
140141
version: v1
@@ -154,6 +155,7 @@ replacements:
154155
index: 1
155156
create: true
156157

158+
157159
- source: # Uncomment the following block if you have a ValidatingWebhook (--programmatic-validation)
158160
kind: Certificate
159161
group: cert-manager.io
@@ -169,6 +171,7 @@ replacements:
169171
delimiter: '/'
170172
index: 0
171173
create: true
174+
172175
- source:
173176
kind: Certificate
174177
group: cert-manager.io
@@ -185,6 +188,7 @@ replacements:
185188
index: 1
186189
create: true
187190

191+
188192
- source: # Uncomment the following block if you have a DefaultingWebhook (--defaulting )
189193
kind: Certificate
190194
group: cert-manager.io
@@ -200,6 +204,7 @@ replacements:
200204
delimiter: '/'
201205
index: 0
202206
create: true
207+
203208
- source:
204209
kind: Certificate
205210
group: cert-manager.io
@@ -216,6 +221,7 @@ replacements:
216221
index: 1
217222
create: true
218223

224+
219225
- source: # Uncomment the following block if you have a ConversionWebhook (--conversion)
220226
kind: Certificate
221227
group: cert-manager.io
@@ -250,3 +256,4 @@ replacements:
250256
index: 1
251257
create: true
252258
# +kubebuilder:scaffold:crdkustomizecainjectionname
259+

hack/docs/internal/cronjob-tutorial/generate_cronjob.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -610,11 +610,6 @@ var _ = AfterSuite(func() {
610610

611611
func (sp *Sample) updateKustomization() {
612612
var err error
613-
err = pluginutil.UncommentCode(
614-
filepath.Join(sp.ctx.Dir, "config/default/kustomization.yaml"),
615-
`#- ../certmanager`, `#`)
616-
hackutils.CheckError("fixing default/kustomization", err)
617-
618613
err = pluginutil.UncommentCode(
619614
filepath.Join(sp.ctx.Dir, "config/default/kustomization.yaml"),
620615
`#- ../prometheus`, `#`)
@@ -637,7 +632,7 @@ func (sp *Sample) updateKustomization() {
637632

638633
err = pluginutil.UncommentCode(
639634
filepath.Join(sp.ctx.Dir, "config/default/kustomization.yaml"),
640-
certManagerForMetricsAndWebhooks, `#`)
635+
certManagerForMetrics, `#`)
641636
hackutils.CheckError("fixing default/kustomization", err)
642637
}
643638

0 commit comments

Comments
 (0)