mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-20 01:23:48 +00:00
simplify regexp with raw string
This commit is contained in:
@@ -573,6 +573,8 @@ func makeFullArgs(table Table, chain Chain, args ...string) []string {
|
||||
return append([]string{string(chain), "-t", string(table)}, args...)
|
||||
}
|
||||
|
||||
const iptablesVersionPattern = `v([0-9]+(\.[0-9]+)+)`
|
||||
|
||||
// getIPTablesVersion runs "iptables --version" and parses the returned version
|
||||
func getIPTablesVersion(exec utilexec.Interface, protocol Protocol) (*utilversion.Version, error) {
|
||||
// this doesn't access mutable state so we don't need to use the interface / runner
|
||||
@@ -581,7 +583,7 @@ func getIPTablesVersion(exec utilexec.Interface, protocol Protocol) (*utilversio
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
versionMatcher := regexp.MustCompile("v([0-9]+(\\.[0-9]+)+)")
|
||||
versionMatcher := regexp.MustCompile(iptablesVersionPattern)
|
||||
match := versionMatcher.FindStringSubmatch(string(bytes))
|
||||
if match == nil {
|
||||
return nil, fmt.Errorf("no iptables version found in string: %s", bytes)
|
||||
@@ -641,7 +643,7 @@ func getIPTablesRestoreVersionString(exec utilexec.Interface, protocol Protocol)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
versionMatcher := regexp.MustCompile("v([0-9]+(\\.[0-9]+)+)")
|
||||
versionMatcher := regexp.MustCompile(iptablesVersionPattern)
|
||||
match := versionMatcher.FindStringSubmatch(string(bytes))
|
||||
if match == nil {
|
||||
return "", fmt.Errorf("no iptables version found in string: %s", bytes)
|
||||
|
Reference in New Issue
Block a user