4
4
"context"
5
5
"fmt"
6
6
"log"
7
+ "strconv"
7
8
"time"
8
9
9
10
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -65,7 +66,7 @@ func (w *Watcher) Start(notifyF WatchNotifyFunctions, gvr schema.GroupVersionRes
65
66
return err
66
67
}
67
68
for i , item := range list .Items {
68
- if item .GetResourceVersion () > resourceVersion {
69
+ if isResourceVersionHigher ( item .GetResourceVersion (), resourceVersion ) {
69
70
// Update the resourceVersion to the latest
70
71
resourceVersion = item .GetResourceVersion ()
71
72
if w .preList {
@@ -127,7 +128,7 @@ func (w *Watcher) Start(notifyF WatchNotifyFunctions, gvr schema.GroupVersionRes
127
128
continue
128
129
}
129
130
// Update the resourceVersion
130
- if addedObject .GetResourceVersion () > resourceVersion {
131
+ if isResourceVersionHigher ( addedObject .GetResourceVersion (), resourceVersion ) {
131
132
resourceVersion = addedObject .GetResourceVersion ()
132
133
}
133
134
notifyF .AddFunc (addedObject )
@@ -140,7 +141,7 @@ func (w *Watcher) Start(notifyF WatchNotifyFunctions, gvr schema.GroupVersionRes
140
141
continue
141
142
}
142
143
// Update the resourceVersion
143
- if modifiedObject .GetResourceVersion () > resourceVersion {
144
+ if isResourceVersionHigher ( modifiedObject .GetResourceVersion (), resourceVersion ) {
144
145
resourceVersion = modifiedObject .GetResourceVersion ()
145
146
}
146
147
notifyF .UpdateFunc (modifiedObject )
@@ -153,7 +154,7 @@ func (w *Watcher) Start(notifyF WatchNotifyFunctions, gvr schema.GroupVersionRes
153
154
continue
154
155
}
155
156
// Update the resourceVersion
156
- if deletedObject .GetResourceVersion () > resourceVersion {
157
+ if isResourceVersionHigher ( deletedObject .GetResourceVersion (), resourceVersion ) {
157
158
resourceVersion = deletedObject .GetResourceVersion ()
158
159
}
159
160
notifyF .DeleteFunc (deletedObject )
@@ -177,3 +178,24 @@ func (w *Watcher) Stop() {
177
178
178
179
func (w * Watcher ) Destroy () {
179
180
}
181
+
182
+ func isResourceVersionHigher (resourceVersion string , currentResourceVersion string ) bool {
183
+ // If the currentResourceVersion is empty, return true
184
+ if currentResourceVersion == "" {
185
+ return true
186
+ }
187
+
188
+ // Convert the resourceVersion to int64
189
+ resourceVersionInt , err := strconv .ParseInt (resourceVersion , 10 , 64 )
190
+ if err != nil {
191
+ return false
192
+ }
193
+
194
+ // Convert the currentResourceVersion to int64
195
+ currentResourceVersionInt , err := strconv .ParseInt (currentResourceVersion , 10 , 64 )
196
+ if err != nil {
197
+ return false
198
+ }
199
+
200
+ return resourceVersionInt > currentResourceVersionInt
201
+ }
0 commit comments