mirror of https://github.com/k3s-io/k3s
Merge pull request #51914 from sergeylanzman/master
Automatic merge from submit-queue (batch tested with PRs 55392, 55491, 51914, 55831, 55836). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Move regexp.MustCompile to global variable Move regexp.MustCompile to global variable. regexp.MustCompile heavy function and can be run on init app ```release-note NONE ```pull/6/head
commit
79c2274566
|
@ -39,7 +39,8 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
envResources = `
|
||||
validEnvNameRegexp = regexp.MustCompile("[^a-zA-Z0-9_]")
|
||||
envResources = `
|
||||
pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs)`
|
||||
|
||||
envLong = templates.LongDesc(`
|
||||
|
@ -172,7 +173,6 @@ func validateNoOverwrites(existing []v1.EnvVar, env []v1.EnvVar) error {
|
|||
}
|
||||
|
||||
func keyToEnvName(key string) string {
|
||||
validEnvNameRegexp := regexp.MustCompile("[^a-zA-Z0-9_]")
|
||||
return strings.ToUpper(validEnvNameRegexp.ReplaceAllString(key, "_"))
|
||||
}
|
||||
|
||||
|
|
|
@ -44,8 +44,11 @@ const (
|
|||
// Optional device.
|
||||
nvidiaUVMToolsDevice string = "/dev/nvidia-uvm-tools"
|
||||
devDirectory = "/dev"
|
||||
nvidiaDeviceRE = `^nvidia[0-9]*$`
|
||||
nvidiaFullpathRE = `^/dev/nvidia[0-9]*$`
|
||||
)
|
||||
|
||||
var (
|
||||
nvidiaDeviceRE = regexp.MustCompile(`^nvidia[0-9]*$`)
|
||||
nvidiaFullpathRE = regexp.MustCompile(`^/dev/nvidia[0-9]*$`)
|
||||
)
|
||||
|
||||
type activePodsLister interface {
|
||||
|
@ -194,7 +197,6 @@ func (ngm *nvidiaGPUManager) updateAllocatedGPUs() {
|
|||
// we want more features, features like schedule containers according to GPU family
|
||||
// name.
|
||||
func (ngm *nvidiaGPUManager) discoverGPUs() error {
|
||||
reg := regexp.MustCompile(nvidiaDeviceRE)
|
||||
files, err := ioutil.ReadDir(devDirectory)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -203,7 +205,7 @@ func (ngm *nvidiaGPUManager) discoverGPUs() error {
|
|||
if f.IsDir() {
|
||||
continue
|
||||
}
|
||||
if reg.MatchString(f.Name()) {
|
||||
if nvidiaDeviceRE.MatchString(f.Name()) {
|
||||
glog.V(2).Infof("Found Nvidia GPU %q", f.Name())
|
||||
ngm.allGPUs.Insert(path.Join(devDirectory, f.Name()))
|
||||
}
|
||||
|
@ -274,5 +276,5 @@ func (ngm *nvidiaGPUManager) gpusInUse() *podGPUs {
|
|||
}
|
||||
|
||||
func isValidPath(path string) bool {
|
||||
return regexp.MustCompile(nvidiaFullpathRE).MatchString(path)
|
||||
return nvidiaFullpathRE.MatchString(path)
|
||||
}
|
||||
|
|
|
@ -43,6 +43,8 @@ var (
|
|||
"node.session.auth.password",
|
||||
"node.session.auth.username_in",
|
||||
"node.session.auth.password_in"}
|
||||
ifaceTransportNameRe = regexp.MustCompile(`iface.transport_name = (.*)\n`)
|
||||
ifaceRe = regexp.MustCompile(`.+/iface-([^/]+)/.+`)
|
||||
)
|
||||
|
||||
func updateISCSIDiscoverydb(b iscsiDiskMounter, tp string) error {
|
||||
|
@ -429,9 +431,7 @@ func (util *ISCSIUtil) DetachDisk(c iscsiDiskUnmounter, mntPath string) error {
|
|||
}
|
||||
|
||||
func extractTransportname(ifaceOutput string) (iscsiTransport string) {
|
||||
re := regexp.MustCompile(`iface.transport_name = (.*)\n`)
|
||||
|
||||
rexOutput := re.FindStringSubmatch(ifaceOutput)
|
||||
rexOutput := ifaceTransportNameRe.FindStringSubmatch(ifaceOutput)
|
||||
if rexOutput == nil {
|
||||
return ""
|
||||
}
|
||||
|
@ -460,9 +460,7 @@ func extractDeviceAndPrefix(mntPath string) (string, string, error) {
|
|||
}
|
||||
|
||||
func extractIface(mntPath string) (string, bool) {
|
||||
re := regexp.MustCompile(`.+/iface-([^/]+)/.+`)
|
||||
|
||||
reOutput := re.FindStringSubmatch(mntPath)
|
||||
reOutput := ifaceRe.FindStringSubmatch(mntPath)
|
||||
if reOutput != nil {
|
||||
return reOutput[1], true
|
||||
}
|
||||
|
|
|
@ -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], " ")
|
||||
|
|
|
@ -43,7 +43,11 @@ type Parser struct {
|
|||
width int
|
||||
}
|
||||
|
||||
var ErrSyntax = errors.New("invalid syntax")
|
||||
var (
|
||||
ErrSyntax = errors.New("invalid syntax")
|
||||
dictKeyRex = regexp.MustCompile(`^'([^']*)'$`)
|
||||
sliceOperatorRex = regexp.MustCompile(`^(-?[\d]*)(:-?[\d]*)?(:[\d]*)?$`)
|
||||
)
|
||||
|
||||
// Parse parsed the given text and return a node Parser.
|
||||
// If an error is encountered, parsing stops and an empty
|
||||
|
@ -283,8 +287,7 @@ Loop:
|
|||
}
|
||||
|
||||
// dict key
|
||||
reg := regexp.MustCompile(`^'([^']*)'$`)
|
||||
value := reg.FindStringSubmatch(text)
|
||||
value := dictKeyRex.FindStringSubmatch(text)
|
||||
if value != nil {
|
||||
parser, err := parseAction("arraydict", fmt.Sprintf(".%s", value[1]))
|
||||
if err != nil {
|
||||
|
@ -297,8 +300,7 @@ Loop:
|
|||
}
|
||||
|
||||
//slice operator
|
||||
reg = regexp.MustCompile(`^(-?[\d]*)(:-?[\d]*)?(:[\d]*)?$`)
|
||||
value = reg.FindStringSubmatch(text)
|
||||
value = sliceOperatorRex.FindStringSubmatch(text)
|
||||
if value == nil {
|
||||
return fmt.Errorf("invalid array index %s", text)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue