Skip to content

Commit

Permalink
fix: conversion webhook E2E test
Browse files Browse the repository at this point in the history
Signed-off-by: Mateus Oliveira <[email protected]>
  • Loading branch information
mateusoliveira43 committed Dec 6, 2024
1 parent 077dea8 commit 9b5ad9c
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ var _ = Describe("Manager", Ordered, func() {
Eventually(verifyCAInjection).Should(Succeed())
})

It("should have CA injection for CronJob conversion webhook", func() {
By("checking CA injection for CronJob conversion webhook")
verifyCAInjection := func(g Gomega) {
cmd := exec.Command("kubectl", "get",
"customresourcedefinitions.apiextensions.k8s.io",
"cronjobs.batch.tutorial.kubebuilder.io",
"-o", "go-template={{ .spec.conversion.webhook.clientConfig.caBundle }}")
vwhOutput, err := utils.Run(cmd)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(len(vwhOutput)).To(BeNumerically(">", 10))
}
Eventually(verifyCAInjection).Should(Succeed())
})

// +kubebuilder:scaffold:e2e-webhooks-checks

// TODO: Customize the e2e test suite with scenarios specific to your project.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ func (f *WebhookTestUpdater) GetCodeFragments() machinery.CodeFragmentsMap {
)
}

if f.Resource.HasConversionWebhook() {
conversionWebhookCode := fmt.Sprintf(
conversionWebhookChecksFragment,
f.Resource.Kind,
f.Resource.Plural+"."+f.Resource.Group+"."+f.Resource.Domain,
)
codeFragments[machinery.NewMarkerFor(f.GetPath(), webhookChecksMarker)] = append(
codeFragments[machinery.NewMarkerFor(f.GetPath(), webhookChecksMarker)],
conversionWebhookCode,
)
}

return codeFragments
}

Expand Down Expand Up @@ -147,6 +159,22 @@ const validatingWebhookChecksFragment = `It("should have CA injection for valida
`

const conversionWebhookChecksFragment = `It("should have CA injection for %[1]s conversion webhook", func() {
By("checking CA injection for %[1]s conversion webhook")
verifyCAInjection := func(g Gomega) {
cmd := exec.Command("kubectl", "get",
"customresourcedefinitions.apiextensions.k8s.io",
"%[2]s",
"-o", "go-template={{ .spec.conversion.webhook.clientConfig.caBundle }}")
vwhOutput, err := utils.Run(cmd)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(len(vwhOutput)).To(BeNumerically(">", 10))
}
Eventually(verifyCAInjection).Should(Succeed())
})
`

var TestTemplate = `{{ .Boilerplate }}
Expand Down
14 changes: 14 additions & 0 deletions testdata/project-v4-multigroup/test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ var _ = Describe("Manager", Ordered, func() {
Eventually(verifyCAInjection).Should(Succeed())
})

It("should have CA injection for Wordpress conversion webhook", func() {
By("checking CA injection for Wordpress conversion webhook")
verifyCAInjection := func(g Gomega) {
cmd := exec.Command("kubectl", "get",
"customresourcedefinitions.apiextensions.k8s.io",
"wordpresses.example.com.testproject.org",
"-o", "go-template={{ .spec.conversion.webhook.clientConfig.caBundle }}")
vwhOutput, err := utils.Run(cmd)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(len(vwhOutput)).To(BeNumerically(">", 10))
}
Eventually(verifyCAInjection).Should(Succeed())
})

// +kubebuilder:scaffold:e2e-webhooks-checks

// TODO: Customize the e2e test suite with scenarios specific to your project.
Expand Down
14 changes: 14 additions & 0 deletions testdata/project-v4-with-plugins/test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,20 @@ var _ = Describe("Manager", Ordered, func() {
Eventually(verifyCAInjection).Should(Succeed())
})

It("should have CA injection for Wordpress conversion webhook", func() {
By("checking CA injection for Wordpress conversion webhook")
verifyCAInjection := func(g Gomega) {
cmd := exec.Command("kubectl", "get",
"customresourcedefinitions.apiextensions.k8s.io",
"wordpresses.example.com.testproject.org",
"-o", "go-template={{ .spec.conversion.webhook.clientConfig.caBundle }}")
vwhOutput, err := utils.Run(cmd)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(len(vwhOutput)).To(BeNumerically(">", 10))
}
Eventually(verifyCAInjection).Should(Succeed())
})

// +kubebuilder:scaffold:e2e-webhooks-checks

// TODO: Customize the e2e test suite with scenarios specific to your project.
Expand Down
14 changes: 14 additions & 0 deletions testdata/project-v4/test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ var _ = Describe("Manager", Ordered, func() {
Eventually(verifyCAInjection).Should(Succeed())
})

It("should have CA injection for FirstMate conversion webhook", func() {
By("checking CA injection for FirstMate conversion webhook")
verifyCAInjection := func(g Gomega) {
cmd := exec.Command("kubectl", "get",
"customresourcedefinitions.apiextensions.k8s.io",
"firstmates.crew.testproject.org",
"-o", "go-template={{ .spec.conversion.webhook.clientConfig.caBundle }}")
vwhOutput, err := utils.Run(cmd)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(len(vwhOutput)).To(BeNumerically(">", 10))
}
Eventually(verifyCAInjection).Should(Succeed())
})

// +kubebuilder:scaffold:e2e-webhooks-checks

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

0 comments on commit 9b5ad9c

Please sign in to comment.