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
09f00aeb
Commit
09f00aeb
authored
Mar 07, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #22303 from marun/expose-net-e2e-utils
Auto commit by PR queue bot
parents
9ac86270
d405718a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
88 deletions
+96
-88
networking.go
test/e2e/networking.go
+8
-88
util.go
test/e2e/util.go
+88
-0
No files found.
test/e2e/networking.go
View file @
09f00aeb
...
@@ -17,14 +17,12 @@ limitations under the License.
...
@@ -17,14 +17,12 @@ limitations under the License.
package
e2e
package
e2e
import
(
import
(
"errors"
"fmt"
"fmt"
"net/http"
"net/http"
"strings"
"strings"
"time"
"time"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/intstr"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/ginkgo"
...
@@ -52,7 +50,7 @@ var _ = Describe("Networking", func() {
...
@@ -52,7 +50,7 @@ var _ = Describe("Networking", func() {
It
(
"should provide Internet connection for containers [Conformance]"
,
func
()
{
It
(
"should provide Internet connection for containers [Conformance]"
,
func
()
{
By
(
"Running container which tries to wget google.com"
)
By
(
"Running container which tries to wget google.com"
)
expectNoError
(
c
heckConnectivityToHost
(
f
,
""
,
"wget-test"
,
"google.com"
))
expectNoError
(
C
heckConnectivityToHost
(
f
,
""
,
"wget-test"
,
"google.com"
))
})
})
// First test because it has no dependencies on variables created later on.
// First test because it has no dependencies on variables created later on.
...
@@ -112,7 +110,7 @@ var _ = Describe("Networking", func() {
...
@@ -112,7 +110,7 @@ var _ = Describe("Networking", func() {
By
(
"Creating a webserver (pending) pod on each node"
)
By
(
"Creating a webserver (pending) pod on each node"
)
nodes
,
err
:=
g
etReadyNodes
(
f
)
nodes
,
err
:=
G
etReadyNodes
(
f
)
expectNoError
(
err
)
expectNoError
(
err
)
if
len
(
nodes
.
Items
)
==
1
{
if
len
(
nodes
.
Items
)
==
1
{
...
@@ -220,17 +218,17 @@ var _ = Describe("Networking", func() {
...
@@ -220,17 +218,17 @@ var _ = Describe("Networking", func() {
It
(
"should function for pod communication on a single node"
,
func
()
{
It
(
"should function for pod communication on a single node"
,
func
()
{
By
(
"Picking a node"
)
By
(
"Picking a node"
)
nodes
,
err
:=
g
etReadyNodes
(
f
)
nodes
,
err
:=
G
etReadyNodes
(
f
)
expectNoError
(
err
)
expectNoError
(
err
)
node
:=
nodes
.
Items
[
0
]
node
:=
nodes
.
Items
[
0
]
By
(
"Creating a webserver pod"
)
By
(
"Creating a webserver pod"
)
podName
:=
"same-node-webserver"
podName
:=
"same-node-webserver"
defer
f
.
Client
.
Pods
(
f
.
Namespace
.
Name
)
.
Delete
(
podName
,
nil
)
defer
f
.
Client
.
Pods
(
f
.
Namespace
.
Name
)
.
Delete
(
podName
,
nil
)
ip
:=
l
aunchWebserverPod
(
f
,
podName
,
node
.
Name
)
ip
:=
L
aunchWebserverPod
(
f
,
podName
,
node
.
Name
)
By
(
"Checking that the webserver is accessible from a pod on the same node"
)
By
(
"Checking that the webserver is accessible from a pod on the same node"
)
expectNoError
(
c
heckConnectivityToHost
(
f
,
node
.
Name
,
"same-node-wget"
,
ip
))
expectNoError
(
C
heckConnectivityToHost
(
f
,
node
.
Name
,
"same-node-wget"
,
ip
))
})
})
It
(
"should function for pod communication between nodes"
,
func
()
{
It
(
"should function for pod communication between nodes"
,
func
()
{
...
@@ -238,7 +236,7 @@ var _ = Describe("Networking", func() {
...
@@ -238,7 +236,7 @@ var _ = Describe("Networking", func() {
podClient
:=
f
.
Client
.
Pods
(
f
.
Namespace
.
Name
)
podClient
:=
f
.
Client
.
Pods
(
f
.
Namespace
.
Name
)
By
(
"Picking multiple nodes"
)
By
(
"Picking multiple nodes"
)
nodes
,
err
:=
g
etReadyNodes
(
f
)
nodes
,
err
:=
G
etReadyNodes
(
f
)
expectNoError
(
err
)
expectNoError
(
err
)
if
len
(
nodes
.
Items
)
==
1
{
if
len
(
nodes
.
Items
)
==
1
{
...
@@ -251,10 +249,10 @@ var _ = Describe("Networking", func() {
...
@@ -251,10 +249,10 @@ var _ = Describe("Networking", func() {
By
(
"Creating a webserver pod"
)
By
(
"Creating a webserver pod"
)
podName
:=
"different-node-webserver"
podName
:=
"different-node-webserver"
defer
podClient
.
Delete
(
podName
,
nil
)
defer
podClient
.
Delete
(
podName
,
nil
)
ip
:=
l
aunchWebserverPod
(
f
,
podName
,
node1
.
Name
)
ip
:=
L
aunchWebserverPod
(
f
,
podName
,
node1
.
Name
)
By
(
"Checking that the webserver is accessible from a pod on a different node"
)
By
(
"Checking that the webserver is accessible from a pod on a different node"
)
expectNoError
(
c
heckConnectivityToHost
(
f
,
node2
.
Name
,
"different-node-wget"
,
ip
))
expectNoError
(
C
heckConnectivityToHost
(
f
,
node2
.
Name
,
"different-node-wget"
,
ip
))
})
})
})
})
})
})
...
@@ -298,81 +296,3 @@ func LaunchNetTestPodPerNode(f *Framework, nodes *api.NodeList, name, version st
...
@@ -298,81 +296,3 @@ func LaunchNetTestPodPerNode(f *Framework, nodes *api.NodeList, name, version st
}
}
return
podNames
return
podNames
}
}
func
getReadyNodes
(
f
*
Framework
)
(
nodes
*
api
.
NodeList
,
err
error
)
{
nodes
=
ListSchedulableNodesOrDie
(
f
.
Client
)
// previous tests may have cause failures of some nodes. Let's skip
// 'Not Ready' nodes, just in case (there is no need to fail the test).
filterNodes
(
nodes
,
func
(
node
api
.
Node
)
bool
{
return
!
node
.
Spec
.
Unschedulable
&&
isNodeConditionSetAsExpected
(
&
node
,
api
.
NodeReady
,
true
)
})
if
len
(
nodes
.
Items
)
==
0
{
return
nil
,
errors
.
New
(
"No Ready nodes found."
)
}
return
nodes
,
nil
}
func
launchWebserverPod
(
f
*
Framework
,
podName
,
nodeName
string
)
(
ip
string
)
{
containerName
:=
fmt
.
Sprintf
(
"%s-container"
,
podName
)
port
:=
8080
pod
:=
&
api
.
Pod
{
TypeMeta
:
unversioned
.
TypeMeta
{
Kind
:
"Pod"
,
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
podName
,
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
containerName
,
Image
:
"gcr.io/google_containers/porter:cd5cb5791ebaa8641955f0e8c2a9bed669b1eaab"
,
Env
:
[]
api
.
EnvVar
{{
Name
:
fmt
.
Sprintf
(
"SERVE_PORT_%d"
,
port
),
Value
:
"foo"
}},
Ports
:
[]
api
.
ContainerPort
{{
ContainerPort
:
port
}},
},
},
NodeName
:
nodeName
,
RestartPolicy
:
api
.
RestartPolicyNever
,
},
}
podClient
:=
f
.
Client
.
Pods
(
f
.
Namespace
.
Name
)
_
,
err
:=
podClient
.
Create
(
pod
)
expectNoError
(
err
)
expectNoError
(
f
.
WaitForPodRunning
(
podName
))
createdPod
,
err
:=
podClient
.
Get
(
podName
)
expectNoError
(
err
)
ip
=
fmt
.
Sprintf
(
"%s:%d"
,
createdPod
.
Status
.
PodIP
,
port
)
Logf
(
"Target pod IP:port is %s"
,
ip
)
return
}
func
checkConnectivityToHost
(
f
*
Framework
,
nodeName
,
podName
,
host
string
)
error
{
contName
:=
fmt
.
Sprintf
(
"%s-container"
,
podName
)
pod
:=
&
api
.
Pod
{
TypeMeta
:
unversioned
.
TypeMeta
{
Kind
:
"Pod"
,
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
podName
,
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
contName
,
Image
:
"gcr.io/google_containers/busybox:1.24"
,
Command
:
[]
string
{
"wget"
,
"-s"
,
host
},
},
},
NodeName
:
nodeName
,
RestartPolicy
:
api
.
RestartPolicyNever
,
},
}
podClient
:=
f
.
Client
.
Pods
(
f
.
Namespace
.
Name
)
_
,
err
:=
podClient
.
Create
(
pod
)
if
err
!=
nil
{
return
err
}
defer
podClient
.
Delete
(
podName
,
nil
)
return
waitForPodSuccessInNamespace
(
f
.
Client
,
podName
,
contName
,
f
.
Namespace
.
Name
)
}
test/e2e/util.go
View file @
09f00aeb
...
@@ -18,6 +18,7 @@ package e2e
...
@@ -18,6 +18,7 @@ package e2e
import
(
import
(
"bytes"
"bytes"
"errors"
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"io/ioutil"
...
@@ -3455,3 +3456,90 @@ func checkPodHashLabel(pods *api.PodList) error {
...
@@ -3455,3 +3456,90 @@ func checkPodHashLabel(pods *api.PodList) error {
}
}
return
nil
return
nil
}
}
// GetReadyNodes retrieves a list of schedulable nodes whose condition
// is Ready. An error will be returned if no such nodes are found.
func
GetReadyNodes
(
f
*
Framework
)
(
nodes
*
api
.
NodeList
,
err
error
)
{
nodes
=
ListSchedulableNodesOrDie
(
f
.
Client
)
// previous tests may have cause failures of some nodes. Let's skip
// 'Not Ready' nodes, just in case (there is no need to fail the test).
filterNodes
(
nodes
,
func
(
node
api
.
Node
)
bool
{
return
!
node
.
Spec
.
Unschedulable
&&
isNodeConditionSetAsExpected
(
&
node
,
api
.
NodeReady
,
true
)
})
if
len
(
nodes
.
Items
)
==
0
{
return
nil
,
errors
.
New
(
"No Ready nodes found."
)
}
return
nodes
,
nil
}
// LaunchWebserverPod launches a pod serving http on port 8080 to act
// as the target for networking connectivity checks. The ip address
// of the created pod will be returned if the pod is launched
// successfully.
func
LaunchWebserverPod
(
f
*
Framework
,
podName
,
nodeName
string
)
(
ip
string
)
{
containerName
:=
fmt
.
Sprintf
(
"%s-container"
,
podName
)
port
:=
8080
pod
:=
&
api
.
Pod
{
TypeMeta
:
unversioned
.
TypeMeta
{
Kind
:
"Pod"
,
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
podName
,
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
containerName
,
Image
:
"gcr.io/google_containers/porter:cd5cb5791ebaa8641955f0e8c2a9bed669b1eaab"
,
Env
:
[]
api
.
EnvVar
{{
Name
:
fmt
.
Sprintf
(
"SERVE_PORT_%d"
,
port
),
Value
:
"foo"
}},
Ports
:
[]
api
.
ContainerPort
{{
ContainerPort
:
port
}},
},
},
NodeName
:
nodeName
,
RestartPolicy
:
api
.
RestartPolicyNever
,
},
}
podClient
:=
f
.
Client
.
Pods
(
f
.
Namespace
.
Name
)
_
,
err
:=
podClient
.
Create
(
pod
)
expectNoError
(
err
)
expectNoError
(
f
.
WaitForPodRunning
(
podName
))
createdPod
,
err
:=
podClient
.
Get
(
podName
)
expectNoError
(
err
)
ip
=
fmt
.
Sprintf
(
"%s:%d"
,
createdPod
.
Status
.
PodIP
,
port
)
Logf
(
"Target pod IP:port is %s"
,
ip
)
return
}
// CheckConnectivityToHost launches a pod running wget on the
// specified node to test connectivity to the specified host. An
// error will be returned if the host is not reachable from the pod.
func
CheckConnectivityToHost
(
f
*
Framework
,
nodeName
,
podName
,
host
string
)
error
{
contName
:=
fmt
.
Sprintf
(
"%s-container"
,
podName
)
pod
:=
&
api
.
Pod
{
TypeMeta
:
unversioned
.
TypeMeta
{
Kind
:
"Pod"
,
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
podName
,
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
contName
,
Image
:
"gcr.io/google_containers/busybox:1.24"
,
Command
:
[]
string
{
"wget"
,
"-s"
,
host
},
},
},
NodeName
:
nodeName
,
RestartPolicy
:
api
.
RestartPolicyNever
,
},
}
podClient
:=
f
.
Client
.
Pods
(
f
.
Namespace
.
Name
)
_
,
err
:=
podClient
.
Create
(
pod
)
if
err
!=
nil
{
return
err
}
defer
podClient
.
Delete
(
podName
,
nil
)
return
waitForPodSuccessInNamespace
(
f
.
Client
,
podName
,
contName
,
f
.
Namespace
.
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