@@ -19,6 +19,7 @@ package watch
19
19
import (
20
20
"context"
21
21
"fmt"
22
+ "sync"
22
23
"time"
23
24
24
25
"k8s.io/apimachinery/pkg/api/meta"
@@ -56,7 +57,7 @@ type dynamicWatch struct {
56
57
57
58
// lastRV caches the last reported resource version.
58
59
// This helps us avoid sending duplicate events (e.g. on a rewatch)
59
- lastRV map [types. NamespacedName ] string
60
+ lastRV sync. Map
60
61
}
61
62
62
63
func (dw * dynamicWatch ) newDynamicClient (gvk schema.GroupVersionKind , namespace string ) (dynamic.ResourceInterface , error ) {
@@ -79,7 +80,7 @@ func (dw *dynamicWatch) Add(trigger schema.GroupVersionKind, options metav1.List
79
80
return fmt .Errorf ("creating client for (%s): %v" , trigger .String (), err )
80
81
}
81
82
82
- dw .lastRV = make ( map [types. NamespacedName ] string )
83
+ dw .lastRV = sync. Map {}
83
84
84
85
go func () {
85
86
for {
@@ -140,14 +141,14 @@ func (dw *dynamicWatch) watchUntilClosed(client dynamic.ResourceInterface, trigg
140
141
switch clientEvent .Type {
141
142
case watch .Deleted :
142
143
// stop lastRV growing indefinitely
143
- delete ( dw .lastRV , key )
144
+ dw .lastRV . Delete ( key )
144
145
// We always send the delete notification
145
146
case watch .Added , watch .Modified :
146
- if previousRV , found := dw .lastRV [ key ] ; found && previousRV == rv {
147
+ if previousRV , found := dw .lastRV . Load ( key ) ; found && previousRV == rv {
147
148
// Don't send spurious invalidations
148
149
continue
149
150
}
150
- dw .lastRV [ key ] = rv
151
+ dw .lastRV . Store ( key , rv )
151
152
}
152
153
153
154
log .WithValues ("type" , clientEvent .Type ).WithValues ("kind" , trigger .String ()).WithValues ("name" , key .Name , "namespace" , key .Namespace ).Info ("broadcasting event" )
0 commit comments