@@ -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