Skip to content

Commit

Permalink
Merge pull request #4407 from mateusoliveira43/fix/conversion-webhook…
Browse files Browse the repository at this point in the history
…-e2e-test

✨ (go/v4): add support to inject conversion webhook for the marker +kubebuilder:scaffold:e2e-webhooks-checks
  • Loading branch information
k8s-ci-robot authored Dec 6, 2024
2 parents 7c14cc9 + 9b5ad9c commit 6c6d6fa
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 6c6d6fa

Please sign in to comment.