Skip to content

Commit 6c6d6fa

Browse files
authored
Merge pull request #4407 from mateusoliveira43/fix/conversion-webhook-e2e-test
✨ (go/v4): add support to inject conversion webhook for the marker +kubebuilder:scaffold:e2e-webhooks-checks
2 parents 7c14cc9 + 9b5ad9c commit 6c6d6fa

File tree

5 files changed

+84
-0
lines changed
  • docs/book/src/multiversion-tutorial/testdata/project/test/e2e
  • pkg/plugins/golang/v4/scaffolds/internal/templates/test/e2e
  • testdata

5 files changed

+84
-0
lines changed

docs/book/src/multiversion-tutorial/testdata/project/test/e2e/e2e_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,20 @@ var _ = Describe("Manager", Ordered, func() {
272272
Eventually(verifyCAInjection).Should(Succeed())
273273
})
274274

275+
It("should have CA injection for CronJob conversion webhook", func() {
276+
By("checking CA injection for CronJob conversion webhook")
277+
verifyCAInjection := func(g Gomega) {
278+
cmd := exec.Command("kubectl", "get",
279+
"customresourcedefinitions.apiextensions.k8s.io",
280+
"cronjobs.batch.tutorial.kubebuilder.io",
281+
"-o", "go-template={{ .spec.conversion.webhook.clientConfig.caBundle }}")
282+
vwhOutput, err := utils.Run(cmd)
283+
g.Expect(err).NotTo(HaveOccurred())
284+
g.Expect(len(vwhOutput)).To(BeNumerically(">", 10))
285+
}
286+
Eventually(verifyCAInjection).Should(Succeed())
287+
})
288+
275289
// +kubebuilder:scaffold:e2e-webhooks-checks
276290

277291
// TODO: Customize the e2e test suite with scenarios specific to your project.

pkg/plugins/golang/v4/scaffolds/internal/templates/test/e2e/test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ func (f *WebhookTestUpdater) GetCodeFragments() machinery.CodeFragmentsMap {
9999
)
100100
}
101101

102+
if f.Resource.HasConversionWebhook() {
103+
conversionWebhookCode := fmt.Sprintf(
104+
conversionWebhookChecksFragment,
105+
f.Resource.Kind,
106+
f.Resource.Plural+"."+f.Resource.Group+"."+f.Resource.Domain,
107+
)
108+
codeFragments[machinery.NewMarkerFor(f.GetPath(), webhookChecksMarker)] = append(
109+
codeFragments[machinery.NewMarkerFor(f.GetPath(), webhookChecksMarker)],
110+
conversionWebhookCode,
111+
)
112+
}
113+
102114
return codeFragments
103115
}
104116

@@ -147,6 +159,22 @@ const validatingWebhookChecksFragment = `It("should have CA injection for valida
147159
148160
`
149161

162+
const conversionWebhookChecksFragment = `It("should have CA injection for %[1]s conversion webhook", func() {
163+
By("checking CA injection for %[1]s conversion webhook")
164+
verifyCAInjection := func(g Gomega) {
165+
cmd := exec.Command("kubectl", "get",
166+
"customresourcedefinitions.apiextensions.k8s.io",
167+
"%[2]s",
168+
"-o", "go-template={{ .spec.conversion.webhook.clientConfig.caBundle }}")
169+
vwhOutput, err := utils.Run(cmd)
170+
g.Expect(err).NotTo(HaveOccurred())
171+
g.Expect(len(vwhOutput)).To(BeNumerically(">", 10))
172+
}
173+
Eventually(verifyCAInjection).Should(Succeed())
174+
})
175+
176+
`
177+
150178
var TestTemplate = `{{ .Boilerplate }}
151179
152180

testdata/project-v4-multigroup/test/e2e/e2e_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,20 @@ var _ = Describe("Manager", Ordered, func() {
272272
Eventually(verifyCAInjection).Should(Succeed())
273273
})
274274

275+
It("should have CA injection for Wordpress conversion webhook", func() {
276+
By("checking CA injection for Wordpress conversion webhook")
277+
verifyCAInjection := func(g Gomega) {
278+
cmd := exec.Command("kubectl", "get",
279+
"customresourcedefinitions.apiextensions.k8s.io",
280+
"wordpresses.example.com.testproject.org",
281+
"-o", "go-template={{ .spec.conversion.webhook.clientConfig.caBundle }}")
282+
vwhOutput, err := utils.Run(cmd)
283+
g.Expect(err).NotTo(HaveOccurred())
284+
g.Expect(len(vwhOutput)).To(BeNumerically(">", 10))
285+
}
286+
Eventually(verifyCAInjection).Should(Succeed())
287+
})
288+
275289
// +kubebuilder:scaffold:e2e-webhooks-checks
276290

277291
// TODO: Customize the e2e test suite with scenarios specific to your project.

testdata/project-v4-with-plugins/test/e2e/e2e_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,20 @@ var _ = Describe("Manager", Ordered, func() {
258258
Eventually(verifyCAInjection).Should(Succeed())
259259
})
260260

261+
It("should have CA injection for Wordpress conversion webhook", func() {
262+
By("checking CA injection for Wordpress conversion webhook")
263+
verifyCAInjection := func(g Gomega) {
264+
cmd := exec.Command("kubectl", "get",
265+
"customresourcedefinitions.apiextensions.k8s.io",
266+
"wordpresses.example.com.testproject.org",
267+
"-o", "go-template={{ .spec.conversion.webhook.clientConfig.caBundle }}")
268+
vwhOutput, err := utils.Run(cmd)
269+
g.Expect(err).NotTo(HaveOccurred())
270+
g.Expect(len(vwhOutput)).To(BeNumerically(">", 10))
271+
}
272+
Eventually(verifyCAInjection).Should(Succeed())
273+
})
274+
261275
// +kubebuilder:scaffold:e2e-webhooks-checks
262276

263277
// TODO: Customize the e2e test suite with scenarios specific to your project.

testdata/project-v4/test/e2e/e2e_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,20 @@ var _ = Describe("Manager", Ordered, func() {
272272
Eventually(verifyCAInjection).Should(Succeed())
273273
})
274274

275+
It("should have CA injection for FirstMate conversion webhook", func() {
276+
By("checking CA injection for FirstMate conversion webhook")
277+
verifyCAInjection := func(g Gomega) {
278+
cmd := exec.Command("kubectl", "get",
279+
"customresourcedefinitions.apiextensions.k8s.io",
280+
"firstmates.crew.testproject.org",
281+
"-o", "go-template={{ .spec.conversion.webhook.clientConfig.caBundle }}")
282+
vwhOutput, err := utils.Run(cmd)
283+
g.Expect(err).NotTo(HaveOccurred())
284+
g.Expect(len(vwhOutput)).To(BeNumerically(">", 10))
285+
}
286+
Eventually(verifyCAInjection).Should(Succeed())
287+
})
288+
275289
// +kubebuilder:scaffold:e2e-webhooks-checks
276290

277291
// TODO: Customize the e2e test suite with scenarios specific to your project.

0 commit comments

Comments
 (0)