Move regexp.MustCompile to global variable

This commit is contained in:
Sergey Lanzman
2017-09-04 22:56:06 +03:00
parent 0eb999c26a
commit 3474747465
5 changed files with 25 additions and 20 deletions

View File

@@ -46,6 +46,10 @@ const (
rbdCmdErr = "executable file not found in $PATH"
)
var (
clientKubeLockMagicRe = regexp.MustCompile("client.* " + kubeLockMagic + ".*")
)
// search /sys/bus for rbd device that matches given pool and image
func getDevFromImageAndPool(pool, image string) (string, bool) {
// /sys/bus/rbd/devices/X/name and /sys/bus/rbd/devices/X/pool
@@ -183,8 +187,7 @@ func (util *RBDUtil) rbdLock(b rbdMounter, lock bool) error {
}
// best effort clean up orphaned locked if not used
re := regexp.MustCompile("client.* " + kubeLockMagic + ".*")
locks := re.FindAllStringSubmatch(output, -1)
locks := clientKubeLockMagicRe.FindAllStringSubmatch(output, -1)
for _, v := range locks {
if len(v) > 0 {
lockInfo := strings.Split(v[0], " ")