Skip to content

Commit

Permalink
Merge pull request #1377 from KielChan/FixMultiListWatchResourceVersi…
Browse files Browse the repository at this point in the history
…onMismatchWhenWatchReconnected

fix multiListWatch resourceVersion mismatch if watch reconnected
  • Loading branch information
k8s-ci-robot committed Mar 17, 2021
2 parents 3626f8a + c3e7eb5 commit 030b089
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/listwatch/listwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,17 @@ func (mlw multiListerWatcher) Watch(options metav1.ListOptions) (watch.Interface
resourceVersions := make([]string, len(mlw))
// Allow resource versions to be "".
if options.ResourceVersion != "" {
rvs := strings.Split(options.ResourceVersion, "/")
if len(rvs) != len(mlw) {
return nil, fmt.Errorf("expected resource version to have %d parts to match the number of ListerWatchers", len(mlw))
rvs := make([]string, 0, len(mlw))
if strings.Contains(options.ResourceVersion, "/") {
rvs = strings.Split(options.ResourceVersion, "/")
if len(rvs) != len(mlw) {
return nil, fmt.Errorf("expected resource version to have %d parts to match the number of ListerWatchers, actual: %d", len(mlw), len(rvs))
}
} else {
// watch reconnected and resource version is the latest one from event.Object has no "/"
for i := 0; i < len(mlw); i++ {
rvs = append(rvs, options.ResourceVersion)
}
}
resourceVersions = rvs
}
Expand Down

0 comments on commit 030b089

Please sign in to comment.