4
4
"bytes"
5
5
"context"
6
6
"encoding/json"
7
- "errors"
8
7
"fmt"
9
8
"path/filepath"
10
9
"strconv"
@@ -31,7 +30,6 @@ import (
31
30
k8sjson "k8s.io/apimachinery/pkg/runtime/serializer/json"
32
31
"k8s.io/apimachinery/pkg/util/diff"
33
32
"k8s.io/apimachinery/pkg/util/wait"
34
- "k8s.io/apimachinery/pkg/watch"
35
33
"k8s.io/client-go/discovery"
36
34
"k8s.io/client-go/util/retry"
37
35
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -2869,92 +2867,42 @@ var _ = Describe("Install Plan", func() {
2869
2867
// Should have removed every matching step
2870
2868
require .Equal (GinkgoT (), 0 , len (expectedSteps ), "Actual resource steps do not match expected: %#v" , expectedSteps )
2871
2869
2872
- // the test from here out verifies created RBAC is removed after CSV deletion
2873
- createdClusterRoles , err := c . KubernetesInterface (). RbacV1 (). ClusterRoles (). List ( context . Background (), metav1. ListOptions { LabelSelector : fmt . Sprintf ( "%v=%v" , ownerutil . OwnerKey , stableCSVName )})
2874
- createdClusterRoleNames := map [ string ] struct {}{}
2875
- for _ , role := range createdClusterRoles . Items {
2876
- createdClusterRoleNames [ role . GetName ()] = struct {}{}
2877
- GinkgoT (). Logf ( "Monitoring cluster role %v" , role . GetName ())
2870
+ GinkgoT (). Logf ( "deleting csv %s/%s" , generatedNamespace . GetName (), stableCSVName )
2871
+ // Explicitly delete the CSV
2872
+ err = crc . OperatorsV1alpha1 (). ClusterServiceVersions ( generatedNamespace . GetName ()). Delete ( context . Background (), stableCSVName , metav1. DeleteOptions {})
2873
+ // Looking for no error OR IsNotFound error
2874
+ if err != nil && apierrors . IsNotFound ( err ) {
2875
+ err = nil
2878
2876
}
2879
-
2880
- createdClusterRoleBindings , err := c .KubernetesInterface ().RbacV1 ().ClusterRoleBindings ().List (context .Background (), metav1.ListOptions {LabelSelector : fmt .Sprintf ("%v=%v" , ownerutil .OwnerKey , stableCSVName )})
2881
- createdClusterRoleBindingNames := map [string ]struct {}{}
2882
- for _ , binding := range createdClusterRoleBindings .Items {
2883
- createdClusterRoleBindingNames [binding .GetName ()] = struct {}{}
2884
- GinkgoT ().Logf ("Monitoring cluster role binding %v" , binding .GetName ())
2885
- }
2886
-
2887
- crWatcher , err := c .KubernetesInterface ().RbacV1 ().ClusterRoles ().Watch (context .Background (), metav1.ListOptions {LabelSelector : fmt .Sprintf ("%v=%v" , ownerutil .OwnerKey , stableCSVName )})
2888
- require .NoError (GinkgoT (), err )
2889
- crbWatcher , err := c .KubernetesInterface ().RbacV1 ().ClusterRoleBindings ().Watch (context .Background (), metav1.ListOptions {LabelSelector : fmt .Sprintf ("%v=%v" , ownerutil .OwnerKey , stableCSVName )})
2890
2877
require .NoError (GinkgoT (), err )
2891
2878
2892
- done := make (chan struct {})
2893
- errExit := make (chan error )
2894
- go func () {
2895
- defer GinkgoRecover ()
2896
- for {
2897
- select {
2898
- case evt , ok := <- crWatcher .ResultChan ():
2899
- if ! ok {
2900
- errExit <- errors .New ("cr watch channel closed unexpectedly" )
2901
- return
2902
- }
2903
- if evt .Type == watch .Deleted {
2904
- cr , ok := evt .Object .(* rbacv1.ClusterRole )
2905
- if ! ok {
2906
- continue
2907
- }
2908
- delete (createdClusterRoleNames , cr .GetName ())
2909
- if len (createdClusterRoleNames ) == 0 && len (createdClusterRoleBindingNames ) == 0 {
2910
- done <- struct {}{}
2911
- return
2912
- }
2913
- }
2914
- case evt , ok := <- crbWatcher .ResultChan ():
2915
- if ! ok {
2916
- errExit <- errors .New ("crb watch channel closed unexpectedly" )
2917
- return
2918
- }
2919
- if evt .Type == watch .Deleted {
2920
- crb , ok := evt .Object .(* rbacv1.ClusterRoleBinding )
2921
- if ! ok {
2922
- continue
2923
- }
2924
- delete (createdClusterRoleBindingNames , crb .GetName ())
2925
- if len (createdClusterRoleNames ) == 0 && len (createdClusterRoleBindingNames ) == 0 {
2926
- done <- struct {}{}
2927
- return
2928
- }
2929
- }
2930
- case <- time .After (pollDuration ):
2931
- done <- struct {}{}
2932
- return
2933
- }
2879
+ Eventually (func () bool {
2880
+ crbs , err := c .KubernetesInterface ().RbacV1 ().ClusterRoleBindings ().List (context .Background (), metav1.ListOptions {LabelSelector : fmt .Sprintf ("%v=%v" , ownerutil .OwnerKey , stableCSVName )})
2881
+ if err != nil {
2882
+ GinkgoT ().Logf ("error getting crbs: %v" , err )
2883
+ return false
2884
+ }
2885
+ if len (crbs .Items ) != 0 {
2886
+ return false
2934
2887
}
2935
- }()
2936
- GinkgoT ().Logf ("Deleting CSV '%v' in namespace %v" , stableCSVName , generatedNamespace .GetName ())
2937
- require .NoError (GinkgoT (), crc .OperatorsV1alpha1 ().ClusterServiceVersions (generatedNamespace .GetName ()).DeleteCollection (context .Background (), metav1.DeleteOptions {}, metav1.ListOptions {}))
2938
- select {
2939
- case <- done :
2940
- break
2941
- case err := <- errExit :
2942
- GinkgoT ().Fatal (err )
2943
- }
2944
-
2945
- require .Emptyf (GinkgoT (), createdClusterRoleNames , "unexpected cluster role remain: %v" , createdClusterRoleNames )
2946
- require .Emptyf (GinkgoT (), createdClusterRoleBindingNames , "unexpected cluster role binding remain: %v" , createdClusterRoleBindingNames )
2947
2888
2948
- Eventually ( func () error {
2949
- _ , err := c . GetServiceAccount ( generatedNamespace . GetName (), serviceAccountName )
2950
- if err == nil {
2951
- return fmt . Errorf ( "The %v/%v ServiceAccount should have been deleted" , generatedNamespace . GetName (), serviceAccountName )
2889
+ crs , err := c . KubernetesInterface (). RbacV1 (). ClusterRoles (). List ( context . Background (), metav1. ListOptions { LabelSelector : fmt . Sprintf ( "%v=%v" , ownerutil . OwnerKey , stableCSVName )})
2890
+ if err != nil {
2891
+ GinkgoT (). Logf ( "error getting crs: %v" , err )
2892
+ return false
2952
2893
}
2953
- if ! apierrors .IsNotFound (err ) {
2954
- return err
2894
+ if len (crs .Items ) != 0 {
2895
+ return false
2896
+ }
2897
+
2898
+ _ , err = c .KubernetesInterface ().CoreV1 ().ServiceAccounts (generatedNamespace .GetName ()).Get (context .Background (), serviceAccountName , metav1.GetOptions {})
2899
+ if err != nil && ! apierrors .IsNotFound (err ) {
2900
+ GinkgoT ().Logf ("error getting sa %s/%s: %v" , generatedNamespace .GetName (), serviceAccountName , err )
2901
+ return false
2955
2902
}
2956
- return nil
2957
- }, timeout , interval ).Should (BeNil ())
2903
+
2904
+ return true
2905
+ }, pollDuration * 2 , pollInterval ).Should (BeTrue ())
2958
2906
})
2959
2907
2960
2908
It ("CRD validation" , func () {
0 commit comments