@@ -15,6 +15,8 @@ import (
1515 "github.com/stretchr/testify/require"
1616 corev1 "k8s.io/api/core/v1"
1717 v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
19+ "k8s.io/apimachinery/pkg/runtime"
1820 "k8s.io/apimachinery/pkg/watch"
1921 dynamicfake "k8s.io/client-go/dynamic/fake"
2022 "k8s.io/client-go/kubernetes/scheme"
@@ -81,13 +83,19 @@ func testWaiter(t *testing.T, when spec.G, it spec.S) {
8183 Status : conditionReady (corev1 .ConditionFalse , generation - 1 ),
8284 }
8385
86+ builderObj := & v1alpha2.Builder {
87+ TypeMeta : resourceToWatch .TypeMeta ,
88+ ObjectMeta : resourceToWatch .ObjectMeta ,
89+ Status : v1alpha2.BuilderStatus {Status : conditionReady (corev1 .ConditionTrue , generation )},
90+ }
91+
92+ content , err := runtime .DefaultUnstructuredConverter .ToUnstructured (builderObj )
93+ if err != nil {
94+ panic (err )
95+ }
8496 watcher .addEvent (watch.Event {
85- Type : watch .Modified ,
86- Object : & v1alpha2.Builder {
87- TypeMeta : resourceToWatch .TypeMeta ,
88- ObjectMeta : resourceToWatch .ObjectMeta ,
89- Status : v1alpha2.BuilderStatus {Status : conditionReady (corev1 .ConditionTrue , generation )},
90- },
97+ Type : watch .Modified ,
98+ Object : & unstructured.Unstructured {Object : content },
9199 })
92100
93101 require .NoError (t , waiter .Wait (context .Background (), resourceToWatch ))
@@ -99,18 +107,56 @@ func testWaiter(t *testing.T, when spec.G, it spec.S) {
99107 Status : conditionReady (corev1 .ConditionFalse , generation - 1 ),
100108 }
101109
110+ builderObj := & v1alpha2.Builder {
111+ TypeMeta : resourceToWatch .TypeMeta ,
112+ ObjectMeta : resourceToWatch .ObjectMeta ,
113+ Status : v1alpha2.BuilderStatus {Status : conditionReady (corev1 .ConditionTrue , generation )},
114+ }
115+
116+ content , err := runtime .DefaultUnstructuredConverter .ToUnstructured (builderObj )
117+ if err != nil {
118+ panic (err )
119+ }
102120 watcher .addEvent (watch.Event {
103- Type : watch .Modified ,
104- Object : & v1alpha2.Builder {
105- TypeMeta : resourceToWatch .TypeMeta ,
106- ObjectMeta : resourceToWatch .ObjectMeta ,
107- Status : v1alpha2.BuilderStatus {Status : conditionReady (corev1 .ConditionTrue , generation )},
108- },
121+ Type : watch .Modified ,
122+ Object : & unstructured.Unstructured {Object : content },
109123 })
110124
111125 require .NoError (t , waiter .Wait (context .Background (), resourceToWatch , fakeConditionChecker .conditionCheck ))
112126 require .True (t , fakeConditionChecker .called )
113127 })
128+
129+ it ("recovers from too old resource version error" , func () {
130+ watcher .addEvent (watch.Event {
131+ Type : watch .Error ,
132+ Object : & v1.Status {
133+ TypeMeta : v1.TypeMeta {
134+ APIVersion : "v1" ,
135+ Kind : "Status" ,
136+ },
137+ Status : "Failure" ,
138+ Message : "too old resource version: 23358 (23360)" ,
139+ Reason : "Expired" ,
140+ Code : 410 ,
141+ },
142+ })
143+
144+ builderObj := & v1alpha2.Builder {
145+ TypeMeta : resourceToWatch .TypeMeta ,
146+ ObjectMeta : resourceToWatch .ObjectMeta ,
147+ Status : v1alpha2.BuilderStatus {Status : conditionReady (corev1 .ConditionTrue , generation )},
148+ }
149+ content , err := runtime .DefaultUnstructuredConverter .ToUnstructured (builderObj )
150+ if err != nil {
151+ panic (err )
152+ }
153+ watcher .addEvent (watch.Event {
154+ Type : watch .Modified ,
155+ Object : & unstructured.Unstructured {Object : content },
156+ })
157+
158+ require .NoError (t , waiter .Wait (context .Background (), resourceToWatch ))
159+ })
114160 })
115161}
116162
@@ -121,7 +167,6 @@ type fakeConditionChecker struct {
121167func (cc * fakeConditionChecker ) conditionCheck (_ watch.Event ) (bool , error ) {
122168 cc .called = true
123169 return true , nil
124-
125170}
126171
127172func conditionReady (status corev1.ConditionStatus , generation int64 ) corev1alpha1.Status {
@@ -159,10 +204,6 @@ func (t *TestWatcher) watchReactor(action clientgotesting.Action) (handled bool,
159204 }
160205
161206 watchAction := action .(clientgotesting.WatchAction )
162- if watchAction .GetWatchRestrictions ().ResourceVersion != t .expectedResource .GetObjectMeta ().GetResourceVersion () {
163- return true , nil , errors .New ("expected watch on resource version" )
164- }
165-
166207 if watchAction .GetNamespace () != t .expectedResource .GetObjectMeta ().GetNamespace () {
167208 return true , nil , errors .New ("expected watch on namespace" )
168209 }
0 commit comments