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
7823d615
Commit
7823d615
authored
Feb 01, 2016
by
Minhan Xia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
put block/unblock network function into util
parent
5fe856c7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
38 deletions
+54
-38
resize_nodes.go
test/e2e/resize_nodes.go
+0
-38
util.go
test/e2e/util.go
+54
-0
No files found.
test/e2e/resize_nodes.go
View file @
7823d615
...
...
@@ -29,7 +29,6 @@ import (
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/wait"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
...
...
@@ -299,43 +298,6 @@ func verifyPods(c *client.Client, ns, name string, wantName bool, replicas int)
return
nil
}
func
blockNetwork
(
from
string
,
to
string
)
{
Logf
(
"block network traffic from %s to %s"
,
from
,
to
)
iptablesRule
:=
fmt
.
Sprintf
(
"OUTPUT --destination %s --jump REJECT"
,
to
)
dropCmd
:=
fmt
.
Sprintf
(
"sudo iptables --insert %s"
,
iptablesRule
)
if
result
,
err
:=
SSH
(
dropCmd
,
from
,
testContext
.
Provider
);
result
.
Code
!=
0
||
err
!=
nil
{
LogSSHResult
(
result
)
Failf
(
"Unexpected error: %v"
,
err
)
}
}
func
unblockNetwork
(
from
string
,
to
string
)
{
Logf
(
"Unblock network traffic from %s to %s"
,
from
,
to
)
iptablesRule
:=
fmt
.
Sprintf
(
"OUTPUT --destination %s --jump REJECT"
,
to
)
undropCmd
:=
fmt
.
Sprintf
(
"sudo iptables --delete %s"
,
iptablesRule
)
// Undrop command may fail if the rule has never been created.
// In such case we just lose 30 seconds, but the cluster is healthy.
// But if the rule had been created and removing it failed, the node is broken and
// not coming back. Subsequent tests will run or fewer nodes (some of the tests
// may fail). Manual intervention is required in such case (recreating the
// cluster solves the problem too).
err
:=
wait
.
Poll
(
time
.
Millisecond
*
100
,
time
.
Second
*
30
,
func
()
(
bool
,
error
)
{
result
,
err
:=
SSH
(
undropCmd
,
from
,
testContext
.
Provider
)
if
result
.
Code
==
0
&&
err
==
nil
{
return
true
,
nil
}
LogSSHResult
(
result
)
if
err
!=
nil
{
Logf
(
"Unexpected error: %v"
,
err
)
}
return
false
,
nil
})
if
err
!=
nil
{
Failf
(
"Failed to remove the iptable REJECT rule. Manual intervention is "
+
"required on host %s: remove rule %s, if exists"
,
from
,
iptablesRule
)
}
}
func
getMaster
(
c
*
client
.
Client
)
string
{
master
:=
""
switch
testContext
.
Provider
{
...
...
test/e2e/util.go
View file @
7823d615
...
...
@@ -2939,3 +2939,57 @@ func ensureGCELoadBalancerResourcesDeleted(ip, portRange string) error {
return
true
,
nil
})
}
// The following helper functions can block/unblock network from source
// host to destination host by manipulating iptable rules.
// This function assumes it can ssh to the source host.
//
// Caution:
// Recommend to input IP instead of hostnames. Using hostnames will cause iptables to
// do a DNS lookup to resolve the name to an IP address, which will
// slow down the test and cause it to fail if DNS is absent or broken.
//
// Suggested usage pattern:
// func foo() {
// ...
// defer unblockNetwork(from, to)
// blockNetwork(from, to)
// ...
// }
//
func
blockNetwork
(
from
string
,
to
string
)
{
Logf
(
"block network traffic from %s to %s"
,
from
,
to
)
iptablesRule
:=
fmt
.
Sprintf
(
"OUTPUT --destination %s --jump REJECT"
,
to
)
dropCmd
:=
fmt
.
Sprintf
(
"sudo iptables --insert %s"
,
iptablesRule
)
if
result
,
err
:=
SSH
(
dropCmd
,
from
,
testContext
.
Provider
);
result
.
Code
!=
0
||
err
!=
nil
{
LogSSHResult
(
result
)
Failf
(
"Unexpected error: %v"
,
err
)
}
}
func
unblockNetwork
(
from
string
,
to
string
)
{
Logf
(
"Unblock network traffic from %s to %s"
,
from
,
to
)
iptablesRule
:=
fmt
.
Sprintf
(
"OUTPUT --destination %s --jump REJECT"
,
to
)
undropCmd
:=
fmt
.
Sprintf
(
"sudo iptables --delete %s"
,
iptablesRule
)
// Undrop command may fail if the rule has never been created.
// In such case we just lose 30 seconds, but the cluster is healthy.
// But if the rule had been created and removing it failed, the node is broken and
// not coming back. Subsequent tests will run or fewer nodes (some of the tests
// may fail). Manual intervention is required in such case (recreating the
// cluster solves the problem too).
err
:=
wait
.
Poll
(
time
.
Millisecond
*
100
,
time
.
Second
*
30
,
func
()
(
bool
,
error
)
{
result
,
err
:=
SSH
(
undropCmd
,
from
,
testContext
.
Provider
)
if
result
.
Code
==
0
&&
err
==
nil
{
return
true
,
nil
}
LogSSHResult
(
result
)
if
err
!=
nil
{
Logf
(
"Unexpected error: %v"
,
err
)
}
return
false
,
nil
})
if
err
!=
nil
{
Failf
(
"Failed to remove the iptable REJECT rule. Manual intervention is "
+
"required on host %s: remove rule %s, if exists"
,
from
,
iptablesRule
)
}
}
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