Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
c0d248ad
Unverified
Commit
c0d248ad
authored
Nov 05, 2018
by
k8s-ci-robot
Committed by
GitHub
Nov 05, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #70398 from islinwb/fix_nf_conntrack
use 'nf_conntrack' instead of 'nf_conntrack_ipv4' for linux kernel >= 4.19
parents
f44a8a4c
7a591ed3
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
63 deletions
+61
-63
proxier.go
pkg/proxy/ipvs/proxier.go
+5
-14
BUILD
pkg/util/ipvs/BUILD
+4
-32
ipvs.go
pkg/util/ipvs/ipvs.go
+46
-8
kernelcheck_linux.go
pkg/util/ipvs/kernelcheck_linux.go
+5
-8
kernelcheck_linux_test.go
pkg/util/ipvs/kernelcheck_linux_test.go
+1
-1
No files found.
pkg/proxy/ipvs/proxier.go
View file @
c0d248ad
...
...
@@ -157,15 +157,6 @@ var ipsetWithIptablesChain = []struct {
{
kubeNodePortLocalSetSCTP
,
string
(
KubeNodePortChain
),
"RETURN"
,
"dst"
,
"sctp"
},
}
var
ipvsModules
=
[]
string
{
"ip_vs"
,
"ip_vs_rr"
,
"ip_vs_wrr"
,
"ip_vs_sh"
,
"nf_conntrack_ipv4"
,
"nf_conntrack"
,
}
// In IPVS proxy mode, the following flags need to be set
const
sysctlRouteLocalnet
=
"net/ipv4/conf/all/route_localnet"
const
sysctlBridgeCallIPTables
=
"net/bridge/bridge-nf-call-iptables"
...
...
@@ -455,14 +446,12 @@ func NewLinuxKernelHandler() *LinuxKernelHandler {
// GetModules returns all installed kernel modules.
func
(
handle
*
LinuxKernelHandler
)
GetModules
()
([]
string
,
error
)
{
// Check whether IPVS required kernel modules are built-in
kernelVersionFile
:=
"/proc/sys/kernel/osrelease"
b
,
err
:=
ioutil
.
ReadFile
(
kernelVersionFile
)
kernelVersion
,
ipvsModules
,
err
:=
utilipvs
.
GetKernelVersionAndIPVSMods
(
handle
.
executor
)
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to read file %s with error %v"
,
kernelVersionFile
,
err
)
return
nil
,
err
}
kernelVersion
:=
strings
.
TrimSpace
(
string
(
b
))
builtinModsFilePath
:=
fmt
.
Sprintf
(
"/lib/modules/%s/modules.builtin"
,
kernelVersion
)
b
,
err
=
ioutil
.
ReadFile
(
builtinModsFilePath
)
b
,
err
:
=
ioutil
.
ReadFile
(
builtinModsFilePath
)
if
err
!=
nil
{
glog
.
Warningf
(
"Failed to read file %s with error %v. You can ignore this message when kube-proxy is running inside container without mounting /lib/modules"
,
builtinModsFilePath
,
err
)
}
...
...
@@ -503,6 +492,8 @@ func CanUseIPVSProxier(handle KernelHandler, ipsetver IPSetVersioner) (bool, err
}
wantModules
:=
sets
.
NewString
()
loadModules
:=
sets
.
NewString
()
linuxKernelHandler
:=
NewLinuxKernelHandler
()
_
,
ipvsModules
,
_
:=
utilipvs
.
GetKernelVersionAndIPVSMods
(
linuxKernelHandler
.
executor
)
wantModules
.
Insert
(
ipvsModules
...
)
loadModules
.
Insert
(
mods
...
)
modules
:=
wantModules
.
Difference
(
loadModules
)
.
UnsortedList
()
...
...
pkg/util/ipvs/BUILD
View file @
c0d248ad
...
...
@@ -34,42 +34,14 @@ go_library(
"kernelcheck_unsupported.go",
],
importpath = "k8s.io/kubernetes/pkg/util/ipvs",
deps = select({
"@io_bazel_rules_go//go/platform:android": [
"//vendor/k8s.io/utils/exec:go_default_library",
],
"@io_bazel_rules_go//go/platform:darwin": [
"//vendor/k8s.io/utils/exec:go_default_library",
],
"@io_bazel_rules_go//go/platform:dragonfly": [
"//vendor/k8s.io/utils/exec:go_default_library",
],
"@io_bazel_rules_go//go/platform:freebsd": [
"//vendor/k8s.io/utils/exec:go_default_library",
],
deps = [
"//staging/src/k8s.io/apimachinery/pkg/util/version:go_default_library",
"//vendor/k8s.io/utils/exec:go_default_library",
] + select({
"@io_bazel_rules_go//go/platform:linux": [
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/github.com/docker/libnetwork/ipvs:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/k8s.io/utils/exec:go_default_library",
],
"@io_bazel_rules_go//go/platform:nacl": [
"//vendor/k8s.io/utils/exec:go_default_library",
],
"@io_bazel_rules_go//go/platform:netbsd": [
"//vendor/k8s.io/utils/exec:go_default_library",
],
"@io_bazel_rules_go//go/platform:openbsd": [
"//vendor/k8s.io/utils/exec:go_default_library",
],
"@io_bazel_rules_go//go/platform:plan9": [
"//vendor/k8s.io/utils/exec:go_default_library",
],
"@io_bazel_rules_go//go/platform:solaris": [
"//vendor/k8s.io/utils/exec:go_default_library",
],
"@io_bazel_rules_go//go/platform:windows": [
"//vendor/k8s.io/utils/exec:go_default_library",
],
"//conditions:default": [],
}),
...
...
pkg/util/ipvs/ipvs.go
View file @
c0d248ad
...
...
@@ -19,6 +19,11 @@ package ipvs
import
(
"net"
"strconv"
"strings"
"fmt"
"k8s.io/apimachinery/pkg/util/version"
"k8s.io/utils/exec"
)
// Interface is an injectable interface for running ipvs commands. Implementations must be goroutine-safe.
...
...
@@ -67,14 +72,21 @@ const (
IPVSProxyMode
=
"ipvs"
)
// Sets of IPVS required kernel modules.
var
ipvsModules
=
[]
string
{
"ip_vs"
,
"ip_vs_rr"
,
"ip_vs_wrr"
,
"ip_vs_sh"
,
"nf_conntrack_ipv4"
,
}
// IPVS required kernel modules.
const
(
// ModIPVS is the kernel module "ip_vs"
ModIPVS
string
=
"ip_vs"
// ModIPVSRR is the kernel module "ip_vs_rr"
ModIPVSRR
string
=
"ip_vs_rr"
// ModIPVSWRR is the kernel module "ip_vs_wrr"
ModIPVSWRR
string
=
"ip_vs_wrr"
// ModIPVSSH is the kernel module "ip_vs_sh"
ModIPVSSH
string
=
"ip_vs_sh"
// ModNfConntrackIPV4 is the module "nf_conntrack_ipv4"
ModNfConntrackIPV4
string
=
"nf_conntrack_ipv4"
// ModNfConntrack is the kernel module "nf_conntrack"
ModNfConntrack
string
=
"nf_conntrack"
)
// Equal check the equality of virtual server.
// We don't use struct == since it doesn't work because of slice.
...
...
@@ -110,3 +122,29 @@ func (rs *RealServer) Equal(other *RealServer) bool {
return
rs
.
Address
.
Equal
(
other
.
Address
)
&&
rs
.
Port
==
other
.
Port
}
// GetKernelVersionAndIPVSMods returns the linux kernel version and the required ipvs modules
func
GetKernelVersionAndIPVSMods
(
Executor
exec
.
Interface
)
(
kernelVersion
string
,
ipvsModules
[]
string
,
err
error
)
{
kernelVersionFile
:=
"/proc/sys/kernel/osrelease"
out
,
err
:=
Executor
.
Command
(
"cut"
,
"-f1"
,
"-d"
,
" "
,
kernelVersionFile
)
.
CombinedOutput
()
if
err
!=
nil
{
return
""
,
nil
,
fmt
.
Errorf
(
"error getting os release kernel version: %v(%s)"
,
err
,
out
)
}
kernelVersion
=
strings
.
TrimSpace
(
string
(
out
))
// parse kernel version
ver1
,
err
:=
version
.
ParseGeneric
(
kernelVersion
)
if
err
!=
nil
{
return
kernelVersion
,
nil
,
fmt
.
Errorf
(
"error parsing kernel version: %v(%s)"
,
err
,
kernelVersion
)
}
// "nf_conntrack_ipv4" has been removed since v4.19
// see https://github.com/torvalds/linux/commit/a0ae2562c6c4b2721d9fddba63b7286c13517d9f
ver2
,
_
:=
version
.
ParseGeneric
(
"4.19"
)
// get required ipvs modules
if
ver1
.
LessThan
(
ver2
)
{
ipvsModules
=
append
(
ipvsModules
,
ModIPVS
,
ModIPVSRR
,
ModIPVSWRR
,
ModIPVSSH
,
ModNfConntrackIPV4
)
}
else
{
ipvsModules
=
append
(
ipvsModules
,
ModIPVS
,
ModIPVSRR
,
ModIPVSWRR
,
ModIPVSSH
,
ModNfConntrack
)
}
return
kernelVersion
,
ipvsModules
,
nil
}
pkg/util/ipvs/kernelcheck_linux.go
View file @
c0d248ad
...
...
@@ -44,6 +44,11 @@ func (r RequiredIPVSKernelModulesAvailableCheck) Name() string {
func
(
r
RequiredIPVSKernelModulesAvailableCheck
)
Check
()
(
warnings
,
errors
[]
error
)
{
glog
.
V
(
1
)
.
Infoln
(
"validating the kernel module IPVS required exists in machine or not"
)
kernelVersion
,
ipvsModules
,
err
:=
GetKernelVersionAndIPVSMods
(
r
.
Executor
)
if
err
!=
nil
{
errors
=
append
(
errors
,
err
)
}
// Find out loaded kernel modules
out
,
err
:=
r
.
Executor
.
Command
(
"cut"
,
"-f1"
,
"-d"
,
" "
,
"/proc/modules"
)
.
CombinedOutput
()
if
err
!=
nil
{
...
...
@@ -60,14 +65,6 @@ func (r RequiredIPVSKernelModulesAvailableCheck) Check() (warnings, errors []err
// Check builtin modules exist or not
if
len
(
modules
)
!=
0
{
kernelVersionFile
:=
"/proc/sys/kernel/osrelease"
b
,
err
:=
r
.
Executor
.
Command
(
"cut"
,
"-f1"
,
"-d"
,
" "
,
kernelVersionFile
)
.
CombinedOutput
()
if
err
!=
nil
{
errors
=
append
(
errors
,
fmt
.
Errorf
(
"error getting os release kernel version: %v(%s)"
,
err
,
out
))
return
nil
,
errors
}
kernelVersion
:=
strings
.
TrimSpace
(
string
(
b
))
builtinModsFilePath
:=
fmt
.
Sprintf
(
"/lib/modules/%s/modules.builtin"
,
kernelVersion
)
out
,
err
:=
r
.
Executor
.
Command
(
"cut"
,
"-f1"
,
"-d"
,
" "
,
builtinModsFilePath
)
.
CombinedOutput
()
if
err
!=
nil
{
...
...
pkg/util/ipvs/kernelcheck_linux_test.go
View file @
c0d248ad
...
...
@@ -97,8 +97,8 @@ func TestRequiredIPVSKernelModulesAvailableCheck(t *testing.T) {
for
i
,
tc
:=
range
cases
{
fcmd
:=
fakeexec
.
FakeCmd
{
CombinedOutputScript
:
[]
fakeexec
.
FakeCombinedOutputAction
{
func
()
([]
byte
,
error
)
{
return
[]
byte
(
cases
[
i
]
.
loadedKernel
),
nil
},
func
()
([]
byte
,
error
)
{
return
[]
byte
(
cases
[
i
]
.
kernelVersion
),
nil
},
func
()
([]
byte
,
error
)
{
return
[]
byte
(
cases
[
i
]
.
loadedKernel
),
nil
},
func
()
([]
byte
,
error
)
{
return
[]
byte
(
cases
[
i
]
.
builtinKernel
),
nil
},
},
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment