Skip to content

Commit 8ab52a0

Browse files
committed
Move partition checking into the inner linkcache type. This makes it
easier to unit test.
1 parent e4acbe2 commit 8ab52a0

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

pkg/linkcache/cache.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,12 @@ func (l *ListingCache) listAndUpdate() error {
9999
continue
100100
}
101101

102-
// TODO(juliankatz): To have certainty this works for all edge cases, we
103-
// need to test this with a manually partitioned disk.
102+
diskByIdPath := filepath.Join(l.dir, entry.Name())
103+
104104
if partitionNameRegex.MatchString(entry.Name()) {
105105
continue
106106
}
107107

108-
diskByIdPath := filepath.Join(l.dir, entry.Name())
109-
110108
// Add the device to the map regardless of successful symlink eval.
111109
// Otherwise, a broken symlink will lead us to remove it from the cache.
112110
visited[diskByIdPath] = struct{}{}
@@ -153,6 +151,14 @@ func newLinkCache() *linkCache {
153151
}
154152

155153
func (d *linkCache) AddOrUpdateDevice(symlink, realPath string) {
154+
// Ignore partitions, which are noise as far as our logging is concerned.
155+
// Expression: -part[0-9]+$
156+
if partitionNameRegex.MatchString(symlink) {
157+
// TODO(juliankatz): To have certainty this works for all edge cases, we
158+
// need to test this with a manually partitioned disk.
159+
return
160+
}
161+
156162
prevEntry, exists := d.devices[symlink]
157163
if !exists || prevEntry.path != realPath {
158164
klog.Infof("Symlink updated for link %s, previous value: %s, new value: %s", symlink, prevEntry.path, realPath)

pkg/linkcache/cache_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@ func TestLinkCache(t *testing.T) {
170170
devices: map[string]linkCacheEntry{},
171171
},
172172
},
173+
{
174+
name: "PartitionIgnored",
175+
setupCache: func(lc *linkCache) {
176+
lc.AddOrUpdateDevice(gcpPersistentDiskPartitionID, devicePathSDA+"1")
177+
lc.AddOrUpdateDevice(gcpPersistentDiskID, devicePathSDA)
178+
lc.AddOrUpdateDevice(gcpPVCID, devicePathSDB)
179+
},
180+
expected: &linkCache{
181+
devices: map[string]linkCacheEntry{
182+
gcpPersistentDiskID: {path: devicePathSDA, brokenSymlink: false},
183+
gcpPVCID: {path: devicePathSDB, brokenSymlink: false},
184+
},
185+
},
186+
},
173187
}
174188

175189
for _, tt := range tests {

0 commit comments

Comments
 (0)