mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 02:41:25 +00:00
Merge pull request #112241 from xiaoliwang/simplified_regexp
Optimize: simplified regexp
This commit is contained in:
commit
cae4c036c8
@ -70,7 +70,7 @@ func TestGetDataFromInitConfig(t *testing.T) {
|
|||||||
t.Fatalf("failed to get secret data. fatal error: %v", err)
|
t.Fatalf("failed to get secret data. fatal error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
re := regexp.MustCompile(`[-._a-zA-Z0-9]+`)
|
re := regexp.MustCompile(`[-.\w]+`)
|
||||||
for name, data := range secretData {
|
for name, data := range secretData {
|
||||||
if !re.MatchString(name) {
|
if !re.MatchString(name) {
|
||||||
t.Fatalf(dedent.Dedent("failed to validate secretData\n %s isn't a valid secret key"), name)
|
t.Fatalf(dedent.Dedent("failed to validate secretData\n %s isn't a valid secret key"), name)
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
|
|
||||||
// GetKubeletVersion is helper function that returns version of kubelet available in $PATH
|
// GetKubeletVersion is helper function that returns version of kubelet available in $PATH
|
||||||
func GetKubeletVersion(execer utilsexec.Interface) (*version.Version, error) {
|
func GetKubeletVersion(execer utilsexec.Interface) (*version.Version, error) {
|
||||||
kubeletVersionRegex := regexp.MustCompile(`^\s*Kubernetes v((0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)([-0-9a-zA-Z_\.+]*)?)\s*$`)
|
kubeletVersionRegex := regexp.MustCompile(`^\s*Kubernetes v((0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)([-\w.+]*)?)\s*$`)
|
||||||
|
|
||||||
command := execer.Command("kubelet", "--version")
|
command := execer.Command("kubelet", "--version")
|
||||||
out, err := command.Output()
|
out, err := command.Output()
|
||||||
|
@ -25,7 +25,7 @@ var (
|
|||||||
// (if present). All the parts before the tag we match in a single match everything (but not greedy) group.
|
// (if present). All the parts before the tag we match in a single match everything (but not greedy) group.
|
||||||
// All matched sub-groups, except the tag one, get thrown away. Hence, in a result of FindStringSubmatch, if a tag
|
// All matched sub-groups, except the tag one, get thrown away. Hence, in a result of FindStringSubmatch, if a tag
|
||||||
// matches, it's going to be the second returned element (after the full match).
|
// matches, it's going to be the second returned element (after the full match).
|
||||||
tagMatcher = regexp.MustCompile(`^(?U:.*)(?::([[:word:]][[:word:].-]*))?(?:@sha256:[a-fA-F0-9]{64})?$`)
|
tagMatcher = regexp.MustCompile(`^(?U:.*)(?::([[:word:]][[:word:].-]*))?(?:@sha256:[a-fA-F\d]{64})?$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// TagFromImage extracts a tag from image. An empty string is returned if no tag is discovered.
|
// TagFromImage extracts a tag from image. An empty string is returned if no tag is discovered.
|
||||||
|
@ -48,7 +48,7 @@ func Reset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
testFunction = regexp.MustCompile(`.*\.Test[^./]+(.func[0-9]*)?$`)
|
testFunction = regexp.MustCompile(`.*\.Test[^./]+(.func\d*)?$`)
|
||||||
|
|
||||||
lock = sync.Mutex{}
|
lock = sync.Mutex{}
|
||||||
fixtureDir = ""
|
fixtureDir = ""
|
||||||
|
@ -41,9 +41,9 @@ const (
|
|||||||
var (
|
var (
|
||||||
kubeReleaseBucketURL = "https://dl.k8s.io"
|
kubeReleaseBucketURL = "https://dl.k8s.io"
|
||||||
kubeCIBucketURL = "https://storage.googleapis.com/k8s-release-dev"
|
kubeCIBucketURL = "https://storage.googleapis.com/k8s-release-dev"
|
||||||
kubeReleaseRegex = regexp.MustCompile(`^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)([-0-9a-zA-Z_\.+]*)?$`)
|
kubeReleaseRegex = regexp.MustCompile(`^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)([-\w.+]*)?$`)
|
||||||
kubeReleaseLabelRegex = regexp.MustCompile(`^((latest|stable)+(-[1-9](\.[1-9]([0-9])?)?)?)\z`)
|
kubeReleaseLabelRegex = regexp.MustCompile(`^((latest|stable)+(-[1-9](\.[1-9](\d)?)?)?)\z`)
|
||||||
kubeBucketPrefixes = regexp.MustCompile(`^((release|ci)/)?([-\w_\.+]+)$`)
|
kubeBucketPrefixes = regexp.MustCompile(`^((release|ci)/)?([-\w.+]+)$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// KubernetesReleaseVersion is helper function that can fetch
|
// KubernetesReleaseVersion is helper function that can fetch
|
||||||
@ -135,7 +135,7 @@ func kubernetesReleaseVersion(version string, fetcher func(string, time.Duration
|
|||||||
// Current usage is for CI images where all of symbols except '+' are valid,
|
// Current usage is for CI images where all of symbols except '+' are valid,
|
||||||
// but function is for generic usage where input can't be always pre-validated.
|
// but function is for generic usage where input can't be always pre-validated.
|
||||||
func KubernetesVersionToImageTag(version string) string {
|
func KubernetesVersionToImageTag(version string) string {
|
||||||
allowed := regexp.MustCompile(`[^-a-zA-Z0-9_\.]`)
|
allowed := regexp.MustCompile(`[^-\w.]`)
|
||||||
return allowed.ReplaceAllString(version, "_")
|
return allowed.ReplaceAllString(version, "_")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user