Skip to content

Commit

Permalink
Add Uninstall Contour CRDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Vaseekaran committed Nov 25, 2024
1 parent 3f99b3e commit c13ddf0
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/e2e/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func apiGroupKoperatorDependencies() map[string]string {
"cert-manager": "cert-manager.io",
"zookeeper": "zookeeper.pravega.io",
"prometheus": "monitoring.coreos.com",
"contour": "projectcontour.io",
}
}

Expand Down
5 changes: 5 additions & 0 deletions tests/e2e/test_uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,10 @@ func testUninstall() bool {
ConfigPath: kubectlOptions.ConfigPath,
Namespace: certManagerHelmDescriptor.Namespace,
})
requireUninstallingContour(k8s.KubectlOptions{
ContextName: kubectlOptions.ContextName,
ConfigPath: kubectlOptions.ConfigPath,
Namespace: contourIngressControllerHelmDescriptor.Namespace,
})
})
}
8 changes: 8 additions & 0 deletions tests/e2e/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type dependencyCRDsType struct {
zookeeper []string
prometheus []string
certManager []string
contour []string
}

func (c *dependencyCRDsType) Zookeeper() []string {
Expand All @@ -35,13 +36,20 @@ func (c *dependencyCRDsType) Prometheus() []string {
func (c *dependencyCRDsType) CertManager() []string {
return c.certManager
}
func (c *dependencyCRDsType) Contour() []string {
return c.contour
}

func (c *dependencyCRDsType) Initialize(kubectlOptions k8s.KubectlOptions) error {
var err error
c.certManager, err = listK8sResourceKinds(kubectlOptions, apiGroupKoperatorDependencies()["cert-manager"])
if err != nil {
return fmt.Errorf("initialize Cert-manager CRDs error: %w", err)
}
c.contour, err = listK8sResourceKinds(kubectlOptions, apiGroupKoperatorDependencies()["contour"])
if err != nil {
return fmt.Errorf("initialize Contour Ingress Controller CRDs error: %w", err)
}
c.prometheus, err = listK8sResourceKinds(kubectlOptions, apiGroupKoperatorDependencies()["prometheus"])
if err != nil {
return fmt.Errorf("initialize Prometheus CRDs error: %w", err)
Expand Down
43 changes: 43 additions & 0 deletions tests/e2e/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,49 @@ func requireRemoveCertManagerCRDs(kubectlOptions k8s.KubectlOptions) {
}
})
}
func requireUninstallingContour(kubectlOptions k8s.KubectlOptions) {
When("Uninstalling zookeeper-operator", func() {
requireUninstallingContourHelmChart(kubectlOptions)
requireRemoveContourCRDs(kubectlOptions)
requireRemoveNamespace(kubectlOptions, contourIngressControllerHelmDescriptor.Namespace)
})
}

// requireUninstallingCertManagerHelmChart uninstalls cert-manager helm chart
// and checks the success of that operation.
func requireUninstallingContourHelmChart(kubectlOptions k8s.KubectlOptions) {
It("Uninstalling Project Contour Helm chart", func() {
err := contourIngressControllerHelmDescriptor.uninstallHelmChart(kubectlOptions, true)
Expect(err).NotTo(HaveOccurred())

By("Verifying Project Contour helm chart resources cleanup")

k8sResourceKinds, err := listK8sResourceKinds(kubectlOptions, "")
Expect(err).ShouldNot(HaveOccurred())

contourAvailableResourceKinds := stringSlicesInstersect(dependencyCRDs.Contour(), k8sResourceKinds)
contourAvailableResourceKinds = append(contourAvailableResourceKinds, basicK8sResourceKinds()...)

remainedResources, err := getK8sResources(kubectlOptions,
contourAvailableResourceKinds,
fmt.Sprintf(managedByHelmLabelTemplate, contourIngressControllerHelmDescriptor.ReleaseName),
"",
kubectlArgGoTemplateKindNameNamespace,
"--all-namespaces")
Expect(err).ShouldNot(HaveOccurred())

Expect(remainedResources).Should(BeEmpty())
})
}

func requireRemoveContourCRDs(kubectlOptions k8s.KubectlOptions) {
It("Removing Contour Ingress Controller CRDs", func() {
for _, crd := range dependencyCRDs.Contour() {
err := deleteK8sResourceNoErrNotFound(kubectlOptions, defaultDeletionTimeout, crdKind, crd)
Expect(err).ShouldNot(HaveOccurred())
}
})
}

// requireRemoveNamespace deletes the indicated namespace object
func requireRemoveNamespace(kubectlOptions k8s.KubectlOptions, namespace string) {
Expand Down

0 comments on commit c13ddf0

Please sign in to comment.