Skip to content

Commit ec9b26b

Browse files
authored
Merge pull request #320 from andyzhangx/namePattern-list
feat: support namePattern as a list
2 parents 195ef85 + 2119da0 commit ec9b26b

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

pkg/common/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const (
8484
// DefaultVolumeMode is the default volume mode of created PV object.
8585
DefaultVolumeMode = "Filesystem"
8686

87-
// DefaultNamePattern is the default name pattern of in PV discovery.
87+
// DefaultNamePattern is the default name pattern list (separated by comma) of in PV discovery.
8888
DefaultNamePattern = "*"
8989
)
9090

pkg/common/common_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func TestLoadProvisionerConfigs(t *testing.T) {
109109
- "2"
110110
volumeMode: Filesystem
111111
fsType: ext4
112-
namePattern: nvm*
112+
namePattern: nvm*,sdb*
113113
`,
114114
"useAlphaAPI": "true",
115115
"minResyncPeriod": "1h30m",
@@ -122,7 +122,7 @@ func TestLoadProvisionerConfigs(t *testing.T) {
122122
BlockCleanerCommand: []string{"/scripts/shred.sh", "2"},
123123
VolumeMode: "Filesystem",
124124
FsType: "ext4",
125-
NamePattern: "nvm*",
125+
NamePattern: "nvm*,sdb*",
126126
},
127127
},
128128
UseAlphaAPI: true,

pkg/discovery/discovery.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,19 +276,31 @@ func (d *Discoverer) discoverVolumesAtPath(class string, config common.MountConf
276276
mountPointMap[mp.Path] = empty{}
277277
}
278278

279+
var namePatterns []string
280+
if config.NamePattern != "" {
281+
namePatterns = strings.Split(config.NamePattern, ",")
282+
}
283+
279284
var discoErrors []error
280285
var totalCapacityBlockBytes, totalCapacityFSBytes int64
281286
for _, file := range files {
282-
if config.NamePattern != "" {
283-
matched, err := filepath.Match(config.NamePattern, file)
284-
if err != nil {
285-
return err
286-
}
287-
if !matched {
288-
klog.V(5).Infof("file(%s) under(%s) does not match pattern(%s)", file, config.MountDir, config.NamePattern)
289-
continue
287+
var matched bool
288+
for _, pattern := range namePatterns {
289+
if pattern != "" {
290+
matched, err = filepath.Match(pattern, file)
291+
if err != nil {
292+
return err
293+
}
294+
if matched {
295+
break
296+
}
290297
}
291298
}
299+
if config.NamePattern != "" && !matched {
300+
klog.V(5).Infof("file(%s) under(%s) does not match pattern(%s)", file, config.MountDir, config.NamePattern)
301+
continue
302+
}
303+
292304
startTime := time.Now()
293305
filePath := filepath.Join(config.MountDir, file)
294306
volMode, err := common.GetVolumeMode(d.VolUtil, filePath)

0 commit comments

Comments
 (0)