Skip to content

Commit 93574c5

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. dd
1 parent cd97195 commit 93574c5

File tree

16 files changed

+768
-747
lines changed

16 files changed

+768
-747
lines changed

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

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,9 @@ 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
4845
cd testdata/project-v4/
4946
go mod tidy
5047
@@ -81,17 +78,6 @@ jobs:
8178

8279
- name: Prepare project-v4-with-plugins
8380
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
9581
cd testdata/project-v4-with-plugins/
9682
go mod tidy
9783
@@ -128,13 +114,6 @@ jobs:
128114

129115
- name: Prepare project-v4-multigroup
130116
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
138117
cd testdata/project-v4-multigroup
139118
go mod tidy
140119

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

Lines changed: 3 additions & 3 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
@@ -153,7 +153,7 @@ replacements:
153153
delimiter: '.'
154154
index: 1
155155
create: true
156-
156+
#
157157
- source: # Uncomment the following block if you have a ValidatingWebhook (--programmatic-validation)
158158
kind: Certificate
159159
group: cert-manager.io
@@ -184,7 +184,7 @@ replacements:
184184
delimiter: '/'
185185
index: 1
186186
create: true
187-
187+
#
188188
- source: # Uncomment the following block if you have a DefaultingWebhook (--defaulting )
189189
kind: Certificate
190190
group: cert-manager.io

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

Lines changed: 4 additions & 4 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
@@ -153,7 +153,7 @@ replacements:
153153
delimiter: '.'
154154
index: 1
155155
create: true
156-
156+
#
157157
- source: # Uncomment the following block if you have a ValidatingWebhook (--programmatic-validation)
158158
kind: Certificate
159159
group: cert-manager.io
@@ -184,7 +184,7 @@ replacements:
184184
delimiter: '/'
185185
index: 1
186186
create: true
187-
187+
#
188188
- source: # Uncomment the following block if you have a DefaultingWebhook (--defaulting )
189189
kind: Certificate
190190
group: cert-manager.io
@@ -215,7 +215,7 @@ replacements:
215215
delimiter: '/'
216216
index: 1
217217
create: true
218-
218+
#
219219
- source: # Uncomment the following block if you have a ConversionWebhook (--conversion)
220220
kind: Certificate
221221
group: cert-manager.io

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

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

Lines changed: 1 addition & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ const cronjobSample = `
3333
- date; echo Hello from the Kubernetes cluster
3434
restartPolicy: OnFailure`
3535

36-
const certManagerForMetricsAndWebhooks = `#replacements:
37-
# - source: # Uncomment the following block to enable certificates for metrics
36+
const certManagerForMetrics = `# - source: # Uncomment the following block to enable certificates for metrics
3837
# kind: Service
3938
# version: v1
4039
# name: controller-manager-metrics-service
@@ -92,103 +91,4 @@ const certManagerForMetricsAndWebhooks = `#replacements:
9291
# options:
9392
# delimiter: '.'
9493
# index: 1
95-
# create: true
96-
#
97-
# - source: # Uncomment the following block if you have any webhook
98-
# kind: Service
99-
# version: v1
100-
# name: webhook-service
101-
# fieldPath: .metadata.name # Name of the service
102-
# targets:
103-
# - select:
104-
# kind: Certificate
105-
# group: cert-manager.io
106-
# version: v1
107-
# name: serving-cert
108-
# fieldPaths:
109-
# - .spec.dnsNames.0
110-
# - .spec.dnsNames.1
111-
# options:
112-
# delimiter: '.'
113-
# index: 0
114-
# create: true
115-
# - source:
116-
# kind: Service
117-
# version: v1
118-
# name: webhook-service
119-
# fieldPath: .metadata.namespace # Namespace of the service
120-
# targets:
121-
# - select:
122-
# kind: Certificate
123-
# group: cert-manager.io
124-
# version: v1
125-
# name: serving-cert
126-
# fieldPaths:
127-
# - .spec.dnsNames.0
128-
# - .spec.dnsNames.1
129-
# options:
130-
# delimiter: '.'
131-
# index: 1
132-
# create: true
133-
#
134-
# - source: # Uncomment the following block if you have a ValidatingWebhook (--programmatic-validation)
135-
# kind: Certificate
136-
# group: cert-manager.io
137-
# version: v1
138-
# name: serving-cert # This name should match the one in certificate.yaml
139-
# fieldPath: .metadata.namespace # Namespace of the certificate CR
140-
# targets:
141-
# - select:
142-
# kind: ValidatingWebhookConfiguration
143-
# fieldPaths:
144-
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
145-
# options:
146-
# delimiter: '/'
147-
# index: 0
148-
# create: true
149-
# - source:
150-
# kind: Certificate
151-
# group: cert-manager.io
152-
# version: v1
153-
# name: serving-cert
154-
# fieldPath: .metadata.name
155-
# targets:
156-
# - select:
157-
# kind: ValidatingWebhookConfiguration
158-
# fieldPaths:
159-
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
160-
# options:
161-
# delimiter: '/'
162-
# index: 1
163-
# create: true
164-
#
165-
# - source: # Uncomment the following block if you have a DefaultingWebhook (--defaulting )
166-
# kind: Certificate
167-
# group: cert-manager.io
168-
# version: v1
169-
# name: serving-cert
170-
# fieldPath: .metadata.namespace # Namespace of the certificate CR
171-
# targets:
172-
# - select:
173-
# kind: MutatingWebhookConfiguration
174-
# fieldPaths:
175-
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
176-
# options:
177-
# delimiter: '/'
178-
# index: 0
179-
# create: true
180-
# - source:
181-
# kind: Certificate
182-
# group: cert-manager.io
183-
# version: v1
184-
# name: serving-cert
185-
# fieldPath: .metadata.name
186-
# targets:
187-
# - select:
188-
# kind: MutatingWebhookConfiguration
189-
# fieldPaths:
190-
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
191-
# options:
192-
# delimiter: '/'
193-
# index: 1
19494
# create: true`

hack/docs/internal/multiversion-tutorial/generate_multiversion.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ func (sp *Sample) UpdateTutorial() {
103103
sp.updateConversionFiles()
104104
sp.updateSampleV2()
105105
sp.updateMain()
106-
sp.updateDefaultKustomize()
107106
}
108107

109108
func (sp *Sample) updateCronjobV1DueForce() {
@@ -281,20 +280,6 @@ interfaces, a conversion webhook will be registered.
281280
hackutils.CheckError("fix cronjob v1 tests after each", err)
282281
}
283282

284-
func (sp *Sample) updateDefaultKustomize() {
285-
// Enable CA for Conversion Webhook
286-
err := pluginutil.UncommentCode(
287-
filepath.Join(sp.ctx.Dir, "config/default/kustomization.yaml"),
288-
caInjectionNamespace, `#`)
289-
hackutils.CheckError("fixing default/kustomization", err)
290-
291-
// Enable CA for Conversion Webhook
292-
err = pluginutil.UncommentCode(
293-
filepath.Join(sp.ctx.Dir, "config/default/kustomization.yaml"),
294-
caInjectionCert, `#`)
295-
hackutils.CheckError("fixing default/kustomization", err)
296-
}
297-
298283
func (sp *Sample) updateSampleV2() {
299284
path := filepath.Join(sp.ctx.Dir, "config/samples/batch_v2_cronjob.yaml")
300285
oldText := `# TODO(user): Add fields here`

hack/docs/internal/multiversion-tutorial/kustomize.go

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)