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
b7d76023
Commit
b7d76023
authored
Oct 04, 2016
by
Marek Grabowski
Committed by
GitHub
Oct 04, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "move pod networking tests common"
parent
ee77d4e6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
227 additions
and
285 deletions
+227
-285
networking.go
test/e2e/common/networking.go
+0
-62
util.go
test/e2e/common/util.go
+0
-1
networking.go
test/e2e/networking.go
+93
-59
networking_utils.go
test/e2e/networking_utils.go
+132
-140
remote.go
test/e2e_node/remote/remote.go
+2
-23
No files found.
test/e2e/common/networking.go
deleted
100644 → 0
View file @
ee77d4e6
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
common
import
(
.
"github.com/onsi/ginkgo"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/test/e2e/framework"
networking_util
"k8s.io/kubernetes/test/utils"
)
var
_
=
framework
.
KubeDescribe
(
"Networking"
,
func
()
{
f
:=
framework
.
NewDefaultFramework
(
"pod-network-test"
)
framework
.
KubeDescribe
(
"Granular Checks: Pods"
,
func
()
{
// Try to hit all endpoints through a test container, retry 5 times,
// expect exactly one unique hostname. Each of these endpoints reports
// its own hostname.
It
(
"should function for intra-pod communication: http [Conformance]"
,
func
()
{
config
:=
networking_util
.
NewCoreNetworkingTestConfig
(
f
)
for
_
,
endpointPod
:=
range
config
.
EndpointPods
{
config
.
DialFromTestContainer
(
"http"
,
endpointPod
.
Status
.
PodIP
,
networking_util
.
EndpointHttpPort
,
config
.
MaxTries
,
0
,
sets
.
NewString
(
endpointPod
.
Name
))
}
})
It
(
"should function for intra-pod communication: udp [Conformance]"
,
func
()
{
config
:=
networking_util
.
NewCoreNetworkingTestConfig
(
f
)
for
_
,
endpointPod
:=
range
config
.
EndpointPods
{
config
.
DialFromTestContainer
(
"udp"
,
endpointPod
.
Status
.
PodIP
,
networking_util
.
EndpointUdpPort
,
config
.
MaxTries
,
0
,
sets
.
NewString
(
endpointPod
.
Name
))
}
})
It
(
"should function for node-pod communication: http [Conformance]"
,
func
()
{
config
:=
networking_util
.
NewCoreNetworkingTestConfig
(
f
)
for
_
,
endpointPod
:=
range
config
.
EndpointPods
{
config
.
DialFromNode
(
"http"
,
endpointPod
.
Status
.
PodIP
,
networking_util
.
EndpointHttpPort
,
config
.
MaxTries
,
0
,
sets
.
NewString
(
endpointPod
.
Name
))
}
})
It
(
"should function for node-pod communication: udp [Conformance]"
,
func
()
{
config
:=
networking_util
.
NewCoreNetworkingTestConfig
(
f
)
for
_
,
endpointPod
:=
range
config
.
EndpointPods
{
config
.
DialFromNode
(
"udp"
,
endpointPod
.
Status
.
PodIP
,
networking_util
.
EndpointUdpPort
,
config
.
MaxTries
,
0
,
sets
.
NewString
(
endpointPod
.
Name
))
}
})
})
})
test/e2e/common/util.go
View file @
b7d76023
...
...
@@ -40,7 +40,6 @@ var CommonImageWhiteList = sets.NewString(
"gcr.io/google_containers/mounttest:0.7"
,
"gcr.io/google_containers/mounttest-user:0.3"
,
"gcr.io/google_containers/netexec:1.4"
,
"gcr.io/google_containers/netexec:1.5"
,
"gcr.io/google_containers/nginx-slim:0.7"
,
"gcr.io/google_containers/serve_hostname:v1.4"
,
"gcr.io/google_containers/test-webserver:e2e"
,
...
...
test/e2e/networking.go
View file @
b7d76023
...
...
@@ -20,10 +20,10 @@ import (
"fmt"
"net/http"
.
"github.com/onsi/ginkgo"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/test/e2e/framework"
networking_util
"k8s.io/kubernetes/test/utils"
.
"github.com/onsi/ginkgo"
)
var
_
=
framework
.
KubeDescribe
(
"Networking"
,
func
()
{
...
...
@@ -77,114 +77,148 @@ var _ = framework.KubeDescribe("Networking", func() {
It
(
"should check kube-proxy urls"
,
func
()
{
// TODO: this is overkill we just need the host networking pod
// to hit kube-proxy urls.
config
:=
networking_util
.
NewNetworkingTestConfig
(
f
)
config
:=
NewNetworkingTestConfig
(
f
)
By
(
"checking kube-proxy URLs"
)
config
.
GetSelfURL
(
"/healthz"
,
"ok"
)
config
.
GetSelfURL
(
"/proxyMode"
,
"iptables"
)
// the default
config
.
getSelfURL
(
"/healthz"
,
"ok"
)
config
.
getSelfURL
(
"/proxyMode"
,
"iptables"
)
// the default
})
framework
.
KubeDescribe
(
"Granular Checks: Pods"
,
func
()
{
// Try to hit all endpoints through a test container, retry 5 times,
// expect exactly one unique hostname. Each of these endpoints reports
// its own hostname.
It
(
"should function for intra-pod communication: http [Conformance]"
,
func
()
{
config
:=
NewNetworkingTestConfig
(
f
)
for
_
,
endpointPod
:=
range
config
.
endpointPods
{
config
.
dialFromTestContainer
(
"http"
,
endpointPod
.
Status
.
PodIP
,
endpointHttpPort
,
config
.
maxTries
,
0
,
sets
.
NewString
(
endpointPod
.
Name
))
}
})
It
(
"should function for intra-pod communication: udp [Conformance]"
,
func
()
{
config
:=
NewNetworkingTestConfig
(
f
)
for
_
,
endpointPod
:=
range
config
.
endpointPods
{
config
.
dialFromTestContainer
(
"udp"
,
endpointPod
.
Status
.
PodIP
,
endpointUdpPort
,
config
.
maxTries
,
0
,
sets
.
NewString
(
endpointPod
.
Name
))
}
})
It
(
"should function for node-pod communication: http [Conformance]"
,
func
()
{
config
:=
NewNetworkingTestConfig
(
f
)
for
_
,
endpointPod
:=
range
config
.
endpointPods
{
config
.
dialFromNode
(
"http"
,
endpointPod
.
Status
.
PodIP
,
endpointHttpPort
,
config
.
maxTries
,
0
,
sets
.
NewString
(
endpointPod
.
Name
))
}
})
It
(
"should function for node-pod communication: udp [Conformance]"
,
func
()
{
config
:=
NewNetworkingTestConfig
(
f
)
for
_
,
endpointPod
:=
range
config
.
endpointPods
{
config
.
dialFromNode
(
"udp"
,
endpointPod
.
Status
.
PodIP
,
endpointUdpPort
,
config
.
maxTries
,
0
,
sets
.
NewString
(
endpointPod
.
Name
))
}
})
})
// TODO: Remove [Slow] when this has had enough bake time to prove presubmit worthiness.
framework
.
KubeDescribe
(
"Granular Checks: Services [Slow]"
,
func
()
{
It
(
"should function for pod-Service: http"
,
func
()
{
config
:=
networking_util
.
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(http) %v --> %v:%v (config.clusterIP)"
,
config
.
TestContainerPod
.
Name
,
config
.
ClusterIP
,
networking_util
.
C
lusterHttpPort
))
config
.
DialFromTestContainer
(
"http"
,
config
.
ClusterIP
,
networking_util
.
ClusterHttpPort
,
config
.
MaxTries
,
0
,
config
.
E
ndpointHostnames
())
config
:=
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(http) %v --> %v:%v (config.clusterIP)"
,
config
.
testContainerPod
.
Name
,
config
.
clusterIP
,
c
lusterHttpPort
))
config
.
dialFromTestContainer
(
"http"
,
config
.
clusterIP
,
clusterHttpPort
,
config
.
maxTries
,
0
,
config
.
e
ndpointHostnames
())
By
(
fmt
.
Sprintf
(
"dialing(http) %v --> %v:%v (nodeIP)"
,
config
.
TestContainerPod
.
Name
,
config
.
ExternalAddrs
[
0
],
config
.
N
odeHttpPort
))
config
.
DialFromTestContainer
(
"http"
,
config
.
NodeIP
,
config
.
NodeHttpPort
,
config
.
MaxTries
,
0
,
config
.
E
ndpointHostnames
())
By
(
fmt
.
Sprintf
(
"dialing(http) %v --> %v:%v (nodeIP)"
,
config
.
testContainerPod
.
Name
,
config
.
externalAddrs
[
0
],
config
.
n
odeHttpPort
))
config
.
dialFromTestContainer
(
"http"
,
config
.
nodeIP
,
config
.
nodeHttpPort
,
config
.
maxTries
,
0
,
config
.
e
ndpointHostnames
())
})
It
(
"should function for pod-Service: udp"
,
func
()
{
config
:=
networking_util
.
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(udp) %v --> %v:%v (config.clusterIP)"
,
config
.
TestContainerPod
.
Name
,
config
.
ClusterIP
,
networking_util
.
C
lusterUdpPort
))
config
.
DialFromTestContainer
(
"udp"
,
config
.
ClusterIP
,
networking_util
.
ClusterUdpPort
,
config
.
MaxTries
,
0
,
config
.
E
ndpointHostnames
())
config
:=
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(udp) %v --> %v:%v (config.clusterIP)"
,
config
.
testContainerPod
.
Name
,
config
.
clusterIP
,
c
lusterUdpPort
))
config
.
dialFromTestContainer
(
"udp"
,
config
.
clusterIP
,
clusterUdpPort
,
config
.
maxTries
,
0
,
config
.
e
ndpointHostnames
())
By
(
fmt
.
Sprintf
(
"dialing(udp) %v --> %v:%v (nodeIP)"
,
config
.
TestContainerPod
.
Name
,
config
.
ExternalAddrs
[
0
],
config
.
N
odeUdpPort
))
config
.
DialFromTestContainer
(
"udp"
,
config
.
NodeIP
,
config
.
NodeUdpPort
,
config
.
MaxTries
,
0
,
config
.
E
ndpointHostnames
())
By
(
fmt
.
Sprintf
(
"dialing(udp) %v --> %v:%v (nodeIP)"
,
config
.
testContainerPod
.
Name
,
config
.
externalAddrs
[
0
],
config
.
n
odeUdpPort
))
config
.
dialFromTestContainer
(
"udp"
,
config
.
nodeIP
,
config
.
nodeUdpPort
,
config
.
maxTries
,
0
,
config
.
e
ndpointHostnames
())
})
It
(
"should function for node-Service: http"
,
func
()
{
config
:=
networking_util
.
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(http) %v (node) --> %v:%v (config.clusterIP)"
,
config
.
NodeIP
,
config
.
ClusterIP
,
networking_util
.
C
lusterHttpPort
))
config
.
DialFromNode
(
"http"
,
config
.
ClusterIP
,
networking_util
.
ClusterHttpPort
,
config
.
MaxTries
,
0
,
config
.
E
ndpointHostnames
())
config
:=
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(http) %v (node) --> %v:%v (config.clusterIP)"
,
config
.
nodeIP
,
config
.
clusterIP
,
c
lusterHttpPort
))
config
.
dialFromNode
(
"http"
,
config
.
clusterIP
,
clusterHttpPort
,
config
.
maxTries
,
0
,
config
.
e
ndpointHostnames
())
By
(
fmt
.
Sprintf
(
"dialing(http) %v (node) --> %v:%v (nodeIP)"
,
config
.
NodeIP
,
config
.
NodeIP
,
config
.
N
odeHttpPort
))
config
.
DialFromNode
(
"http"
,
config
.
NodeIP
,
config
.
NodeHttpPort
,
config
.
MaxTries
,
0
,
config
.
E
ndpointHostnames
())
By
(
fmt
.
Sprintf
(
"dialing(http) %v (node) --> %v:%v (nodeIP)"
,
config
.
nodeIP
,
config
.
nodeIP
,
config
.
n
odeHttpPort
))
config
.
dialFromNode
(
"http"
,
config
.
nodeIP
,
config
.
nodeHttpPort
,
config
.
maxTries
,
0
,
config
.
e
ndpointHostnames
())
})
It
(
"should function for node-Service: udp"
,
func
()
{
config
:=
networking_util
.
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(udp) %v (node) --> %v:%v (config.clusterIP)"
,
config
.
NodeIP
,
config
.
ClusterIP
,
networking_util
.
C
lusterUdpPort
))
config
.
DialFromNode
(
"udp"
,
config
.
ClusterIP
,
networking_util
.
ClusterUdpPort
,
config
.
MaxTries
,
0
,
config
.
E
ndpointHostnames
())
config
:=
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(udp) %v (node) --> %v:%v (config.clusterIP)"
,
config
.
nodeIP
,
config
.
clusterIP
,
c
lusterUdpPort
))
config
.
dialFromNode
(
"udp"
,
config
.
clusterIP
,
clusterUdpPort
,
config
.
maxTries
,
0
,
config
.
e
ndpointHostnames
())
By
(
fmt
.
Sprintf
(
"dialing(udp) %v (node) --> %v:%v (nodeIP)"
,
config
.
NodeIP
,
config
.
NodeIP
,
config
.
N
odeUdpPort
))
config
.
DialFromNode
(
"udp"
,
config
.
NodeIP
,
config
.
NodeUdpPort
,
config
.
MaxTries
,
0
,
config
.
E
ndpointHostnames
())
By
(
fmt
.
Sprintf
(
"dialing(udp) %v (node) --> %v:%v (nodeIP)"
,
config
.
nodeIP
,
config
.
nodeIP
,
config
.
n
odeUdpPort
))
config
.
dialFromNode
(
"udp"
,
config
.
nodeIP
,
config
.
nodeUdpPort
,
config
.
maxTries
,
0
,
config
.
e
ndpointHostnames
())
})
It
(
"should function for endpoint-Service: http"
,
func
()
{
config
:=
networking_util
.
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(http) %v (endpoint) --> %v:%v (config.clusterIP)"
,
config
.
EndpointPods
[
0
]
.
Name
,
config
.
ClusterIP
,
networking_util
.
C
lusterHttpPort
))
config
.
DialFromEndpointContainer
(
"http"
,
config
.
ClusterIP
,
networking_util
.
ClusterHttpPort
,
config
.
MaxTries
,
0
,
config
.
E
ndpointHostnames
())
config
:=
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(http) %v (endpoint) --> %v:%v (config.clusterIP)"
,
config
.
endpointPods
[
0
]
.
Name
,
config
.
clusterIP
,
c
lusterHttpPort
))
config
.
dialFromEndpointContainer
(
"http"
,
config
.
clusterIP
,
clusterHttpPort
,
config
.
maxTries
,
0
,
config
.
e
ndpointHostnames
())
By
(
fmt
.
Sprintf
(
"dialing(http) %v (endpoint) --> %v:%v (nodeIP)"
,
config
.
EndpointPods
[
0
]
.
Name
,
config
.
NodeIP
,
config
.
N
odeHttpPort
))
config
.
DialFromEndpointContainer
(
"http"
,
config
.
NodeIP
,
config
.
NodeHttpPort
,
config
.
MaxTries
,
0
,
config
.
E
ndpointHostnames
())
By
(
fmt
.
Sprintf
(
"dialing(http) %v (endpoint) --> %v:%v (nodeIP)"
,
config
.
endpointPods
[
0
]
.
Name
,
config
.
nodeIP
,
config
.
n
odeHttpPort
))
config
.
dialFromEndpointContainer
(
"http"
,
config
.
nodeIP
,
config
.
nodeHttpPort
,
config
.
maxTries
,
0
,
config
.
e
ndpointHostnames
())
})
It
(
"should function for endpoint-Service: udp"
,
func
()
{
config
:=
networking_util
.
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(udp) %v (endpoint) --> %v:%v (config.clusterIP)"
,
config
.
EndpointPods
[
0
]
.
Name
,
config
.
ClusterIP
,
networking_util
.
C
lusterUdpPort
))
config
.
DialFromEndpointContainer
(
"udp"
,
config
.
ClusterIP
,
networking_util
.
ClusterUdpPort
,
config
.
MaxTries
,
0
,
config
.
E
ndpointHostnames
())
config
:=
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(udp) %v (endpoint) --> %v:%v (config.clusterIP)"
,
config
.
endpointPods
[
0
]
.
Name
,
config
.
clusterIP
,
c
lusterUdpPort
))
config
.
dialFromEndpointContainer
(
"udp"
,
config
.
clusterIP
,
clusterUdpPort
,
config
.
maxTries
,
0
,
config
.
e
ndpointHostnames
())
By
(
fmt
.
Sprintf
(
"dialing(udp) %v (endpoint) --> %v:%v (nodeIP)"
,
config
.
EndpointPods
[
0
]
.
Name
,
config
.
NodeIP
,
config
.
N
odeUdpPort
))
config
.
DialFromEndpointContainer
(
"udp"
,
config
.
NodeIP
,
config
.
NodeUdpPort
,
config
.
MaxTries
,
0
,
config
.
E
ndpointHostnames
())
By
(
fmt
.
Sprintf
(
"dialing(udp) %v (endpoint) --> %v:%v (nodeIP)"
,
config
.
endpointPods
[
0
]
.
Name
,
config
.
nodeIP
,
config
.
n
odeUdpPort
))
config
.
dialFromEndpointContainer
(
"udp"
,
config
.
nodeIP
,
config
.
nodeUdpPort
,
config
.
maxTries
,
0
,
config
.
e
ndpointHostnames
())
})
It
(
"should update endpoints: http"
,
func
()
{
config
:=
networking_util
.
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(http) %v --> %v:%v (config.clusterIP)"
,
config
.
TestContainerPod
.
Name
,
config
.
ClusterIP
,
networking_util
.
C
lusterHttpPort
))
config
.
DialFromTestContainer
(
"http"
,
config
.
ClusterIP
,
networking_util
.
ClusterHttpPort
,
config
.
MaxTries
,
0
,
config
.
E
ndpointHostnames
())
config
:=
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(http) %v --> %v:%v (config.clusterIP)"
,
config
.
testContainerPod
.
Name
,
config
.
clusterIP
,
c
lusterHttpPort
))
config
.
dialFromTestContainer
(
"http"
,
config
.
clusterIP
,
clusterHttpPort
,
config
.
maxTries
,
0
,
config
.
e
ndpointHostnames
())
config
.
D
eleteNetProxyPod
()
config
.
d
eleteNetProxyPod
()
By
(
fmt
.
Sprintf
(
"dialing(http) %v --> %v:%v (config.clusterIP)"
,
config
.
TestContainerPod
.
Name
,
config
.
ClusterIP
,
networking_util
.
C
lusterHttpPort
))
config
.
DialFromTestContainer
(
"http"
,
config
.
ClusterIP
,
networking_util
.
ClusterHttpPort
,
config
.
MaxTries
,
config
.
MaxTries
,
config
.
E
ndpointHostnames
())
By
(
fmt
.
Sprintf
(
"dialing(http) %v --> %v:%v (config.clusterIP)"
,
config
.
testContainerPod
.
Name
,
config
.
clusterIP
,
c
lusterHttpPort
))
config
.
dialFromTestContainer
(
"http"
,
config
.
clusterIP
,
clusterHttpPort
,
config
.
maxTries
,
config
.
maxTries
,
config
.
e
ndpointHostnames
())
})
It
(
"should update endpoints: udp"
,
func
()
{
config
:=
networking_util
.
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(udp) %v --> %v:%v (config.clusterIP)"
,
config
.
TestContainerPod
.
Name
,
config
.
ClusterIP
,
networking_util
.
C
lusterUdpPort
))
config
.
DialFromTestContainer
(
"udp"
,
config
.
ClusterIP
,
networking_util
.
ClusterUdpPort
,
config
.
MaxTries
,
0
,
config
.
E
ndpointHostnames
())
config
:=
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(udp) %v --> %v:%v (config.clusterIP)"
,
config
.
testContainerPod
.
Name
,
config
.
clusterIP
,
c
lusterUdpPort
))
config
.
dialFromTestContainer
(
"udp"
,
config
.
clusterIP
,
clusterUdpPort
,
config
.
maxTries
,
0
,
config
.
e
ndpointHostnames
())
config
.
D
eleteNetProxyPod
()
config
.
d
eleteNetProxyPod
()
By
(
fmt
.
Sprintf
(
"dialing(udp) %v --> %v:%v (config.clusterIP)"
,
config
.
TestContainerPod
.
Name
,
config
.
ClusterIP
,
networking_util
.
C
lusterUdpPort
))
config
.
DialFromTestContainer
(
"udp"
,
config
.
ClusterIP
,
networking_util
.
ClusterUdpPort
,
config
.
MaxTries
,
config
.
MaxTries
,
config
.
E
ndpointHostnames
())
By
(
fmt
.
Sprintf
(
"dialing(udp) %v --> %v:%v (config.clusterIP)"
,
config
.
testContainerPod
.
Name
,
config
.
clusterIP
,
c
lusterUdpPort
))
config
.
dialFromTestContainer
(
"udp"
,
config
.
clusterIP
,
clusterUdpPort
,
config
.
maxTries
,
config
.
maxTries
,
config
.
e
ndpointHostnames
())
})
// Slow because we confirm that the nodePort doesn't serve traffic, which requires a period of polling.
It
(
"should update nodePort: http [Slow]"
,
func
()
{
config
:=
networking_util
.
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(http) %v (node) --> %v:%v (nodeIP)"
,
config
.
NodeIP
,
config
.
NodeIP
,
config
.
N
odeHttpPort
))
config
.
DialFromNode
(
"http"
,
config
.
NodeIP
,
config
.
NodeHttpPort
,
config
.
MaxTries
,
0
,
config
.
E
ndpointHostnames
())
config
:=
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(http) %v (node) --> %v:%v (nodeIP)"
,
config
.
nodeIP
,
config
.
nodeIP
,
config
.
n
odeHttpPort
))
config
.
dialFromNode
(
"http"
,
config
.
nodeIP
,
config
.
nodeHttpPort
,
config
.
maxTries
,
0
,
config
.
e
ndpointHostnames
())
config
.
D
eleteNodePortService
()
config
.
d
eleteNodePortService
()
By
(
fmt
.
Sprintf
(
"dialing(http) %v (node) --> %v:%v (nodeIP)"
,
config
.
NodeIP
,
config
.
NodeIP
,
config
.
N
odeHttpPort
))
config
.
DialFromNode
(
"http"
,
config
.
NodeIP
,
config
.
NodeHttpPort
,
config
.
MaxTries
,
config
.
M
axTries
,
sets
.
NewString
())
By
(
fmt
.
Sprintf
(
"dialing(http) %v (node) --> %v:%v (nodeIP)"
,
config
.
nodeIP
,
config
.
nodeIP
,
config
.
n
odeHttpPort
))
config
.
dialFromNode
(
"http"
,
config
.
nodeIP
,
config
.
nodeHttpPort
,
config
.
maxTries
,
config
.
m
axTries
,
sets
.
NewString
())
})
// Slow because we confirm that the nodePort doesn't serve traffic, which requires a period of polling.
It
(
"should update nodePort: udp [Slow]"
,
func
()
{
config
:=
networking_util
.
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(udp) %v (node) --> %v:%v (nodeIP)"
,
config
.
NodeIP
,
config
.
NodeIP
,
config
.
N
odeUdpPort
))
config
.
DialFromNode
(
"udp"
,
config
.
NodeIP
,
config
.
NodeUdpPort
,
config
.
MaxTries
,
0
,
config
.
E
ndpointHostnames
())
config
:=
NewNetworkingTestConfig
(
f
)
By
(
fmt
.
Sprintf
(
"dialing(udp) %v (node) --> %v:%v (nodeIP)"
,
config
.
nodeIP
,
config
.
nodeIP
,
config
.
n
odeUdpPort
))
config
.
dialFromNode
(
"udp"
,
config
.
nodeIP
,
config
.
nodeUdpPort
,
config
.
maxTries
,
0
,
config
.
e
ndpointHostnames
())
config
.
D
eleteNodePortService
()
config
.
d
eleteNodePortService
()
By
(
fmt
.
Sprintf
(
"dialing(udp) %v (node) --> %v:%v (nodeIP)"
,
config
.
NodeIP
,
config
.
NodeIP
,
config
.
N
odeUdpPort
))
config
.
DialFromNode
(
"udp"
,
config
.
NodeIP
,
config
.
NodeUdpPort
,
config
.
MaxTries
,
config
.
M
axTries
,
sets
.
NewString
())
By
(
fmt
.
Sprintf
(
"dialing(udp) %v (node) --> %v:%v (nodeIP)"
,
config
.
nodeIP
,
config
.
nodeIP
,
config
.
n
odeUdpPort
))
config
.
dialFromNode
(
"udp"
,
config
.
nodeIP
,
config
.
nodeUdpPort
,
config
.
maxTries
,
config
.
m
axTries
,
sets
.
NewString
())
})
// TODO: Test sessionAffinity #31712
})
...
...
test/
utils
/networking_utils.go
→
test/
e2e
/networking_utils.go
View file @
b7d76023
...
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package
utils
package
e2e
import
(
"encoding/json"
...
...
@@ -38,13 +38,13 @@ import (
)
const
(
E
ndpointHttpPort
=
8080
E
ndpointUdpPort
=
8081
T
estContainerHttpPort
=
8080
C
lusterHttpPort
=
80
C
lusterUdpPort
=
90
N
etexecImageName
=
"gcr.io/google_containers/netexec:1.5"
H
ostexecImageName
=
"gcr.io/google_containers/hostexec:1.2"
e
ndpointHttpPort
=
8080
e
ndpointUdpPort
=
8081
t
estContainerHttpPort
=
8080
c
lusterHttpPort
=
80
c
lusterUdpPort
=
90
n
etexecImageName
=
"gcr.io/google_containers/netexec:1.5"
h
ostexecImageName
=
"gcr.io/google_containers/hostexec:1.2"
testPodName
=
"test-container-pod"
hostTestPodName
=
"host-test-container-pod"
nodePortServiceName
=
"node-port-service"
...
...
@@ -58,79 +58,61 @@ const (
// NewNetworkingTestConfig creates and sets up a new test config helper.
func
NewNetworkingTestConfig
(
f
*
framework
.
Framework
)
*
NetworkingTestConfig
{
config
:=
&
NetworkingTestConfig
{
f
:
f
,
Namespace
:
f
.
Namespace
.
Name
}
By
(
fmt
.
Sprintf
(
"Performing setup for networking test in namespace %v"
,
config
.
Namespace
))
config
.
setup
(
getServiceSelector
()
)
config
:=
&
NetworkingTestConfig
{
f
:
f
,
ns
:
f
.
Namespace
.
Name
}
By
(
fmt
.
Sprintf
(
"Performing setup for networking test in namespace %v"
,
config
.
ns
))
config
.
setup
()
return
config
}
// NewNetworkingTestNodeE2EConfig creates and sets up a new test config helper for Node E2E.
func
NewCoreNetworkingTestConfig
(
f
*
framework
.
Framework
)
*
NetworkingTestConfig
{
config
:=
&
NetworkingTestConfig
{
f
:
f
,
Namespace
:
f
.
Namespace
.
Name
}
By
(
fmt
.
Sprintf
(
"Performing setup for networking test in namespace %v"
,
config
.
Namespace
))
config
.
setupCore
(
getServiceSelector
())
return
config
}
func
getServiceSelector
()
map
[
string
]
string
{
By
(
"creating a selector"
)
selectorName
:=
"selector-"
+
string
(
uuid
.
NewUUID
())
serviceSelector
:=
map
[
string
]
string
{
selectorName
:
"true"
,
}
return
serviceSelector
}
// NetworkingTestConfig is a convenience class around some utility methods
// for testing kubeproxy/networking/services/endpoints.
type
NetworkingTestConfig
struct
{
//
T
estContaienrPod is a test pod running the netexec image. It is capable
//
t
estContaienrPod is a test pod running the netexec image. It is capable
// of executing tcp/udp requests against ip:port.
T
estContainerPod
*
api
.
Pod
//
H
ostTestContainerPod is a pod running with hostNetworking=true, and the
t
estContainerPod
*
api
.
Pod
//
h
ostTestContainerPod is a pod running with hostNetworking=true, and the
// hostexec image.
H
ostTestContainerPod
*
api
.
Pod
//
E
ndpointPods are the pods belonging to the Service created by this
h
ostTestContainerPod
*
api
.
Pod
//
e
ndpointPods are the pods belonging to the Service created by this
// test config. Each invocation of `setup` creates a service with
// 1 pod per node running the netexecImage.
E
ndpointPods
[]
*
api
.
Pod
e
ndpointPods
[]
*
api
.
Pod
f
*
framework
.
Framework
podClient
*
framework
.
PodClient
// NodePortService is a Service with Type=NodePort spanning over all
// nodePortService is a Service with Type=NodePort spanning over all
// endpointPods.
N
odePortService
*
api
.
Service
//
E
xternalAddrs is a list of external IPs of nodes in the cluster.
E
xternalAddrs
[]
string
//
N
odes is a list of nodes in the cluster.
N
odes
[]
api
.
Node
//
M
axTries is the number of retries tolerated for tests run against
n
odePortService
*
api
.
Service
//
e
xternalAddrs is a list of external IPs of nodes in the cluster.
e
xternalAddrs
[]
string
//
n
odes is a list of nodes in the cluster.
n
odes
[]
api
.
Node
//
m
axTries is the number of retries tolerated for tests run against
// endpoints and services created by this config.
M
axTries
int
// The
C
lusterIP of the Service reated by this test config.
C
lusterIP
string
m
axTries
int
// The
c
lusterIP of the Service reated by this test config.
c
lusterIP
string
// External ip of first node for use in nodePort testing.
N
odeIP
string
n
odeIP
string
// The http/udp nodePorts of the Service.
N
odeHttpPort
int
N
odeUdpPort
int
n
odeHttpPort
int
n
odeUdpPort
int
// The kubernetes namespace within which all resources for this
// config are created
Namespace
string
ns
string
}
func
(
config
*
NetworkingTestConfig
)
D
ialFromEndpointContainer
(
protocol
,
targetIP
string
,
targetPort
,
maxTries
,
minTries
int
,
expectedEps
sets
.
String
)
{
config
.
DialFromContainer
(
protocol
,
config
.
EndpointPods
[
0
]
.
Status
.
PodIP
,
targetIP
,
E
ndpointHttpPort
,
targetPort
,
maxTries
,
minTries
,
expectedEps
)
func
(
config
*
NetworkingTestConfig
)
d
ialFromEndpointContainer
(
protocol
,
targetIP
string
,
targetPort
,
maxTries
,
minTries
int
,
expectedEps
sets
.
String
)
{
config
.
dialFromContainer
(
protocol
,
config
.
endpointPods
[
0
]
.
Status
.
PodIP
,
targetIP
,
e
ndpointHttpPort
,
targetPort
,
maxTries
,
minTries
,
expectedEps
)
}
func
(
config
*
NetworkingTestConfig
)
D
ialFromTestContainer
(
protocol
,
targetIP
string
,
targetPort
,
maxTries
,
minTries
int
,
expectedEps
sets
.
String
)
{
config
.
DialFromContainer
(
protocol
,
config
.
TestContainerPod
.
Status
.
PodIP
,
targetIP
,
T
estContainerHttpPort
,
targetPort
,
maxTries
,
minTries
,
expectedEps
)
func
(
config
*
NetworkingTestConfig
)
d
ialFromTestContainer
(
protocol
,
targetIP
string
,
targetPort
,
maxTries
,
minTries
int
,
expectedEps
sets
.
String
)
{
config
.
dialFromContainer
(
protocol
,
config
.
testContainerPod
.
Status
.
PodIP
,
targetIP
,
t
estContainerHttpPort
,
targetPort
,
maxTries
,
minTries
,
expectedEps
)
}
// diagnoseMissingEndpoints prints debug information about the endpoints that
// are NOT in the given list of foundEndpoints. These are the endpoints we
// expected a response from.
func
(
config
*
NetworkingTestConfig
)
diagnoseMissingEndpoints
(
foundEndpoints
sets
.
String
)
{
for
_
,
e
:=
range
config
.
E
ndpointPods
{
for
_
,
e
:=
range
config
.
e
ndpointPods
{
if
foundEndpoints
.
Has
(
e
.
Name
)
{
continue
}
...
...
@@ -141,16 +123,16 @@ func (config *NetworkingTestConfig) diagnoseMissingEndpoints(foundEndpoints sets
}
}
//
E
ndpointHostnames returns a set of hostnames for existing endpoints.
func
(
config
*
NetworkingTestConfig
)
E
ndpointHostnames
()
sets
.
String
{
//
e
ndpointHostnames returns a set of hostnames for existing endpoints.
func
(
config
*
NetworkingTestConfig
)
e
ndpointHostnames
()
sets
.
String
{
expectedEps
:=
sets
.
NewString
()
for
_
,
p
:=
range
config
.
E
ndpointPods
{
for
_
,
p
:=
range
config
.
e
ndpointPods
{
expectedEps
.
Insert
(
p
.
Name
)
}
return
expectedEps
}
//
D
ialFromContainers executes a curl via kubectl exec in a test container,
//
d
ialFromContainers executes a curl via kubectl exec in a test container,
// which might then translate to a tcp or udp request based on the protocol
// argument in the url.
// - minTries is the minimum number of curl attempts required before declaring
...
...
@@ -163,7 +145,7 @@ func (config *NetworkingTestConfig) EndpointHostnames() sets.String {
// maxTries == minTries will confirm that we see the expected endpoints and no
// more for maxTries. Use this if you want to eg: fail a readiness check on a
// pod and confirm it doesn't show up as an endpoint.
func
(
config
*
NetworkingTestConfig
)
D
ialFromContainer
(
protocol
,
containerIP
,
targetIP
string
,
containerHttpPort
,
targetPort
,
maxTries
,
minTries
int
,
expectedEps
sets
.
String
)
{
func
(
config
*
NetworkingTestConfig
)
d
ialFromContainer
(
protocol
,
containerIP
,
targetIP
string
,
containerHttpPort
,
targetPort
,
maxTries
,
minTries
int
,
expectedEps
sets
.
String
)
{
cmd
:=
fmt
.
Sprintf
(
"curl -q -s 'http://%s:%d/dial?request=hostName&protocol=%s&host=%s&port=%d&tries=1'"
,
containerIP
,
containerHttpPort
,
...
...
@@ -174,19 +156,23 @@ func (config *NetworkingTestConfig) DialFromContainer(protocol, containerIP, tar
eps
:=
sets
.
NewString
()
for
i
:=
0
;
i
<
maxTries
;
i
++
{
stdout
:=
config
.
f
.
ExecShellInPod
(
config
.
HostTestContainerPod
.
Name
,
cmd
)
var
output
map
[
string
][]
string
if
err
:=
json
.
Unmarshal
([]
byte
(
stdout
),
&
output
);
err
!=
nil
{
framework
.
Logf
(
"WARNING: Failed to unmarshal curl response. Cmd %v run in %v, output: %s, err: %v"
,
cmd
,
config
.
HostTestContainerPod
.
Name
,
stdout
,
err
)
continue
}
for
_
,
hostName
:=
range
output
[
"responses"
]
{
eps
.
Insert
(
hostName
)
stdout
,
err
:=
framework
.
RunHostCmd
(
config
.
ns
,
config
.
hostTestContainerPod
.
Name
,
cmd
)
if
err
!=
nil
{
// A failure to kubectl exec counts as a try, not a hard fail.
// Also note that we will keep failing for maxTries in tests where
// we confirm unreachability.
framework
.
Logf
(
"Failed to execute %v: %v"
,
cmd
,
err
)
}
else
{
var
output
map
[
string
][]
string
if
err
:=
json
.
Unmarshal
([]
byte
(
stdout
),
&
output
);
err
!=
nil
{
framework
.
Logf
(
"WARNING: Failed to unmarshal curl response. Cmd %v run in %v, output: %s, err: %v"
,
cmd
,
config
.
hostTestContainerPod
.
Name
,
stdout
,
err
)
continue
}
for
_
,
hostName
:=
range
output
[
"responses"
]
{
eps
.
Insert
(
hostName
)
}
}
framework
.
Logf
(
"Waiting for endpoints: %v"
,
expectedEps
.
Difference
(
eps
))
// Check against i+1 so we exit if minTries == maxTries.
...
...
@@ -199,7 +185,7 @@ func (config *NetworkingTestConfig) DialFromContainer(protocol, containerIP, tar
framework
.
Failf
(
"Failed to find expected endpoints:
\n
Tries %d
\n
Command %v
\n
retrieved %v
\n
expected %v
\n
"
,
minTries
,
cmd
,
eps
,
expectedEps
)
}
//
D
ialFromNode executes a tcp or udp request based on protocol via kubectl exec
//
d
ialFromNode executes a tcp or udp request based on protocol via kubectl exec
// in a test container running with host networking.
// - minTries is the minimum number of curl attempts required before declaring
// success. Set to 0 if you'd like to return as soon as all endpoints respond
...
...
@@ -209,7 +195,7 @@ func (config *NetworkingTestConfig) DialFromContainer(protocol, containerIP, tar
// maxTries == minTries will confirm that we see the expected endpoints and no
// more for maxTries. Use this if you want to eg: fail a readiness check on a
// pod and confirm it doesn't show up as an endpoint.
func
(
config
*
NetworkingTestConfig
)
D
ialFromNode
(
protocol
,
targetIP
string
,
targetPort
,
maxTries
,
minTries
int
,
expectedEps
sets
.
String
)
{
func
(
config
*
NetworkingTestConfig
)
d
ialFromNode
(
protocol
,
targetIP
string
,
targetPort
,
maxTries
,
minTries
int
,
expectedEps
sets
.
String
)
{
var
cmd
string
if
protocol
==
"udp"
{
cmd
=
fmt
.
Sprintf
(
"echo 'hostName' | timeout -t 3 nc -w 1 -u %s %d"
,
targetIP
,
targetPort
)
...
...
@@ -224,8 +210,15 @@ func (config *NetworkingTestConfig) DialFromNode(protocol, targetIP string, targ
filterCmd
:=
fmt
.
Sprintf
(
"%s | grep -v '^
\\
s*$'"
,
cmd
)
for
i
:=
0
;
i
<
maxTries
;
i
++
{
stdout
:=
config
.
f
.
ExecShellInPod
(
config
.
HostTestContainerPod
.
Name
,
filterCmd
)
eps
.
Insert
(
strings
.
TrimSpace
(
stdout
))
stdout
,
err
:=
framework
.
RunHostCmd
(
config
.
ns
,
config
.
hostTestContainerPod
.
Name
,
filterCmd
)
if
err
!=
nil
{
// A failure to kubectl exec counts as a try, not a hard fail.
// Also note that we will keep failing for maxTries in tests where
// we confirm unreachability.
framework
.
Logf
(
"Failed to execute %v: %v"
,
filterCmd
,
err
)
}
else
{
eps
.
Insert
(
strings
.
TrimSpace
(
stdout
))
}
framework
.
Logf
(
"Waiting for %+v endpoints, got endpoints %+v"
,
expectedEps
.
Difference
(
eps
),
eps
)
// Check against i+1 so we exit if minTries == maxTries.
...
...
@@ -238,13 +231,13 @@ func (config *NetworkingTestConfig) DialFromNode(protocol, targetIP string, targ
framework
.
Failf
(
"Failed to find expected endpoints:
\n
Tries %d
\n
Command %v
\n
retrieved %v
\n
expected %v
\n
"
,
minTries
,
cmd
,
eps
,
expectedEps
)
}
//
G
etSelfURL executes a curl against the given path via kubectl exec into a
//
g
etSelfURL executes a curl against the given path via kubectl exec into a
// test container running with host networking, and fails if the output
// doesn't match the expected string.
func
(
config
*
NetworkingTestConfig
)
G
etSelfURL
(
path
string
,
expected
string
)
{
func
(
config
*
NetworkingTestConfig
)
g
etSelfURL
(
path
string
,
expected
string
)
{
cmd
:=
fmt
.
Sprintf
(
"curl -q -s --connect-timeout 1 http://localhost:10249%s"
,
path
)
By
(
fmt
.
Sprintf
(
"Getting kube-proxy self URL %s"
,
path
))
stdout
:=
framework
.
RunHostCmdOrDie
(
config
.
Namespace
,
config
.
H
ostTestContainerPod
.
Name
,
cmd
)
stdout
:=
framework
.
RunHostCmdOrDie
(
config
.
ns
,
config
.
h
ostTestContainerPod
.
Name
,
cmd
)
Expect
(
strings
.
Contains
(
stdout
,
expected
))
.
To
(
BeTrue
())
}
...
...
@@ -258,7 +251,7 @@ func (config *NetworkingTestConfig) createNetShellPodSpec(podName string, node s
Handler
:
api
.
Handler
{
HTTPGet
:
&
api
.
HTTPGetAction
{
Path
:
"/healthz"
,
Port
:
intstr
.
IntOrString
{
IntVal
:
E
ndpointHttpPort
},
Port
:
intstr
.
IntOrString
{
IntVal
:
e
ndpointHttpPort
},
},
},
}
...
...
@@ -269,27 +262,27 @@ func (config *NetworkingTestConfig) createNetShellPodSpec(podName string, node s
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
podName
,
Namespace
:
config
.
Namespace
,
Namespace
:
config
.
ns
,
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"webserver"
,
Image
:
N
etexecImageName
,
Image
:
n
etexecImageName
,
ImagePullPolicy
:
api
.
PullIfNotPresent
,
Command
:
[]
string
{
"/netexec"
,
fmt
.
Sprintf
(
"--http-port=%d"
,
E
ndpointHttpPort
),
fmt
.
Sprintf
(
"--udp-port=%d"
,
E
ndpointUdpPort
),
fmt
.
Sprintf
(
"--http-port=%d"
,
e
ndpointHttpPort
),
fmt
.
Sprintf
(
"--udp-port=%d"
,
e
ndpointUdpPort
),
},
Ports
:
[]
api
.
ContainerPort
{
{
Name
:
"http"
,
ContainerPort
:
E
ndpointHttpPort
,
ContainerPort
:
e
ndpointHttpPort
,
},
{
Name
:
"udp"
,
ContainerPort
:
E
ndpointUdpPort
,
ContainerPort
:
e
ndpointUdpPort
,
Protocol
:
api
.
ProtocolUDP
,
},
},
...
...
@@ -311,23 +304,23 @@ func (config *NetworkingTestConfig) createTestPodSpec() *api.Pod {
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
testPodName
,
Namespace
:
config
.
Namespace
,
Namespace
:
config
.
ns
,
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"webserver"
,
Image
:
N
etexecImageName
,
Image
:
n
etexecImageName
,
ImagePullPolicy
:
api
.
PullIfNotPresent
,
Command
:
[]
string
{
"/netexec"
,
fmt
.
Sprintf
(
"--http-port=%d"
,
E
ndpointHttpPort
),
fmt
.
Sprintf
(
"--udp-port=%d"
,
E
ndpointUdpPort
),
fmt
.
Sprintf
(
"--http-port=%d"
,
e
ndpointHttpPort
),
fmt
.
Sprintf
(
"--udp-port=%d"
,
e
ndpointUdpPort
),
},
Ports
:
[]
api
.
ContainerPort
{
{
Name
:
"http"
,
ContainerPort
:
T
estContainerHttpPort
,
ContainerPort
:
t
estContainerHttpPort
,
},
},
},
...
...
@@ -345,24 +338,24 @@ func (config *NetworkingTestConfig) createNodePortService(selector map[string]st
Spec
:
api
.
ServiceSpec
{
Type
:
api
.
ServiceTypeNodePort
,
Ports
:
[]
api
.
ServicePort
{
{
Port
:
ClusterHttpPort
,
Name
:
"http"
,
Protocol
:
api
.
ProtocolTCP
,
TargetPort
:
intstr
.
FromInt
(
E
ndpointHttpPort
)},
{
Port
:
ClusterUdpPort
,
Name
:
"udp"
,
Protocol
:
api
.
ProtocolUDP
,
TargetPort
:
intstr
.
FromInt
(
E
ndpointUdpPort
)},
{
Port
:
clusterHttpPort
,
Name
:
"http"
,
Protocol
:
api
.
ProtocolTCP
,
TargetPort
:
intstr
.
FromInt
(
e
ndpointHttpPort
)},
{
Port
:
clusterUdpPort
,
Name
:
"udp"
,
Protocol
:
api
.
ProtocolUDP
,
TargetPort
:
intstr
.
FromInt
(
e
ndpointUdpPort
)},
},
Selector
:
selector
,
},
}
config
.
N
odePortService
=
config
.
createService
(
serviceSpec
)
config
.
n
odePortService
=
config
.
createService
(
serviceSpec
)
}
func
(
config
*
NetworkingTestConfig
)
D
eleteNodePortService
()
{
err
:=
config
.
getServiceClient
()
.
Delete
(
config
.
N
odePortService
.
Name
)
func
(
config
*
NetworkingTestConfig
)
d
eleteNodePortService
()
{
err
:=
config
.
getServiceClient
()
.
Delete
(
config
.
n
odePortService
.
Name
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
"error while deleting NodePortService. err:%v)"
,
err
)
time
.
Sleep
(
15
*
time
.
Second
)
// wait for kube-proxy to catch up with the service being deleted.
}
func
(
config
*
NetworkingTestConfig
)
createTestPods
()
{
testContainerPod
:=
config
.
createTestPodSpec
()
hostTestContainerPod
:=
framework
.
NewHostExecPodSpec
(
config
.
Namespace
,
hostTestPodName
)
hostTestContainerPod
:=
framework
.
NewHostExecPodSpec
(
config
.
ns
,
hostTestPodName
)
config
.
createPod
(
testContainerPod
)
config
.
createPod
(
hostTestContainerPod
)
...
...
@@ -371,12 +364,12 @@ func (config *NetworkingTestConfig) createTestPods() {
framework
.
ExpectNoError
(
config
.
f
.
WaitForPodRunning
(
hostTestContainerPod
.
Name
))
var
err
error
config
.
T
estContainerPod
,
err
=
config
.
getPodClient
()
.
Get
(
testContainerPod
.
Name
)
config
.
t
estContainerPod
,
err
=
config
.
getPodClient
()
.
Get
(
testContainerPod
.
Name
)
if
err
!=
nil
{
framework
.
Failf
(
"Failed to retrieve %s pod: %v"
,
testContainerPod
.
Name
,
err
)
}
config
.
H
ostTestContainerPod
,
err
=
config
.
getPodClient
()
.
Get
(
hostTestContainerPod
.
Name
)
config
.
h
ostTestContainerPod
,
err
=
config
.
getPodClient
()
.
Get
(
hostTestContainerPod
.
Name
)
if
err
!=
nil
{
framework
.
Failf
(
"Failed to retrieve %s pod: %v"
,
hostTestContainerPod
.
Name
,
err
)
}
...
...
@@ -386,7 +379,7 @@ func (config *NetworkingTestConfig) createService(serviceSpec *api.Service) *api
_
,
err
:=
config
.
getServiceClient
()
.
Create
(
serviceSpec
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
fmt
.
Sprintf
(
"Failed to create %s service: %v"
,
serviceSpec
.
Name
,
err
))
err
=
framework
.
WaitForService
(
config
.
f
.
Client
,
config
.
Namespace
,
serviceSpec
.
Name
,
true
,
5
*
time
.
Second
,
45
*
time
.
Second
)
err
=
framework
.
WaitForService
(
config
.
f
.
Client
,
config
.
ns
,
serviceSpec
.
Name
,
true
,
5
*
time
.
Second
,
45
*
time
.
Second
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
(),
fmt
.
Sprintf
(
"error while waiting for service:%s err: %v"
,
serviceSpec
.
Name
,
err
))
createdService
,
err
:=
config
.
getServiceClient
()
.
Get
(
serviceSpec
.
Name
)
...
...
@@ -395,50 +388,48 @@ func (config *NetworkingTestConfig) createService(serviceSpec *api.Service) *api
return
createdService
}
// setupCore sets up the pods and core test config
// mainly for simplified node e2e setup
func
(
config
*
NetworkingTestConfig
)
setupCore
(
selector
map
[
string
]
string
)
{
By
(
"Creating the service pods in kubernetes"
)
podName
:=
"netserver"
config
.
EndpointPods
=
config
.
createNetProxyPods
(
podName
,
selector
)
By
(
"Creating test pods"
)
config
.
createTestPods
()
epCount
:=
len
(
config
.
EndpointPods
)
config
.
MaxTries
=
epCount
*
epCount
+
testTries
}
// setup includes setupCore and also sets up services
func
(
config
*
NetworkingTestConfig
)
setup
(
selector
map
[
string
]
string
)
{
config
.
setupCore
(
selector
)
func
(
config
*
NetworkingTestConfig
)
setup
()
{
By
(
"creating a selector"
)
selectorName
:=
"selector-"
+
string
(
uuid
.
NewUUID
())
serviceSelector
:=
map
[
string
]
string
{
selectorName
:
"true"
,
}
By
(
"Getting node addresses"
)
framework
.
ExpectNoError
(
framework
.
WaitForAllNodesSchedulable
(
config
.
f
.
Client
))
nodeList
:=
framework
.
GetReadySchedulableNodesOrDie
(
config
.
f
.
Client
)
config
.
E
xternalAddrs
=
framework
.
NodeAddresses
(
nodeList
,
api
.
NodeExternalIP
)
if
len
(
config
.
E
xternalAddrs
)
<
2
{
config
.
e
xternalAddrs
=
framework
.
NodeAddresses
(
nodeList
,
api
.
NodeExternalIP
)
if
len
(
config
.
e
xternalAddrs
)
<
2
{
// fall back to legacy IPs
config
.
E
xternalAddrs
=
framework
.
NodeAddresses
(
nodeList
,
api
.
NodeLegacyHostIP
)
config
.
e
xternalAddrs
=
framework
.
NodeAddresses
(
nodeList
,
api
.
NodeLegacyHostIP
)
}
Expect
(
len
(
config
.
ExternalAddrs
))
.
To
(
BeNumerically
(
">="
,
2
),
fmt
.
Sprintf
(
"At least two nodes necessary with an external or LegacyHostIP"
))
config
.
Nodes
=
nodeList
.
Items
Expect
(
len
(
config
.
externalAddrs
))
.
To
(
BeNumerically
(
">="
,
2
),
fmt
.
Sprintf
(
"At least two nodes necessary with an external or LegacyHostIP"
))
config
.
nodes
=
nodeList
.
Items
By
(
"Creating the service pods in kubernetes"
)
podName
:=
"netserver"
config
.
endpointPods
=
config
.
createNetProxyPods
(
podName
,
serviceSelector
)
By
(
"Creating the service on top of the pods in kubernetes"
)
config
.
createNodePortService
(
selector
)
config
.
createNodePortService
(
se
rviceSe
lector
)
for
_
,
p
:=
range
config
.
NodePortService
.
Spec
.
Ports
{
By
(
"Creating test pods"
)
config
.
createTestPods
()
for
_
,
p
:=
range
config
.
nodePortService
.
Spec
.
Ports
{
switch
p
.
Protocol
{
case
api
.
ProtocolUDP
:
config
.
N
odeUdpPort
=
int
(
p
.
NodePort
)
config
.
n
odeUdpPort
=
int
(
p
.
NodePort
)
case
api
.
ProtocolTCP
:
config
.
N
odeHttpPort
=
int
(
p
.
NodePort
)
config
.
n
odeHttpPort
=
int
(
p
.
NodePort
)
default
:
continue
}
}
config
.
ClusterIP
=
config
.
NodePortService
.
Spec
.
ClusterIP
config
.
NodeIP
=
config
.
ExternalAddrs
[
0
]
epCount
:=
len
(
config
.
endpointPods
)
config
.
maxTries
=
epCount
*
epCount
+
testTries
config
.
clusterIP
=
config
.
nodePortService
.
Spec
.
ClusterIP
config
.
nodeIP
=
config
.
externalAddrs
[
0
]
}
func
(
config
*
NetworkingTestConfig
)
cleanup
()
{
...
...
@@ -446,7 +437,7 @@ func (config *NetworkingTestConfig) cleanup() {
nsList
,
err
:=
nsClient
.
List
(
api
.
ListOptions
{})
if
err
==
nil
{
for
_
,
ns
:=
range
nsList
.
Items
{
if
strings
.
Contains
(
ns
.
Name
,
config
.
f
.
BaseName
)
&&
ns
.
Name
!=
config
.
Namespace
{
if
strings
.
Contains
(
ns
.
Name
,
config
.
f
.
BaseName
)
&&
ns
.
Name
!=
config
.
ns
{
nsClient
.
Delete
(
ns
.
Name
)
}
}
...
...
@@ -498,17 +489,17 @@ func (config *NetworkingTestConfig) createNetProxyPods(podName string, selector
return
runningPods
}
func
(
config
*
NetworkingTestConfig
)
D
eleteNetProxyPod
()
{
pod
:=
config
.
E
ndpointPods
[
0
]
func
(
config
*
NetworkingTestConfig
)
d
eleteNetProxyPod
()
{
pod
:=
config
.
e
ndpointPods
[
0
]
config
.
getPodClient
()
.
Delete
(
pod
.
Name
,
api
.
NewDeleteOptions
(
0
))
config
.
EndpointPods
=
config
.
E
ndpointPods
[
1
:
]
config
.
endpointPods
=
config
.
e
ndpointPods
[
1
:
]
// wait for pod being deleted.
err
:=
framework
.
WaitForPodToDisappear
(
config
.
f
.
Client
,
config
.
Namespace
,
pod
.
Name
,
labels
.
Everything
(),
time
.
Second
,
wait
.
ForeverTestTimeout
)
err
:=
framework
.
WaitForPodToDisappear
(
config
.
f
.
Client
,
config
.
ns
,
pod
.
Name
,
labels
.
Everything
(),
time
.
Second
,
wait
.
ForeverTestTimeout
)
if
err
!=
nil
{
framework
.
Failf
(
"Failed to delete %s pod: %v"
,
pod
.
Name
,
err
)
}
// wait for endpoint being removed.
err
=
framework
.
WaitForServiceEndpointsNum
(
config
.
f
.
Client
,
config
.
Namespace
,
nodePortServiceName
,
len
(
config
.
E
ndpointPods
),
time
.
Second
,
wait
.
ForeverTestTimeout
)
err
=
framework
.
WaitForServiceEndpointsNum
(
config
.
f
.
Client
,
config
.
ns
,
nodePortServiceName
,
len
(
config
.
e
ndpointPods
),
time
.
Second
,
wait
.
ForeverTestTimeout
)
if
err
!=
nil
{
framework
.
Failf
(
"Failed to remove endpoint from service: %s"
,
nodePortServiceName
)
}
...
...
@@ -517,18 +508,19 @@ func (config *NetworkingTestConfig) DeleteNetProxyPod() {
}
func
(
config
*
NetworkingTestConfig
)
createPod
(
pod
*
api
.
Pod
)
*
api
.
Pod
{
return
config
.
getPodClient
()
.
Create
(
pod
)
createdPod
,
err
:=
config
.
getPodClient
()
.
Create
(
pod
)
if
err
!=
nil
{
framework
.
Failf
(
"Failed to create %s pod: %v"
,
pod
.
Name
,
err
)
}
return
createdPod
}
func
(
config
*
NetworkingTestConfig
)
getPodClient
()
*
framework
.
PodClient
{
if
config
.
podClient
==
nil
{
config
.
podClient
=
config
.
f
.
PodClient
()
}
return
config
.
podClient
func
(
config
*
NetworkingTestConfig
)
getPodClient
()
client
.
PodInterface
{
return
config
.
f
.
Client
.
Pods
(
config
.
ns
)
}
func
(
config
*
NetworkingTestConfig
)
getServiceClient
()
client
.
ServiceInterface
{
return
config
.
f
.
Client
.
Services
(
config
.
Namespace
)
return
config
.
f
.
Client
.
Services
(
config
.
ns
)
}
func
(
config
*
NetworkingTestConfig
)
getNamespacesClient
()
client
.
NamespaceInterface
{
...
...
test/e2e_node/remote/remote.go
View file @
b7d76023
...
...
@@ -165,27 +165,6 @@ func RunRemote(archive string, host string, cleanup bool, junitFilePrefix string
return
""
,
false
,
err
}
// Configure iptables firewall rules
// TODO: consider calling bootstrap script to configure host based on OS
cmd
:=
getSshCommand
(
"&&"
,
`iptables -L INPUT | grep "Chain INPUT (policy DROP)"`
,
"(iptables -C INPUT -w -p TCP -j ACCEPT || iptables -A INPUT -w -p TCP -j ACCEPT)"
,
"(iptables -C INPUT -w -p UDP -j ACCEPT || iptables -A INPUT -w -p UDP -j ACCEPT)"
,
"(iptables -C INPUT -w -p ICMP -j ACCEPT || iptables -A INPUT -w -p ICMP -j ACCEPT)"
)
output
,
err
:=
RunSshCommand
(
"ssh"
,
GetHostnameOrIp
(
host
),
"--"
,
"sudo"
,
"sh"
,
"-c"
,
cmd
)
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to configured firewall: %v output: %v"
,
err
,
output
)
}
cmd
=
getSshCommand
(
"&&"
,
`iptables -L FORWARD | grep "Chain FORWARD (policy DROP)" > /dev/null`
,
"(iptables -C FORWARD -w -p TCP -j ACCEPT || iptables -A FORWARD -w -p TCP -j ACCEPT)"
,
"(iptables -C FORWARD -w -p UDP -j ACCEPT || iptables -A FORWARD -w -p UDP -j ACCEPT)"
,
"(iptables -C FORWARD -w -p ICMP -j ACCEPT || iptables -A FORWARD -w -p ICMP -j ACCEPT)"
)
output
,
err
=
RunSshCommand
(
"ssh"
,
GetHostnameOrIp
(
host
),
"--"
,
"sudo"
,
"sh"
,
"-c"
,
cmd
)
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to configured firewall: %v output: %v"
,
err
,
output
)
}
// Copy the archive to the staging directory
_
,
err
=
RunSshCommand
(
"scp"
,
archive
,
fmt
.
Sprintf
(
"%s:%s/"
,
GetHostnameOrIp
(
host
),
tmp
))
if
err
!=
nil
{
...
...
@@ -194,7 +173,7 @@ func RunRemote(archive string, host string, cleanup bool, junitFilePrefix string
}
// Kill any running node processes
cmd
=
getSshCommand
(
" ; "
,
cmd
:
=
getSshCommand
(
" ; "
,
"sudo pkill kubelet"
,
"sudo pkill kube-apiserver"
,
"sudo pkill etcd"
,
...
...
@@ -208,7 +187,7 @@ func RunRemote(archive string, host string, cleanup bool, junitFilePrefix string
// Extract the archive
cmd
=
getSshCommand
(
" && "
,
fmt
.
Sprintf
(
"cd %s"
,
tmp
),
fmt
.
Sprintf
(
"tar -xzvf ./%s"
,
archiveName
))
glog
.
Infof
(
"Extracting tar on %s"
,
host
)
output
,
err
=
RunSshCommand
(
"ssh"
,
GetHostnameOrIp
(
host
),
"--"
,
"sh"
,
"-c"
,
cmd
)
output
,
err
:
=
RunSshCommand
(
"ssh"
,
GetHostnameOrIp
(
host
),
"--"
,
"sh"
,
"-c"
,
cmd
)
if
err
!=
nil
{
// Exit failure with the error
return
""
,
false
,
err
...
...
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