Skip to content

Commit da5bf27

Browse files
committed
Remove no-longer-used TestUnderTemporaryNetworkFailure()
This was previously used by some autoscaling tests that have since been removed. It is somewhat sketchy (and inherently [Disruptive]), and depends on iptables (so would need to be updated to use nftables at some point if we were keeping it). Given that it's now unused, just remove it (as well as some helper functions that are no longer used by anyone else as well).
1 parent e69a5ed commit da5bf27

File tree

2 files changed

+0
-157
lines changed

2 files changed

+0
-157
lines changed

test/e2e/framework/network/utils.go

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import (
4545
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
4646
e2epodoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"
4747
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
48-
e2essh "k8s.io/kubernetes/test/e2e/framework/ssh"
4948
imageutils "k8s.io/kubernetes/test/utils/image"
5049
netutils "k8s.io/utils/net"
5150
)
@@ -1099,101 +1098,6 @@ func httpGetNoConnectionPoolTimeout(url string, timeout time.Duration) (*http.Re
10991098
return client.Get(url)
11001099
}
11011100

1102-
// TestUnderTemporaryNetworkFailure blocks outgoing network traffic on 'node'. Then runs testFunc and returns its status.
1103-
// At the end (even in case of errors), the network traffic is brought back to normal.
1104-
// This function executes commands on a node so it will work only for some
1105-
// environments.
1106-
func TestUnderTemporaryNetworkFailure(ctx context.Context, c clientset.Interface, ns string, node *v1.Node, testFunc func(ctx context.Context)) {
1107-
host, err := e2enode.GetSSHExternalIP(node)
1108-
if err != nil {
1109-
framework.Failf("Error getting node external ip : %v", err)
1110-
}
1111-
controlPlaneAddresses := framework.GetControlPlaneAddresses(ctx, c)
1112-
ginkgo.By(fmt.Sprintf("block network traffic from node %s to the control plane", node.Name))
1113-
defer func() {
1114-
// This code will execute even if setting the iptables rule failed.
1115-
// It is on purpose because we may have an error even if the new rule
1116-
// had been inserted. (yes, we could look at the error code and ssh error
1117-
// separately, but I prefer to stay on the safe side).
1118-
ginkgo.By(fmt.Sprintf("Unblock network traffic from node %s to the control plane", node.Name))
1119-
for _, instanceAddress := range controlPlaneAddresses {
1120-
UnblockNetwork(ctx, host, instanceAddress)
1121-
}
1122-
}()
1123-
1124-
framework.Logf("Waiting %v to ensure node %s is ready before beginning test...", resizeNodeReadyTimeout, node.Name)
1125-
if !e2enode.WaitConditionToBe(ctx, c, node.Name, v1.NodeReady, true, resizeNodeReadyTimeout) {
1126-
framework.Failf("Node %s did not become ready within %v", node.Name, resizeNodeReadyTimeout)
1127-
}
1128-
for _, instanceAddress := range controlPlaneAddresses {
1129-
BlockNetwork(ctx, host, instanceAddress)
1130-
}
1131-
1132-
framework.Logf("Waiting %v for node %s to be not ready after simulated network failure", resizeNodeNotReadyTimeout, node.Name)
1133-
if !e2enode.WaitConditionToBe(ctx, c, node.Name, v1.NodeReady, false, resizeNodeNotReadyTimeout) {
1134-
framework.Failf("Node %s did not become not-ready within %v", node.Name, resizeNodeNotReadyTimeout)
1135-
}
1136-
1137-
testFunc(ctx)
1138-
// network traffic is unblocked in a deferred function
1139-
}
1140-
1141-
// BlockNetwork blocks network between the given from value and the given to value.
1142-
// The following helper functions can block/unblock network from source
1143-
// host to destination host by manipulating iptable rules.
1144-
// This function assumes it can ssh to the source host.
1145-
//
1146-
// Caution:
1147-
// Recommend to input IP instead of hostnames. Using hostnames will cause iptables to
1148-
// do a DNS lookup to resolve the name to an IP address, which will
1149-
// slow down the test and cause it to fail if DNS is absent or broken.
1150-
//
1151-
// Suggested usage pattern:
1152-
//
1153-
// func foo() {
1154-
// ...
1155-
// defer UnblockNetwork(from, to)
1156-
// BlockNetwork(from, to)
1157-
// ...
1158-
// }
1159-
func BlockNetwork(ctx context.Context, from string, to string) {
1160-
framework.Logf("block network traffic from %s to %s", from, to)
1161-
iptablesRule := fmt.Sprintf("OUTPUT --destination %s --jump REJECT", to)
1162-
dropCmd := fmt.Sprintf("sudo iptables --insert %s", iptablesRule)
1163-
if result, err := e2essh.SSH(ctx, dropCmd, from, framework.TestContext.Provider); result.Code != 0 || err != nil {
1164-
e2essh.LogResult(result)
1165-
framework.Failf("Unexpected error: %v", err)
1166-
}
1167-
}
1168-
1169-
// UnblockNetwork unblocks network between the given from value and the given to value.
1170-
func UnblockNetwork(ctx context.Context, from string, to string) {
1171-
framework.Logf("Unblock network traffic from %s to %s", from, to)
1172-
iptablesRule := fmt.Sprintf("OUTPUT --destination %s --jump REJECT", to)
1173-
undropCmd := fmt.Sprintf("sudo iptables --delete %s", iptablesRule)
1174-
// Undrop command may fail if the rule has never been created.
1175-
// In such case we just lose 30 seconds, but the cluster is healthy.
1176-
// But if the rule had been created and removing it failed, the node is broken and
1177-
// not coming back. Subsequent tests will run or fewer nodes (some of the tests
1178-
// may fail). Manual intervention is required in such case (recreating the
1179-
// cluster solves the problem too).
1180-
err := wait.PollUntilContextTimeout(ctx, time.Millisecond*100, time.Second*30, false, func(ctx context.Context) (bool, error) {
1181-
result, err := e2essh.SSH(ctx, undropCmd, from, framework.TestContext.Provider)
1182-
if result.Code == 0 && err == nil {
1183-
return true, nil
1184-
}
1185-
e2essh.LogResult(result)
1186-
if err != nil {
1187-
framework.Logf("Unexpected error: %v", err)
1188-
}
1189-
return false, nil
1190-
})
1191-
if err != nil {
1192-
framework.Failf("Failed to remove the iptable REJECT rule. Manual intervention is "+
1193-
"required on host %s: remove rule %s, if exists", from, iptablesRule)
1194-
}
1195-
}
1196-
11971101
// WaitForService waits until the service appears (exist == true), or disappears (exist == false)
11981102
func WaitForService(ctx context.Context, c clientset.Interface, namespace, name string, exist bool, interval, timeout time.Duration) error {
11991103
err := wait.PollUntilContextTimeout(ctx, interval, timeout, true, func(ctx context.Context) (bool, error) {

test/e2e/framework/util.go

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ import (
5656
netutils "k8s.io/utils/net"
5757
)
5858

59-
const (
60-
// TODO(justinsb): Avoid hardcoding this.
61-
awsMasterIP = "172.20.0.9"
62-
)
63-
6459
// DEPRECATED constants. Use the timeouts in framework.Framework instead.
6560
const (
6661
// PodListTimeout is how long to wait for the pod to be listable.
@@ -678,38 +673,6 @@ func GetNodeExternalIPs(node *v1.Node) (ips []string) {
678673
return
679674
}
680675

681-
// getControlPlaneAddresses returns the externalIP, internalIP and hostname fields of control plane nodes.
682-
// If any of these is unavailable, empty slices are returned.
683-
func getControlPlaneAddresses(ctx context.Context, c clientset.Interface) ([]string, []string, []string) {
684-
var externalIPs, internalIPs, hostnames []string
685-
686-
// Populate the internal IPs.
687-
eps, err := c.CoreV1().Endpoints(metav1.NamespaceDefault).Get(ctx, "kubernetes", metav1.GetOptions{})
688-
if err != nil {
689-
Failf("Failed to get kubernetes endpoints: %v", err)
690-
}
691-
for _, subset := range eps.Subsets {
692-
for _, address := range subset.Addresses {
693-
if address.IP != "" {
694-
internalIPs = append(internalIPs, address.IP)
695-
}
696-
}
697-
}
698-
699-
// Populate the external IP/hostname.
700-
hostURL, err := url.Parse(TestContext.Host)
701-
if err != nil {
702-
Failf("Failed to parse hostname: %v", err)
703-
}
704-
if netutils.ParseIPSloppy(hostURL.Host) != nil {
705-
externalIPs = append(externalIPs, hostURL.Host)
706-
} else {
707-
hostnames = append(hostnames, hostURL.Host)
708-
}
709-
710-
return externalIPs, internalIPs, hostnames
711-
}
712-
713676
// GetControlPlaneNodes returns a list of control plane nodes
714677
func GetControlPlaneNodes(ctx context.Context, c clientset.Interface) *v1.NodeList {
715678
allNodes, err := c.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
@@ -737,30 +700,6 @@ func GetControlPlaneNodes(ctx context.Context, c clientset.Interface) *v1.NodeLi
737700
return &cpNodes
738701
}
739702

740-
// GetControlPlaneAddresses returns all IP addresses on which the kubelet can reach the control plane.
741-
// It may return internal and external IPs, even if we expect for
742-
// e.g. internal IPs to be used (issue #56787), so that we can be
743-
// sure to block the control plane fully during tests.
744-
func GetControlPlaneAddresses(ctx context.Context, c clientset.Interface) []string {
745-
externalIPs, internalIPs, _ := getControlPlaneAddresses(ctx, c)
746-
747-
ips := sets.NewString()
748-
switch TestContext.Provider {
749-
case "gce":
750-
for _, ip := range externalIPs {
751-
ips.Insert(ip)
752-
}
753-
for _, ip := range internalIPs {
754-
ips.Insert(ip)
755-
}
756-
case "aws":
757-
ips.Insert(awsMasterIP)
758-
default:
759-
Failf("This test is not supported for provider %s and should be disabled", TestContext.Provider)
760-
}
761-
return ips.List()
762-
}
763-
764703
// PrettyPrintJSON converts metrics to JSON format.
765704
func PrettyPrintJSON(metrics interface{}) string {
766705
output := &bytes.Buffer{}

0 commit comments

Comments
 (0)