@@ -26,12 +26,14 @@ import (
2626 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
2727 apiextensionsfake "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake"
2828 aextv1beta1 "k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions"
29+ "k8s.io/apimachinery/pkg/api/equality"
2930 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3031 "k8s.io/apimachinery/pkg/labels"
3132 "k8s.io/apimachinery/pkg/runtime"
3233 "k8s.io/apimachinery/pkg/util/diff"
3334 utilerrors "k8s.io/apimachinery/pkg/util/errors"
3435 "k8s.io/apimachinery/pkg/util/intstr"
36+ "k8s.io/apimachinery/pkg/util/wait"
3537 "k8s.io/client-go/informers"
3638 k8sfake "k8s.io/client-go/kubernetes/fake"
3739 "k8s.io/client-go/pkg/version"
@@ -3002,6 +3004,7 @@ func TestUpdates(t *testing.T) {
30023004 }
30033005
30043006 deleted := v1alpha1 .ClusterServiceVersionPhase ("deleted" )
3007+ noPrevious := v1alpha1 .ClusterServiceVersionPhase ("NoPrevious" )
30053008
30063009 crd := crd ("c1" , "v1" , "g1" )
30073010 a := csv ("csvA" ,
@@ -3211,13 +3214,40 @@ func TestUpdates(t *testing.T) {
32113214 for i := range tt .expected ["csvA" ] {
32123215 // sync all csvs once
32133216 for _ , csv := range tt .in {
3214- if i > 0 && tt .expected [csv .GetName ()][i - 1 ] == deleted {
3215- // don't sync deleted csvs
3217+ name := csv .GetName ()
3218+ expectedCurrent := tt.expected [name ][i ]
3219+ var expectedPrevious v1alpha1.ClusterServiceVersionPhase
3220+ if i > 0 {
3221+ expectedPrevious = tt .expected [name ][i - 1 ]
3222+ } else {
3223+ expectedPrevious = noPrevious
3224+ }
3225+
3226+ if expectedPrevious == deleted {
3227+ // don't sync previously deleted csvs
32163228 continue
32173229 }
3218- fetched , err := op .GetClient ().OperatorsV1alpha1 ().ClusterServiceVersions (namespace ).Get (csv .GetName (), metav1.GetOptions {})
3230+
3231+ // Get the CSV from the cluster
3232+ fetched , err := op .GetClient ().OperatorsV1alpha1 ().ClusterServiceVersions (namespace ).Get (name , metav1.GetOptions {})
32193233 require .NoError (t , err )
3220- op .syncClusterServiceVersion (fetched )
3234+
3235+ // Sync the CSV once
3236+ _ = op .syncClusterServiceVersion (fetched )
3237+
3238+ // If the csv was deleted by the sync, we don't bother waiting for listers to sync
3239+ if expectedCurrent == deleted {
3240+ continue
3241+ }
3242+
3243+ // If we expect a change, wait for listers to sync the change so that the next sync reflects the changes
3244+ if expectedCurrent != expectedPrevious {
3245+ err = wait .PollImmediate (1 * time .Millisecond , 5 * time .Second , func () (bool , error ) {
3246+ updated , err := op .lister .OperatorsV1alpha1 ().ClusterServiceVersionLister ().ClusterServiceVersions (namespace ).Get (csv .GetName ())
3247+ return ! equality .Semantic .DeepEqual (updated , fetched ), err
3248+ })
3249+ require .NoError (t , err )
3250+ }
32213251 }
32223252
32233253 // check that each csv is in the expected phase
0 commit comments