@@ -249,12 +249,11 @@ func (n namespacedName) String() string {
249249}
250250
251251// pvcToSnapshotsMap maps a PVC to its snapshots.
252- // Key is the namespaced name of the PVC and value is a map.
253- // The key of the inner map is the namespaced name of the snapshot.
254- // TODO: change the key of the inner map to string
252+ // The primary key is the namespaced name of the PVC and value is a map.
253+ // The key of the inner map is the name of the snapshot.
255254type pvcToSnapshotsMap struct {
256255 * sync.RWMutex
257- items map [namespacedName ]map [namespacedName ]struct {}
256+ items map [namespacedName ]map [string ]struct {}
258257}
259258
260259func (m * pvcToSnapshotsMap ) add (pvc , snapshot , namespace string ) {
@@ -266,13 +265,9 @@ func (m *pvcToSnapshotsMap) add(pvc, snapshot, namespace string) {
266265 name : pvc ,
267266 }
268267 if _ , ok := m .items [pvcKey ]; ! ok {
269- m .items [pvcKey ] = make (map [namespacedName ]struct {})
268+ m .items [pvcKey ] = make (map [string ]struct {})
270269 }
271- snapKey := namespacedName {
272- namespace : namespace ,
273- name : snapshot ,
274- }
275- m.items [pvcKey ][snapKey ] = struct {}{}
270+ m.items [pvcKey ][snapshot ] = struct {}{}
276271}
277272
278273func (m * pvcToSnapshotsMap ) get (pvc , namespace string ) []string {
@@ -289,8 +284,8 @@ func (m *pvcToSnapshotsMap) get(pvc, namespace string) []string {
289284 }
290285
291286 snaps := make ([]string , 0 , len (snapMap ))
292- for k := range snapMap {
293- snaps = append (snaps , k . name )
287+ for snap := range snapMap {
288+ snaps = append (snaps , snap )
294289 }
295290 return snaps
296291}
@@ -308,11 +303,7 @@ func (m *pvcToSnapshotsMap) delete(pvc, snapshot, namespace string) {
308303 return
309304 }
310305
311- snapKey := namespacedName {
312- namespace : namespace ,
313- name : snapshot ,
314- }
315- delete (snapMap , snapKey )
306+ delete (snapMap , snapshot )
316307 if len (snapMap ) != 0 {
317308 m .items [pvcKey ] = snapMap
318309 return
@@ -2045,7 +2036,7 @@ func initPVCToSnapshotsMap(ctx context.Context, controllerClusterFlavor cnstypes
20452036
20462037 k8sOrchestratorInstance .pvcToSnapshotsMap = pvcToSnapshotsMap {
20472038 RWMutex : & sync.RWMutex {},
2048- items : make (map [namespacedName ]map [namespacedName ]struct {}),
2039+ items : make (map [namespacedName ]map [string ]struct {}),
20492040 }
20502041 snapshotAdded := func (obj any ) {
20512042 snap , ok := obj .(* snapshotv1.VolumeSnapshot )
@@ -2086,6 +2077,8 @@ func initPVCToSnapshotsMap(ctx context.Context, controllerClusterFlavor cnstypes
20862077 func (obj any ) {
20872078 snapshotAdded (obj )
20882079 },
2080+ // Since the name of PVC associated with a snapshot is immutable,
2081+ // update events do not have any impact on the state of the cache.
20892082 nil ,
20902083 func (obj any ) {
20912084 snapshotDeleted (obj )
0 commit comments