Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
34747474
Commit
34747474
authored
Sep 04, 2017
by
Sergey Lanzman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move regexp.MustCompile to global variable
parent
0eb999c2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
20 deletions
+25
-20
set_env.go
pkg/kubectl/cmd/set/set_env.go
+2
-2
nvidia_gpu_manager.go
pkg/kubelet/gpu/nvidia/nvidia_gpu_manager.go
+7
-5
iscsi_util.go
pkg/volume/iscsi/iscsi_util.go
+4
-6
rbd_util.go
pkg/volume/rbd/rbd_util.go
+5
-2
parser.go
staging/src/k8s.io/client-go/util/jsonpath/parser.go
+7
-5
No files found.
pkg/kubectl/cmd/set/set_env.go
View file @
34747474
...
@@ -39,7 +39,8 @@ import (
...
@@ -39,7 +39,8 @@ import (
)
)
var
(
var
(
envResources
=
`
validEnvNameRegexp
=
regexp
.
MustCompile
(
"[^a-zA-Z0-9_]"
)
envResources
=
`
pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs)`
pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs)`
envLong
=
templates
.
LongDesc
(
`
envLong
=
templates
.
LongDesc
(
`
...
@@ -172,7 +173,6 @@ func validateNoOverwrites(existing []v1.EnvVar, env []v1.EnvVar) error {
...
@@ -172,7 +173,6 @@ func validateNoOverwrites(existing []v1.EnvVar, env []v1.EnvVar) error {
}
}
func
keyToEnvName
(
key
string
)
string
{
func
keyToEnvName
(
key
string
)
string
{
validEnvNameRegexp
:=
regexp
.
MustCompile
(
"[^a-zA-Z0-9_]"
)
return
strings
.
ToUpper
(
validEnvNameRegexp
.
ReplaceAllString
(
key
,
"_"
))
return
strings
.
ToUpper
(
validEnvNameRegexp
.
ReplaceAllString
(
key
,
"_"
))
}
}
...
...
pkg/kubelet/gpu/nvidia/nvidia_gpu_manager.go
View file @
34747474
...
@@ -44,8 +44,11 @@ const (
...
@@ -44,8 +44,11 @@ const (
// Optional device.
// Optional device.
nvidiaUVMToolsDevice
string
=
"/dev/nvidia-uvm-tools"
nvidiaUVMToolsDevice
string
=
"/dev/nvidia-uvm-tools"
devDirectory
=
"/dev"
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
{
type
activePodsLister
interface
{
...
@@ -194,7 +197,6 @@ func (ngm *nvidiaGPUManager) updateAllocatedGPUs() {
...
@@ -194,7 +197,6 @@ func (ngm *nvidiaGPUManager) updateAllocatedGPUs() {
// we want more features, features like schedule containers according to GPU family
// we want more features, features like schedule containers according to GPU family
// name.
// name.
func
(
ngm
*
nvidiaGPUManager
)
discoverGPUs
()
error
{
func
(
ngm
*
nvidiaGPUManager
)
discoverGPUs
()
error
{
reg
:=
regexp
.
MustCompile
(
nvidiaDeviceRE
)
files
,
err
:=
ioutil
.
ReadDir
(
devDirectory
)
files
,
err
:=
ioutil
.
ReadDir
(
devDirectory
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -203,7 +205,7 @@ func (ngm *nvidiaGPUManager) discoverGPUs() error {
...
@@ -203,7 +205,7 @@ func (ngm *nvidiaGPUManager) discoverGPUs() error {
if
f
.
IsDir
()
{
if
f
.
IsDir
()
{
continue
continue
}
}
if
reg
.
MatchString
(
f
.
Name
())
{
if
nvidiaDeviceRE
.
MatchString
(
f
.
Name
())
{
glog
.
V
(
2
)
.
Infof
(
"Found Nvidia GPU %q"
,
f
.
Name
())
glog
.
V
(
2
)
.
Infof
(
"Found Nvidia GPU %q"
,
f
.
Name
())
ngm
.
allGPUs
.
Insert
(
path
.
Join
(
devDirectory
,
f
.
Name
()))
ngm
.
allGPUs
.
Insert
(
path
.
Join
(
devDirectory
,
f
.
Name
()))
}
}
...
@@ -274,5 +276,5 @@ func (ngm *nvidiaGPUManager) gpusInUse() *podGPUs {
...
@@ -274,5 +276,5 @@ func (ngm *nvidiaGPUManager) gpusInUse() *podGPUs {
}
}
func
isValidPath
(
path
string
)
bool
{
func
isValidPath
(
path
string
)
bool
{
return
regexp
.
MustCompile
(
nvidiaFullpathRE
)
.
MatchString
(
path
)
return
nvidiaFullpathRE
.
MatchString
(
path
)
}
}
pkg/volume/iscsi/iscsi_util.go
View file @
34747474
...
@@ -43,6 +43,8 @@ var (
...
@@ -43,6 +43,8 @@ var (
"node.session.auth.password"
,
"node.session.auth.password"
,
"node.session.auth.username_in"
,
"node.session.auth.username_in"
,
"node.session.auth.password_in"
}
"node.session.auth.password_in"
}
ifaceTransportNameRe
=
regexp
.
MustCompile
(
`iface.transport_name = (.*)\n`
)
ifaceRe
=
regexp
.
MustCompile
(
`.+/iface-([^/]+)/.+`
)
)
)
func
updateISCSIDiscoverydb
(
b
iscsiDiskMounter
,
tp
string
)
error
{
func
updateISCSIDiscoverydb
(
b
iscsiDiskMounter
,
tp
string
)
error
{
...
@@ -429,9 +431,7 @@ func (util *ISCSIUtil) DetachDisk(c iscsiDiskUnmounter, mntPath string) error {
...
@@ -429,9 +431,7 @@ func (util *ISCSIUtil) DetachDisk(c iscsiDiskUnmounter, mntPath string) error {
}
}
func
extractTransportname
(
ifaceOutput
string
)
(
iscsiTransport
string
)
{
func
extractTransportname
(
ifaceOutput
string
)
(
iscsiTransport
string
)
{
re
:=
regexp
.
MustCompile
(
`iface.transport_name = (.*)\n`
)
rexOutput
:=
ifaceTransportNameRe
.
FindStringSubmatch
(
ifaceOutput
)
rexOutput
:=
re
.
FindStringSubmatch
(
ifaceOutput
)
if
rexOutput
==
nil
{
if
rexOutput
==
nil
{
return
""
return
""
}
}
...
@@ -460,9 +460,7 @@ func extractDeviceAndPrefix(mntPath string) (string, string, error) {
...
@@ -460,9 +460,7 @@ func extractDeviceAndPrefix(mntPath string) (string, string, error) {
}
}
func
extractIface
(
mntPath
string
)
(
string
,
bool
)
{
func
extractIface
(
mntPath
string
)
(
string
,
bool
)
{
re
:=
regexp
.
MustCompile
(
`.+/iface-([^/]+)/.+`
)
reOutput
:=
ifaceRe
.
FindStringSubmatch
(
mntPath
)
reOutput
:=
re
.
FindStringSubmatch
(
mntPath
)
if
reOutput
!=
nil
{
if
reOutput
!=
nil
{
return
reOutput
[
1
],
true
return
reOutput
[
1
],
true
}
}
...
...
pkg/volume/rbd/rbd_util.go
View file @
34747474
...
@@ -46,6 +46,10 @@ const (
...
@@ -46,6 +46,10 @@ const (
rbdCmdErr
=
"executable file not found in $PATH"
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
// search /sys/bus for rbd device that matches given pool and image
func
getDevFromImageAndPool
(
pool
,
image
string
)
(
string
,
bool
)
{
func
getDevFromImageAndPool
(
pool
,
image
string
)
(
string
,
bool
)
{
// /sys/bus/rbd/devices/X/name and /sys/bus/rbd/devices/X/pool
// /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 {
...
@@ -183,8 +187,7 @@ func (util *RBDUtil) rbdLock(b rbdMounter, lock bool) error {
}
}
// best effort clean up orphaned locked if not used
// best effort clean up orphaned locked if not used
re
:=
regexp
.
MustCompile
(
"client.* "
+
kubeLockMagic
+
".*"
)
locks
:=
clientKubeLockMagicRe
.
FindAllStringSubmatch
(
output
,
-
1
)
locks
:=
re
.
FindAllStringSubmatch
(
output
,
-
1
)
for
_
,
v
:=
range
locks
{
for
_
,
v
:=
range
locks
{
if
len
(
v
)
>
0
{
if
len
(
v
)
>
0
{
lockInfo
:=
strings
.
Split
(
v
[
0
],
" "
)
lockInfo
:=
strings
.
Split
(
v
[
0
],
" "
)
...
...
staging/src/k8s.io/client-go/util/jsonpath/parser.go
View file @
34747474
...
@@ -43,7 +43,11 @@ type Parser struct {
...
@@ -43,7 +43,11 @@ type Parser struct {
width
int
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.
// Parse parsed the given text and return a node Parser.
// If an error is encountered, parsing stops and an empty
// If an error is encountered, parsing stops and an empty
...
@@ -283,8 +287,7 @@ Loop:
...
@@ -283,8 +287,7 @@ Loop:
}
}
// dict key
// dict key
reg
:=
regexp
.
MustCompile
(
`^'([^']*)'$`
)
value
:=
dictKeyRex
.
FindStringSubmatch
(
text
)
value
:=
reg
.
FindStringSubmatch
(
text
)
if
value
!=
nil
{
if
value
!=
nil
{
parser
,
err
:=
parseAction
(
"arraydict"
,
fmt
.
Sprintf
(
".%s"
,
value
[
1
]))
parser
,
err
:=
parseAction
(
"arraydict"
,
fmt
.
Sprintf
(
".%s"
,
value
[
1
]))
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -297,8 +300,7 @@ Loop:
...
@@ -297,8 +300,7 @@ Loop:
}
}
//slice operator
//slice operator
reg
=
regexp
.
MustCompile
(
`^(-?[\d]*)(:-?[\d]*)?(:[\d]*)?$`
)
value
=
sliceOperatorRex
.
FindStringSubmatch
(
text
)
value
=
reg
.
FindStringSubmatch
(
text
)
if
value
==
nil
{
if
value
==
nil
{
return
fmt
.
Errorf
(
"invalid array index %s"
,
text
)
return
fmt
.
Errorf
(
"invalid array index %s"
,
text
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment