mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Drop the "v" from GetIptablesVersionString() output
Neither of its callers wants it
This commit is contained in:
parent
97a2cbc6ef
commit
a41e422600
@ -74,13 +74,12 @@ func ShouldUseIptablesProxier() (bool, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
// returns "vX.X.X", err
|
// returns "X.X.X", err
|
||||||
versionString, err := utiliptables.GetIptablesVersionString(exec)
|
versionString, err := utiliptables.GetIptablesVersionString(exec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
// make a semver of the part after the v in "vX.X.X"
|
version, err := semver.NewVersion(versionString)
|
||||||
version, err := semver.NewVersion(versionString[1:])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -404,13 +404,11 @@ func getIptablesHasCheckCommand(exec utilexec.Interface) (bool, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
// Returns "vX.Y.Z".
|
|
||||||
vstring, err := GetIptablesVersionString(exec)
|
vstring, err := GetIptablesVersionString(exec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
// Make a semver of the part after the v in "vX.X.X".
|
version, err := semver.NewVersion(vstring)
|
||||||
version, err := semver.NewVersion(vstring[1:])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -420,19 +418,18 @@ func getIptablesHasCheckCommand(exec utilexec.Interface) (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetIptablesVersionString runs "iptables --version" to get the version string,
|
// GetIptablesVersionString runs "iptables --version" to get the version string
|
||||||
// then matches for vX.X.X e.g. if "iptables --version" outputs: "iptables v1.3.66"
|
// in the form "X.X.X"
|
||||||
// then it would would return "v1.3.66", nil
|
|
||||||
func GetIptablesVersionString(exec utilexec.Interface) (string, error) {
|
func GetIptablesVersionString(exec utilexec.Interface) (string, error) {
|
||||||
// this doesn't access mutable state so we don't need to use the interface / runner
|
// this doesn't access mutable state so we don't need to use the interface / runner
|
||||||
bytes, err := exec.Command(cmdIptables, "--version").CombinedOutput()
|
bytes, err := exec.Command(cmdIptables, "--version").CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
versionMatcher := regexp.MustCompile("v[0-9]+\\.[0-9]+\\.[0-9]+")
|
versionMatcher := regexp.MustCompile("v([0-9]+\\.[0-9]+\\.[0-9]+)")
|
||||||
match := versionMatcher.FindStringSubmatch(string(bytes))
|
match := versionMatcher.FindStringSubmatch(string(bytes))
|
||||||
if match == nil {
|
if match == nil {
|
||||||
return "", fmt.Errorf("no iptables version found in string: %s", bytes)
|
return "", fmt.Errorf("no iptables version found in string: %s", bytes)
|
||||||
}
|
}
|
||||||
return match[0], nil
|
return match[1], nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user