Skip to content

Commit aab7fd2

Browse files
committed
Changed the pvcToSnapshotsMap type to use k8s NamespacedName
1 parent a4ea357 commit aab7fd2

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

pkg/csi/service/common/commonco/k8sorchestrator/k8sorchestrator.go

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -240,29 +240,21 @@ func (m *volumeIDToNameMap) get(volumeID string) (string, bool) {
240240
return volumeName, found
241241
}
242242

243-
type namespacedName struct {
244-
namespace, name string
245-
}
246-
247-
func (n namespacedName) String() string {
248-
return fmt.Sprintf("%s/%s", n.namespace, n.name)
249-
}
250-
251243
// pvcToSnapshotsMap maps a PVC to its snapshots.
252244
// The primary key is the namespaced name of the PVC and value is a map.
253245
// The key of the inner map is the name of the snapshot.
254246
type pvcToSnapshotsMap struct {
255247
*sync.RWMutex
256-
items map[namespacedName]map[string]struct{}
248+
items map[k8stypes.NamespacedName]map[string]struct{}
257249
}
258250

259251
func (m *pvcToSnapshotsMap) add(pvc, snapshot, namespace string) {
260252
m.Lock()
261253
defer m.Unlock()
262254

263-
pvcKey := namespacedName{
264-
namespace: namespace,
265-
name: pvc,
255+
pvcKey := k8stypes.NamespacedName{
256+
Namespace: namespace,
257+
Name: pvc,
266258
}
267259
if _, ok := m.items[pvcKey]; !ok {
268260
m.items[pvcKey] = make(map[string]struct{})
@@ -274,9 +266,9 @@ func (m *pvcToSnapshotsMap) get(pvc, namespace string) []string {
274266
m.RLock()
275267
defer m.RUnlock()
276268

277-
pvcKey := namespacedName{
278-
namespace: namespace,
279-
name: pvc,
269+
pvcKey := k8stypes.NamespacedName{
270+
Namespace: namespace,
271+
Name: pvc,
280272
}
281273
snapMap, ok := m.items[pvcKey]
282274
if !ok {
@@ -294,9 +286,9 @@ func (m *pvcToSnapshotsMap) delete(pvc, snapshot, namespace string) {
294286
m.Lock()
295287
defer m.Unlock()
296288

297-
pvcKey := namespacedName{
298-
namespace: namespace,
299-
name: pvc,
289+
pvcKey := k8stypes.NamespacedName{
290+
Namespace: namespace,
291+
Name: pvc,
300292
}
301293
snapMap, ok := m.items[pvcKey]
302294
if !ok {
@@ -2036,7 +2028,7 @@ func initPVCToSnapshotsMap(ctx context.Context, controllerClusterFlavor cnstypes
20362028

20372029
k8sOrchestratorInstance.pvcToSnapshotsMap = pvcToSnapshotsMap{
20382030
RWMutex: &sync.RWMutex{},
2039-
items: make(map[namespacedName]map[string]struct{}),
2031+
items: make(map[k8stypes.NamespacedName]map[string]struct{}),
20402032
}
20412033
snapshotAdded := func(obj any) {
20422034
snap, ok := obj.(*snapshotv1.VolumeSnapshot)

0 commit comments

Comments
 (0)