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 2, 2024
1 parent 077dea8 commit f334f3a
Show file tree
Hide file tree
Showing 5 changed files with 80 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 conversion webhooks", func() {
By("checking CA injection for conversion webhooks")
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,14 @@ func (f *WebhookTestUpdater) GetCodeFragments() machinery.CodeFragmentsMap {
)
}

if f.Resource.HasConversionWebhook() {
conversionWebhookCode := fmt.Sprintf(conversionWebhookChecksFragment, 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 +155,22 @@ const validatingWebhookChecksFragment = `It("should have CA injection for valida
`

const conversionWebhookChecksFragment = `It("should have CA injection for conversion webhooks", func() {
By("checking CA injection for conversion webhooks")
verifyCAInjection := func(g Gomega) {
cmd := exec.Command("kubectl", "get",
"customresourcedefinitions.apiextensions.k8s.io",
"%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 conversion webhooks", func() {
By("checking CA injection for conversion webhooks")
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 conversion webhooks", func() {
By("checking CA injection for conversion webhooks")
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 conversion webhooks", func() {
By("checking CA injection for conversion webhooks")
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 f334f3a

Please sign in to comment.