mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 18:00:08 +00:00
proxy/ipvs: Remove kernel module tests
To check kernel modules is a bad way to check functionality. This commit just removes the checks and makes it possible to use a statically linked kernel. Minimal updates to unit-tests are made.
This commit is contained in:
parent
2bb77a13b1
commit
4f02671b23
@ -720,53 +720,8 @@ func (handle *LinuxKernelHandler) GetKernelVersion() (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CanUseIPVSProxier checks if we can use the ipvs Proxier.
|
// CanUseIPVSProxier checks if we can use the ipvs Proxier.
|
||||||
// This is determined by checking if all the required kernel modules can be loaded. It may
|
// Only the ipset version is checked. Necessary kernel functions are assumed to be present.
|
||||||
// return an error if it fails to get the kernel modules information without error, in which
|
|
||||||
// case it will also return false.
|
|
||||||
func CanUseIPVSProxier(handle KernelHandler, ipsetver IPSetVersioner, scheduler string) error {
|
func CanUseIPVSProxier(handle KernelHandler, ipsetver IPSetVersioner, scheduler string) error {
|
||||||
mods, err := handle.GetModules()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error getting installed ipvs required kernel modules: %v", err)
|
|
||||||
}
|
|
||||||
loadModules := sets.NewString()
|
|
||||||
loadModules.Insert(mods...)
|
|
||||||
|
|
||||||
kernelVersionStr, err := handle.GetKernelVersion()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error determining kernel version to find required kernel modules for ipvs support: %v", err)
|
|
||||||
}
|
|
||||||
kernelVersion, err := version.ParseGeneric(kernelVersionStr)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error parsing kernel version %q: %v", kernelVersionStr, err)
|
|
||||||
}
|
|
||||||
mods = utilipvs.GetRequiredIPVSModules(kernelVersion)
|
|
||||||
wantModules := sets.NewString()
|
|
||||||
// We check for the existence of the scheduler mod and will trigger a missingMods error if not found
|
|
||||||
if scheduler == "" {
|
|
||||||
scheduler = defaultScheduler
|
|
||||||
}
|
|
||||||
schedulerMod := "ip_vs_" + scheduler
|
|
||||||
mods = append(mods, schedulerMod)
|
|
||||||
wantModules.Insert(mods...)
|
|
||||||
|
|
||||||
modules := wantModules.Difference(loadModules).UnsortedList()
|
|
||||||
var missingMods []string
|
|
||||||
ConntrackiMissingCounter := 0
|
|
||||||
for _, mod := range modules {
|
|
||||||
if strings.Contains(mod, "nf_conntrack") {
|
|
||||||
ConntrackiMissingCounter++
|
|
||||||
} else {
|
|
||||||
missingMods = append(missingMods, mod)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ConntrackiMissingCounter == 2 {
|
|
||||||
missingMods = append(missingMods, "nf_conntrack_ipv4(or nf_conntrack for Linux kernel 4.19 and later)")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(missingMods) != 0 {
|
|
||||||
return fmt.Errorf("IPVS proxier will not be used because the following required kernel modules are not loaded: %v", missingMods)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check ipset version
|
// Check ipset version
|
||||||
versionString, err := ipsetver.GetVersion()
|
versionString, err := ipsetver.GetVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -307,14 +307,6 @@ func TestCanUseIPVSProxier(t *testing.T) {
|
|||||||
ipsetVersion: "1.1",
|
ipsetVersion: "1.1",
|
||||||
ok: false,
|
ok: false,
|
||||||
},
|
},
|
||||||
// case 3, missing required ip_vs_* kernel modules
|
|
||||||
{
|
|
||||||
mods: []string{"ip_vs", "a", "bc", "def"},
|
|
||||||
scheduler: "sed",
|
|
||||||
kernelVersion: "4.19",
|
|
||||||
ipsetVersion: MinIPSetCheckVersion,
|
|
||||||
ok: false,
|
|
||||||
},
|
|
||||||
// case 4, ipset version too low
|
// case 4, ipset version too low
|
||||||
{
|
{
|
||||||
mods: []string{"ip_vs", "ip_vs_rr", "ip_vs_wrr", "ip_vs_sh", "nf_conntrack"},
|
mods: []string{"ip_vs", "ip_vs_rr", "ip_vs_wrr", "ip_vs_sh", "nf_conntrack"},
|
||||||
@ -347,14 +339,6 @@ func TestCanUseIPVSProxier(t *testing.T) {
|
|||||||
ipsetVersion: "6.19",
|
ipsetVersion: "6.19",
|
||||||
ok: true,
|
ok: true,
|
||||||
},
|
},
|
||||||
// case 8, not ok for sed based IPVS scheduling
|
|
||||||
{
|
|
||||||
mods: []string{"ip_vs", "ip_vs_rr", "ip_vs_wrr", "ip_vs_sh", "nf_conntrack"},
|
|
||||||
scheduler: "sed",
|
|
||||||
kernelVersion: "4.19",
|
|
||||||
ipsetVersion: MinIPSetCheckVersion,
|
|
||||||
ok: false,
|
|
||||||
},
|
|
||||||
// case 9, ok for dh based IPVS scheduling
|
// case 9, ok for dh based IPVS scheduling
|
||||||
{
|
{
|
||||||
mods: []string{"ip_vs", "ip_vs_rr", "ip_vs_wrr", "ip_vs_sh", "nf_conntrack", "ip_vs_dh"},
|
mods: []string{"ip_vs", "ip_vs_rr", "ip_vs_wrr", "ip_vs_sh", "nf_conntrack", "ip_vs_dh"},
|
||||||
@ -363,14 +347,6 @@ func TestCanUseIPVSProxier(t *testing.T) {
|
|||||||
ipsetVersion: MinIPSetCheckVersion,
|
ipsetVersion: MinIPSetCheckVersion,
|
||||||
ok: true,
|
ok: true,
|
||||||
},
|
},
|
||||||
// case 10, non-existent scheduler, error due to modules not existing
|
|
||||||
{
|
|
||||||
mods: []string{"ip_vs", "ip_vs_rr", "ip_vs_wrr", "ip_vs_sh", "nf_conntrack", "ip_vs_dh"},
|
|
||||||
scheduler: "foobar",
|
|
||||||
kernelVersion: "4.19",
|
|
||||||
ipsetVersion: MinIPSetCheckVersion,
|
|
||||||
ok: false,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range testCases {
|
for i := range testCases {
|
||||||
|
Loading…
Reference in New Issue
Block a user