mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
Merge pull request #56529 from gkudra-msft/master
Automatic merge from submit-queue (batch tested with PRs 56529, 57054). 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>. Updates Kubeproxy validators to allow Windows 'kernelspace' mode. **What this PR does / why we need it**: Allows necessary `--proxy-mode` parameter in Kubeproxy, so that it can proceed as usual on Windows. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #56522 ```release-note NONE ```
This commit is contained in:
commit
a54c5fdb14
@ -152,17 +152,20 @@ type KubeProxyConfiguration struct {
|
|||||||
ConfigSyncPeriod metav1.Duration
|
ConfigSyncPeriod metav1.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// Currently two modes of proxying are available: 'userspace' (older, stable) or 'iptables'
|
// Currently, four modes of proxying are available total: 'userspace' (older, stable), 'iptables'
|
||||||
// (newer, faster). If blank, use the best-available proxy (currently iptables, but may
|
// (newer, faster), 'ipvs', and 'kernelspace' (Windows only, newer).
|
||||||
// change in future versions). If the iptables proxy is selected, regardless of how, but
|
//
|
||||||
// the system's kernel or iptables versions are insufficient, this always falls back to the
|
// If blank, use the best-available proxy (currently iptables, but may change in
|
||||||
// userspace proxy.
|
// future versions). If the iptables proxy is selected, regardless of how, but
|
||||||
|
// the system's kernel or iptables versions are insufficient, this always falls
|
||||||
|
// back to the userspace proxy.
|
||||||
type ProxyMode string
|
type ProxyMode string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ProxyModeUserspace ProxyMode = "userspace"
|
ProxyModeUserspace ProxyMode = "userspace"
|
||||||
ProxyModeIPTables ProxyMode = "iptables"
|
ProxyModeIPTables ProxyMode = "iptables"
|
||||||
ProxyModeIPVS ProxyMode = "ipvs"
|
ProxyModeIPVS ProxyMode = "ipvs"
|
||||||
|
ProxyModeKernelspace ProxyMode = "kernelspace"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IPVSSchedulerMethod is the algorithm for allocating TCP connections and
|
// IPVSSchedulerMethod is the algorithm for allocating TCP connections and
|
||||||
|
@ -19,6 +19,7 @@ package validation
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -141,7 +142,16 @@ func validateKubeProxyConntrackConfiguration(config kubeproxyconfig.KubeProxyCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateProxyMode(mode kubeproxyconfig.ProxyMode, fldPath *field.Path) field.ErrorList {
|
func validateProxyMode(mode kubeproxyconfig.ProxyMode, fldPath *field.Path) field.ErrorList {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
return validateProxyModeWindows(mode, fldPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
return validateProxyModeLinux(mode, fldPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateProxyModeLinux(mode kubeproxyconfig.ProxyMode, fldPath *field.Path) field.ErrorList {
|
||||||
allErrs := field.ErrorList{}
|
allErrs := field.ErrorList{}
|
||||||
|
|
||||||
switch mode {
|
switch mode {
|
||||||
case kubeproxyconfig.ProxyModeUserspace:
|
case kubeproxyconfig.ProxyModeUserspace:
|
||||||
case kubeproxyconfig.ProxyModeIPTables:
|
case kubeproxyconfig.ProxyModeIPTables:
|
||||||
@ -149,7 +159,21 @@ func validateProxyMode(mode kubeproxyconfig.ProxyMode, fldPath *field.Path) fiel
|
|||||||
case "":
|
case "":
|
||||||
default:
|
default:
|
||||||
modes := []string{string(kubeproxyconfig.ProxyModeUserspace), string(kubeproxyconfig.ProxyModeIPTables), string(kubeproxyconfig.ProxyModeIPVS)}
|
modes := []string{string(kubeproxyconfig.ProxyModeUserspace), string(kubeproxyconfig.ProxyModeIPTables), string(kubeproxyconfig.ProxyModeIPVS)}
|
||||||
errMsg := fmt.Sprintf("must be %s or blank (blank means the best-available proxy (currently iptables)", strings.Join(modes, ","))
|
errMsg := fmt.Sprintf("must be %s or blank (blank means the best-available proxy [currently iptables])", strings.Join(modes, ","))
|
||||||
|
allErrs = append(allErrs, field.Invalid(fldPath.Child("ProxyMode"), string(mode), errMsg))
|
||||||
|
}
|
||||||
|
return allErrs
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateProxyModeWindows(mode kubeproxyconfig.ProxyMode, fldPath *field.Path) field.ErrorList {
|
||||||
|
allErrs := field.ErrorList{}
|
||||||
|
|
||||||
|
switch mode {
|
||||||
|
case kubeproxyconfig.ProxyModeUserspace:
|
||||||
|
case kubeproxyconfig.ProxyModeKernelspace:
|
||||||
|
default:
|
||||||
|
modes := []string{string(kubeproxyconfig.ProxyModeUserspace), string(kubeproxyconfig.ProxyModeKernelspace)}
|
||||||
|
errMsg := fmt.Sprintf("must be %s or blank (blank means the most-available proxy [currently userspace])", strings.Join(modes, ","))
|
||||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("ProxyMode"), string(mode), errMsg))
|
allErrs = append(allErrs, field.Invalid(fldPath.Child("ProxyMode"), string(mode), errMsg))
|
||||||
}
|
}
|
||||||
return allErrs
|
return allErrs
|
||||||
|
@ -18,6 +18,7 @@ package validation
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -488,11 +489,15 @@ func TestValidateProxyMode(t *testing.T) {
|
|||||||
newPath := field.NewPath("KubeProxyConfiguration")
|
newPath := field.NewPath("KubeProxyConfiguration")
|
||||||
successCases := []kubeproxyconfig.ProxyMode{
|
successCases := []kubeproxyconfig.ProxyMode{
|
||||||
kubeproxyconfig.ProxyModeUserspace,
|
kubeproxyconfig.ProxyModeUserspace,
|
||||||
kubeproxyconfig.ProxyModeIPTables,
|
|
||||||
kubeproxyconfig.ProxyModeIPVS,
|
|
||||||
kubeproxyconfig.ProxyMode(""),
|
kubeproxyconfig.ProxyMode(""),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
successCases = append(successCases, kubeproxyconfig.ProxyModeKernelspace)
|
||||||
|
} else {
|
||||||
|
successCases = append(successCases, kubeproxyconfig.ProxyModeIPTables, kubeproxyconfig.ProxyModeIPVS)
|
||||||
|
}
|
||||||
|
|
||||||
for _, successCase := range successCases {
|
for _, successCase := range successCases {
|
||||||
if errs := validateProxyMode(successCase, newPath.Child("ProxyMode")); len(errs) != 0 {
|
if errs := validateProxyMode(successCase, newPath.Child("ProxyMode")); len(errs) != 0 {
|
||||||
t.Errorf("expected success: %v", errs)
|
t.Errorf("expected success: %v", errs)
|
||||||
@ -505,13 +510,13 @@ func TestValidateProxyMode(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
mode: kubeproxyconfig.ProxyMode("non-existing"),
|
mode: kubeproxyconfig.ProxyMode("non-existing"),
|
||||||
msg: "or blank (blank means the best-available proxy (currently iptables)",
|
msg: "or blank (blank means the",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, errorCase := range errorCases {
|
for _, errorCase := range errorCases {
|
||||||
if errs := validateProxyMode(errorCase.mode, newPath.Child("ProxyMode")); len(errs) == 0 {
|
if errs := validateProxyMode(errorCase.mode, newPath.Child("ProxyMode")); len(errs) == 0 {
|
||||||
t.Errorf("expected failure for %s", errorCase.msg)
|
t.Errorf("expected failure %s for %v", errorCase.msg, errorCase.mode)
|
||||||
} else if !strings.Contains(errs[0].Error(), errorCase.msg) {
|
} else if !strings.Contains(errs[0].Error(), errorCase.msg) {
|
||||||
t.Errorf("unexpected error: %v, expected: %s", errs[0], errorCase.msg)
|
t.Errorf("unexpected error: %v, expected: %s", errs[0], errorCase.msg)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user