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
c2cb2b3c
Commit
c2cb2b3c
authored
Jun 06, 2017
by
Dane LeBlanc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add IPv6 test cases to kube-proxy server test.
fixes #47313
parent
4a01f44b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
164 additions
and
54 deletions
+164
-54
BUILD
cmd/kube-proxy/app/BUILD
+3
-0
server_test.go
cmd/kube-proxy/app/server_test.go
+161
-54
No files found.
cmd/kube-proxy/app/BUILD
View file @
c2cb2b3c
...
@@ -72,10 +72,13 @@ go_test(
...
@@ -72,10 +72,13 @@ go_test(
deps = [
deps = [
"//pkg/api:go_default_library",
"//pkg/api:go_default_library",
"//pkg/apis/componentconfig:go_default_library",
"//pkg/apis/componentconfig:go_default_library",
"//pkg/apis/componentconfig/v1alpha1:go_default_library",
"//pkg/util:go_default_library",
"//pkg/util:go_default_library",
"//pkg/util/configz:go_default_library",
"//pkg/util/iptables:go_default_library",
"//pkg/util/iptables:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/diff:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/diff:go_default_library",
],
],
)
)
...
...
cmd/kube-proxy/app/server_test.go
View file @
c2cb2b3c
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
app
package
app
import
(
import
(
"errors"
"fmt"
"fmt"
"reflect"
"reflect"
"runtime"
"runtime"
...
@@ -27,10 +28,13 @@ import (
...
@@ -27,10 +28,13 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
k8sRuntime
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/componentconfig"
"k8s.io/kubernetes/pkg/apis/componentconfig"
"k8s.io/kubernetes/pkg/apis/componentconfig/v1alpha1"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/configz"
"k8s.io/kubernetes/pkg/util/iptables"
"k8s.io/kubernetes/pkg/util/iptables"
)
)
...
@@ -134,23 +138,67 @@ func Test_getProxyMode(t *testing.T) {
...
@@ -134,23 +138,67 @@ func Test_getProxyMode(t *testing.T) {
}
}
}
}
// This test verifies that Proxy Server does not crash when CleanupAndExit is true.
// TestNewOptionsFailures tests failure modes for NewOptions()
func
TestProxyServerWithCleanupAndExit
(
t
*
testing
.
T
)
{
func
TestNewOptionsFailures
(
t
*
testing
.
T
)
{
options
,
err
:=
NewOptions
()
if
err
!=
nil
{
// Create a fake scheme builder that generates an error
t
.
Fatal
(
err
)
errString
:=
fmt
.
Sprintf
(
"Simulated error"
)
genError
:=
func
(
scheme
*
k8sRuntime
.
Scheme
)
error
{
return
errors
.
New
(
errString
)
}
}
fakeSchemeBuilder
:=
k8sRuntime
.
NewSchemeBuilder
(
genError
)
simulatedErrorTest
:=
func
(
target
string
)
{
var
addToScheme
*
func
(
s
*
k8sRuntime
.
Scheme
)
error
if
target
==
"componentconfig"
{
addToScheme
=
&
componentconfig
.
AddToScheme
}
else
{
addToScheme
=
&
v1alpha1
.
AddToScheme
}
restoreValue
:=
*
addToScheme
restore
:=
func
()
{
*
addToScheme
=
restoreValue
}
defer
restore
()
*
addToScheme
=
fakeSchemeBuilder
.
AddToScheme
_
,
err
:=
NewOptions
()
assert
.
Error
(
t
,
err
,
fmt
.
Sprintf
(
"Simulated error in component %s"
,
target
))
}
// Simulate errors in calls to AddToScheme()
faultTargets
:=
[]
string
{
"componentconfig"
,
"v1alpha1"
}
for
_
,
target
:=
range
faultTargets
{
simulatedErrorTest
(
target
)
}
}
options
.
config
=
&
componentconfig
.
KubeProxyConfiguration
{
// This test verifies that NewProxyServer does not crash when CleanupAndExit is true.
BindAddress
:
"0.0.0.0"
,
func
TestProxyServerWithCleanupAndExit
(
t
*
testing
.
T
)
{
// Each bind address below is a separate test case
bindAddresses
:=
[]
string
{
"0.0.0.0"
,
"2001:db8::1"
,
}
}
options
.
CleanupAndExit
=
true
for
_
,
addr
:=
range
bindAddresses
{
options
,
err
:=
NewOptions
()
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error with address %s: %v"
,
addr
,
err
)
}
options
.
config
=
&
componentconfig
.
KubeProxyConfiguration
{
BindAddress
:
addr
,
}
options
.
CleanupAndExit
=
true
proxyserver
,
err
:=
NewProxyServer
(
options
.
config
,
options
.
CleanupAndExit
,
options
.
scheme
,
options
.
master
)
proxyserver
,
err
:=
NewProxyServer
(
options
.
config
,
options
.
CleanupAndExit
,
options
.
scheme
,
options
.
master
)
assert
.
Nil
(
t
,
err
,
"unexpected error in NewProxyServer, addr: %s"
,
addr
)
assert
.
NotNil
(
t
,
proxyserver
,
"nil proxy server obj, addr: %s"
,
addr
)
assert
.
NotNil
(
t
,
proxyserver
.
IptInterface
,
"nil iptables intf, addr: %s"
,
addr
)
assert
.
Nil
(
t
,
err
)
// Clean up config for next test case
assert
.
NotNil
(
t
,
proxyserver
)
configz
.
Delete
(
"componentconfig"
)
assert
.
NotNil
(
t
,
proxyserver
.
IptInterface
)
}
}
}
func
TestGetConntrackMax
(
t
*
testing
.
T
)
{
func
TestGetConntrackMax
(
t
*
testing
.
T
)
{
...
@@ -211,16 +259,18 @@ func TestGetConntrackMax(t *testing.T) {
...
@@ -211,16 +259,18 @@ func TestGetConntrackMax(t *testing.T) {
}
}
}
}
// TestLoadConfig tests proper operation of loadConfig()
func
TestLoadConfig
(
t
*
testing
.
T
)
{
func
TestLoadConfig
(
t
*
testing
.
T
)
{
yaml
:=
`apiVersion: componentconfig/v1alpha1
bindAddress: 9.8.7.6
yamlTemplate
:=
`apiVersion: componentconfig/v1alpha1
bindAddress: %s
clientConnection:
clientConnection:
acceptContentTypes: "abc"
acceptContentTypes: "abc"
burst: 100
burst: 100
contentType: content-type
contentType: content-type
kubeconfig: "/path/to/kubeconfig"
kubeconfig: "/path/to/kubeconfig"
qps: 7
qps: 7
clusterCIDR: "
1.2.3.0/24
"
clusterCIDR: "
%s
"
configSyncPeriod: 15s
configSyncPeriod: 15s
conntrack:
conntrack:
max: 4
max: 4
...
@@ -229,7 +279,7 @@ conntrack:
...
@@ -229,7 +279,7 @@ conntrack:
tcpCloseWaitTimeout: 10s
tcpCloseWaitTimeout: 10s
tcpEstablishedTimeout: 20s
tcpEstablishedTimeout: 20s
featureGates: "all"
featureGates: "all"
healthzBindAddress:
1.2.3.4:12345
healthzBindAddress:
"%s"
hostnameOverride: "foo"
hostnameOverride: "foo"
iptables:
iptables:
masqueradeAll: true
masqueradeAll: true
...
@@ -237,7 +287,7 @@ iptables:
...
@@ -237,7 +287,7 @@ iptables:
minSyncPeriod: 10s
minSyncPeriod: 10s
syncPeriod: 60s
syncPeriod: 60s
kind: KubeProxyConfiguration
kind: KubeProxyConfiguration
metricsBindAddress:
2.3.4.5:23456
metricsBindAddress:
"%s"
mode: "iptables"
mode: "iptables"
oomScoreAdj: 17
oomScoreAdj: 17
portRange: "2-7"
portRange: "2-7"
...
@@ -245,47 +295,104 @@ resourceContainer: /foo
...
@@ -245,47 +295,104 @@ resourceContainer: /foo
udpTimeoutMilliseconds: 123ms
udpTimeoutMilliseconds: 123ms
`
`
expected
:=
&
componentconfig
.
KubeProxyConfiguration
{
testCases
:=
[]
struct
{
BindAddress
:
"9.8.7.6"
,
name
string
ClientConnection
:
componentconfig
.
ClientConnectionConfiguration
{
bindAddress
string
AcceptContentTypes
:
"abc"
,
clusterCIDR
string
Burst
:
100
,
healthzBindAddress
string
ContentType
:
"content-type"
,
metricsBindAddress
string
KubeConfigFile
:
"/path/to/kubeconfig"
,
}{
QPS
:
7
,
{
},
name
:
"IPv4 config"
,
ClusterCIDR
:
"1.2.3.0/24"
,
bindAddress
:
"9.8.7.6"
,
ConfigSyncPeriod
:
metav1
.
Duration
{
Duration
:
15
*
time
.
Second
},
clusterCIDR
:
"1.2.3.0/24"
,
Conntrack
:
componentconfig
.
KubeProxyConntrackConfiguration
{
healthzBindAddress
:
"1.2.3.4:12345"
,
Max
:
4
,
metricsBindAddress
:
"2.3.4.5:23456"
,
MaxPerCore
:
2
,
Min
:
1
,
TCPCloseWaitTimeout
:
metav1
.
Duration
{
Duration
:
10
*
time
.
Second
},
TCPEstablishedTimeout
:
metav1
.
Duration
{
Duration
:
20
*
time
.
Second
},
},
},
FeatureGates
:
"all"
,
{
HealthzBindAddress
:
"1.2.3.4:12345"
,
name
:
"IPv6 config"
,
HostnameOverride
:
"foo"
,
bindAddress
:
"2001:db8::1"
,
IPTables
:
componentconfig
.
KubeProxyIPTablesConfiguration
{
clusterCIDR
:
"fd00:1::0/64"
,
MasqueradeAll
:
true
,
healthzBindAddress
:
"[fd00:1::5]:12345"
,
MasqueradeBit
:
util
.
Int32Ptr
(
17
),
metricsBindAddress
:
"[fd00:2::5]:23456"
,
MinSyncPeriod
:
metav1
.
Duration
{
Duration
:
10
*
time
.
Second
},
SyncPeriod
:
metav1
.
Duration
{
Duration
:
60
*
time
.
Second
},
},
},
MetricsBindAddress
:
"2.3.4.5:23456"
,
Mode
:
"iptables"
,
OOMScoreAdj
:
util
.
Int32Ptr
(
17
),
PortRange
:
"2-7"
,
ResourceContainer
:
"/foo"
,
UDPIdleTimeout
:
metav1
.
Duration
{
Duration
:
123
*
time
.
Millisecond
},
}
}
options
,
err
:=
NewOptions
()
for
_
,
tc
:=
range
testCases
{
assert
.
NoError
(
t
,
err
)
expected
:=
&
componentconfig
.
KubeProxyConfiguration
{
BindAddress
:
tc
.
bindAddress
,
ClientConnection
:
componentconfig
.
ClientConnectionConfiguration
{
AcceptContentTypes
:
"abc"
,
Burst
:
100
,
ContentType
:
"content-type"
,
KubeConfigFile
:
"/path/to/kubeconfig"
,
QPS
:
7
,
},
ClusterCIDR
:
tc
.
clusterCIDR
,
ConfigSyncPeriod
:
metav1
.
Duration
{
Duration
:
15
*
time
.
Second
},
Conntrack
:
componentconfig
.
KubeProxyConntrackConfiguration
{
Max
:
4
,
MaxPerCore
:
2
,
Min
:
1
,
TCPCloseWaitTimeout
:
metav1
.
Duration
{
Duration
:
10
*
time
.
Second
},
TCPEstablishedTimeout
:
metav1
.
Duration
{
Duration
:
20
*
time
.
Second
},
},
FeatureGates
:
"all"
,
HealthzBindAddress
:
tc
.
healthzBindAddress
,
HostnameOverride
:
"foo"
,
IPTables
:
componentconfig
.
KubeProxyIPTablesConfiguration
{
MasqueradeAll
:
true
,
MasqueradeBit
:
util
.
Int32Ptr
(
17
),
MinSyncPeriod
:
metav1
.
Duration
{
Duration
:
10
*
time
.
Second
},
SyncPeriod
:
metav1
.
Duration
{
Duration
:
60
*
time
.
Second
},
},
MetricsBindAddress
:
tc
.
metricsBindAddress
,
Mode
:
"iptables"
,
OOMScoreAdj
:
util
.
Int32Ptr
(
17
),
PortRange
:
"2-7"
,
ResourceContainer
:
"/foo"
,
UDPIdleTimeout
:
metav1
.
Duration
{
Duration
:
123
*
time
.
Millisecond
},
}
options
,
err
:=
NewOptions
()
assert
.
NoError
(
t
,
err
,
"unexpected error for %s: %v"
,
tc
.
name
,
err
)
yaml
:=
fmt
.
Sprintf
(
yamlTemplate
,
tc
.
bindAddress
,
tc
.
clusterCIDR
,
tc
.
healthzBindAddress
,
tc
.
metricsBindAddress
)
config
,
err
:=
options
.
loadConfig
([]
byte
(
yaml
))
assert
.
NoError
(
t
,
err
,
"unexpected error for %s: %v"
,
tc
.
name
,
err
)
if
!
reflect
.
DeepEqual
(
expected
,
config
)
{
t
.
Fatalf
(
"unexpected config for %s test, diff = %s"
,
tc
.
name
,
diff
.
ObjectDiff
(
config
,
expected
))
}
}
}
config
,
err
:=
options
.
loadConfig
([]
byte
(
yaml
))
// TestLoadConfigFailures tests failure modes for loadConfig()
assert
.
NoError
(
t
,
err
)
func
TestLoadConfigFailures
(
t
*
testing
.
T
)
{
if
!
reflect
.
DeepEqual
(
expected
,
config
)
{
testCases
:=
[]
struct
{
t
.
Fatalf
(
"unexpected config, diff = %s"
,
diff
.
ObjectDiff
(
config
,
expected
))
name
string
config
string
expErr
string
}{
{
name
:
"Decode error test"
,
config
:
"Twas bryllyg, and ye slythy toves"
,
expErr
:
"could not find expected ':'"
,
},
{
name
:
"Bad config type test"
,
config
:
"kind: KubeSchedulerConfiguration"
,
expErr
:
"unexpected config type"
,
},
}
version
:=
"apiVersion: componentconfig/v1alpha1"
for
_
,
tc
:=
range
testCases
{
options
,
_
:=
NewOptions
()
config
:=
fmt
.
Sprintf
(
"%s
\n
%s"
,
version
,
tc
.
config
)
_
,
err
:=
options
.
loadConfig
([]
byte
(
config
))
if
assert
.
Error
(
t
,
err
,
tc
.
name
)
{
assert
.
Contains
(
t
,
err
.
Error
(),
tc
.
expErr
,
tc
.
name
)
}
}
}
}
}
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