Skip to content

Commit d597e34

Browse files
authored
test: cleanup addon csr (#312)
Signed-off-by: zhujian <[email protected]>
1 parent 9d436ff commit d597e34

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

test/e2e/helloworld_helm_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ var _ = ginkgo.Describe("install/uninstall helloworld helm addons", func() {
142142

143143
return err
144144
}, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred())
145+
146+
ginkgo.By(fmt.Sprintf("Clean up CSRs for addon: %s", helloWorldHelmAddonName))
147+
_ = cleanupCSR(hubKubeClient, helloWorldHelmAddonName)
145148
})
146149

147150
ginkgo.It("addon should be available", func() {

test/e2e/helloworld_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"k8s.io/apimachinery/pkg/api/resource"
1515
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1616
"k8s.io/apimachinery/pkg/util/rand"
17+
"k8s.io/client-go/kubernetes"
1718
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
1819
)
1920

@@ -100,6 +101,9 @@ var _ = ginkgo.Describe("install/uninstall helloworld addons", func() {
100101

101102
return err
102103
}, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred())
104+
105+
ginkgo.By(fmt.Sprintf("Clean up CSRs for addon: %s", addonName))
106+
_ = cleanupCSR(hubKubeClient, addonName)
103107
})
104108

105109
ginkgo.It("addon should be worked", func() {
@@ -673,3 +677,26 @@ func prepareAgentInstallNamespaceAddOnDeploymentConfig(namespace string) error {
673677

674678
return err
675679
}
680+
681+
func cleanupCSR(hubKubeClient kubernetes.Interface, addonName string) error {
682+
csrs, err := hubKubeClient.CertificatesV1().CertificateSigningRequests().List(
683+
context.Background(), metav1.ListOptions{
684+
LabelSelector: fmt.Sprintf("%s=%s", addonapiv1alpha1.AddonLabelKey, addonName),
685+
})
686+
if err != nil {
687+
return err
688+
}
689+
690+
for _, csr := range csrs.Items {
691+
692+
if csr.Status.Certificate == nil {
693+
continue
694+
}
695+
err := hubKubeClient.CertificatesV1().CertificateSigningRequests().Delete(
696+
context.Background(), csr.Name, *&metav1.DeleteOptions{})
697+
if err != nil {
698+
return err
699+
}
700+
}
701+
return nil
702+
}

0 commit comments

Comments
 (0)