Skip to content

Commit a99e004

Browse files
authored
Merge pull request kubernetes#70681 from justinsb/block_master_all_ips
e2e: block all master addresses
2 parents f1bf9be + c136a99 commit a99e004

File tree

5 files changed

+66
-30
lines changed

5 files changed

+66
-30
lines changed

test/e2e/apps/network_partition.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,12 @@ var _ = SIGDescribe("Network Partition [Disruptive] [Slow]", func() {
198198
By(fmt.Sprintf("Block traffic from node %s to the master", node.Name))
199199
host, err := framework.GetNodeExternalIP(&node)
200200
framework.ExpectNoError(err)
201-
master := framework.GetMasterAddress(c)
201+
masterAddresses := framework.GetAllMasterAddresses(c)
202202
defer func() {
203203
By(fmt.Sprintf("Unblock traffic from node %s to the master", node.Name))
204-
framework.UnblockNetwork(host, master)
204+
for _, masterAddress := range masterAddresses {
205+
framework.UnblockNetwork(host, masterAddress)
206+
}
205207

206208
if CurrentGinkgoTestDescription().Failed {
207209
return
@@ -214,7 +216,9 @@ var _ = SIGDescribe("Network Partition [Disruptive] [Slow]", func() {
214216
}
215217
}()
216218

217-
framework.BlockNetwork(host, master)
219+
for _, masterAddress := range masterAddresses {
220+
framework.BlockNetwork(host, masterAddress)
221+
}
218222

219223
By("Expect to observe node and pod status change from Ready to NotReady after network partition")
220224
expectNodeReadiness(false, newNode)
@@ -576,10 +580,12 @@ var _ = SIGDescribe("Network Partition [Disruptive] [Slow]", func() {
576580
By(fmt.Sprintf("Block traffic from node %s to the master", node.Name))
577581
host, err := framework.GetNodeExternalIP(&node)
578582
framework.ExpectNoError(err)
579-
master := framework.GetMasterAddress(c)
583+
masterAddresses := framework.GetAllMasterAddresses(c)
580584
defer func() {
581585
By(fmt.Sprintf("Unblock traffic from node %s to the master", node.Name))
582-
framework.UnblockNetwork(host, master)
586+
for _, masterAddress := range masterAddresses {
587+
framework.UnblockNetwork(host, masterAddress)
588+
}
583589

584590
if CurrentGinkgoTestDescription().Failed {
585591
return
@@ -589,7 +595,9 @@ var _ = SIGDescribe("Network Partition [Disruptive] [Slow]", func() {
589595
expectNodeReadiness(true, newNode)
590596
}()
591597

592-
framework.BlockNetwork(host, master)
598+
for _, masterAddress := range masterAddresses {
599+
framework.BlockNetwork(host, masterAddress)
600+
}
593601

594602
By("Expect to observe node and pod status change from Ready to NotReady after network partition")
595603
expectNodeReadiness(false, newNode)

test/e2e/framework/networking_utils.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -952,22 +952,26 @@ func TestUnderTemporaryNetworkFailure(c clientset.Interface, ns string, node *v1
952952
if err != nil {
953953
Failf("Error getting node external ip : %v", err)
954954
}
955-
master := GetMasterAddress(c)
955+
masterAddresses := GetAllMasterAddresses(c)
956956
By(fmt.Sprintf("block network traffic from node %s to the master", node.Name))
957957
defer func() {
958958
// This code will execute even if setting the iptables rule failed.
959959
// It is on purpose because we may have an error even if the new rule
960960
// had been inserted. (yes, we could look at the error code and ssh error
961961
// separately, but I prefer to stay on the safe side).
962962
By(fmt.Sprintf("Unblock network traffic from node %s to the master", node.Name))
963-
UnblockNetwork(host, master)
963+
for _, masterAddress := range masterAddresses {
964+
UnblockNetwork(host, masterAddress)
965+
}
964966
}()
965967

966968
Logf("Waiting %v to ensure node %s is ready before beginning test...", resizeNodeReadyTimeout, node.Name)
967969
if !WaitForNodeToBe(c, node.Name, v1.NodeReady, true, resizeNodeReadyTimeout) {
968970
Failf("Node %s did not become ready within %v", node.Name, resizeNodeReadyTimeout)
969971
}
970-
BlockNetwork(host, master)
972+
for _, masterAddress := range masterAddresses {
973+
BlockNetwork(host, masterAddress)
974+
}
971975

972976
Logf("Waiting %v for node %s to be not ready after simulated network failure", resizeNodeNotReadyTimeout, node.Name)
973977
if !WaitForNodeToBe(c, node.Name, v1.NodeReady, false, resizeNodeNotReadyTimeout) {

test/e2e/framework/util.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4960,19 +4960,28 @@ func getMaster(c clientset.Interface) Address {
49604960
return master
49614961
}
49624962

4963-
// GetMasterAddress returns the hostname/external IP/internal IP as appropriate for e2e tests on a particular provider
4964-
// which is the address of the interface used for communication with the kubelet.
4965-
func GetMasterAddress(c clientset.Interface) string {
4963+
// GetAllMasterAddresses returns all IP addresses on which the kubelet can reach the master.
4964+
// It may return internal and external IPs, even if we expect for
4965+
// e.g. internal IPs to be used (issue #56787), so that we can be
4966+
// sure to block the master fully during tests.
4967+
func GetAllMasterAddresses(c clientset.Interface) []string {
49664968
master := getMaster(c)
4969+
4970+
ips := sets.NewString()
49674971
switch TestContext.Provider {
49684972
case "gce", "gke":
4969-
return master.externalIP
4973+
if master.externalIP != "" {
4974+
ips.Insert(master.externalIP)
4975+
}
4976+
if master.internalIP != "" {
4977+
ips.Insert(master.internalIP)
4978+
}
49704979
case "aws":
4971-
return awsMasterIP
4980+
ips.Insert(awsMasterIP)
49724981
default:
49734982
Failf("This test is not supported for provider %s and should be disabled", TestContext.Provider)
49744983
}
4975-
return ""
4984+
return ips.List()
49764985
}
49774986

49784987
// GetNodeExternalIP returns node external IP concatenated with port 22 for ssh

test/e2e/network/firewall.go

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package network
1818

1919
import (
2020
"fmt"
21+
"time"
2122

2223
"k8s.io/api/core/v1"
2324
"k8s.io/apimachinery/pkg/util/sets"
@@ -172,17 +173,27 @@ var _ = SIGDescribe("Firewall rule", func() {
172173

173174
By("Checking well known ports on master and nodes are not exposed externally")
174175
nodeAddrs := framework.NodeAddresses(nodes, v1.NodeExternalIP)
175-
Expect(len(nodeAddrs)).NotTo(BeZero())
176-
masterAddr := framework.GetMasterAddress(cs)
177-
flag, _ := framework.TestNotReachableHTTPTimeout(masterAddr, ports.InsecureKubeControllerManagerPort, gce.FirewallTestTcpTimeout)
178-
Expect(flag).To(BeTrue())
179-
flag, _ = framework.TestNotReachableHTTPTimeout(masterAddr, ports.SchedulerPort, gce.FirewallTestTcpTimeout)
180-
Expect(flag).To(BeTrue())
181-
flag, _ = framework.TestNotReachableHTTPTimeout(nodeAddrs[0], ports.KubeletPort, gce.FirewallTestTcpTimeout)
182-
Expect(flag).To(BeTrue())
183-
flag, _ = framework.TestNotReachableHTTPTimeout(nodeAddrs[0], ports.KubeletReadOnlyPort, gce.FirewallTestTcpTimeout)
184-
Expect(flag).To(BeTrue())
185-
flag, _ = framework.TestNotReachableHTTPTimeout(nodeAddrs[0], ports.ProxyStatusPort, gce.FirewallTestTcpTimeout)
186-
Expect(flag).To(BeTrue())
176+
if len(nodeAddrs) == 0 {
177+
framework.Failf("did not find any node addresses")
178+
}
179+
180+
masterAddresses := framework.GetAllMasterAddresses(cs)
181+
for _, masterAddress := range masterAddresses {
182+
assertNotReachableHTTPTimeout(masterAddress, ports.InsecureKubeControllerManagerPort, gce.FirewallTestTcpTimeout)
183+
assertNotReachableHTTPTimeout(masterAddress, ports.SchedulerPort, gce.FirewallTestTcpTimeout)
184+
}
185+
assertNotReachableHTTPTimeout(nodeAddrs[0], ports.KubeletPort, gce.FirewallTestTcpTimeout)
186+
assertNotReachableHTTPTimeout(nodeAddrs[0], ports.KubeletReadOnlyPort, gce.FirewallTestTcpTimeout)
187+
assertNotReachableHTTPTimeout(nodeAddrs[0], ports.ProxyStatusPort, gce.FirewallTestTcpTimeout)
187188
})
188189
})
190+
191+
func assertNotReachableHTTPTimeout(ip string, port int, timeout time.Duration) {
192+
unreachable, err := framework.TestNotReachableHTTPTimeout(ip, port, timeout)
193+
if err != nil {
194+
framework.Failf("Unexpected error checking for reachability of %s:%d: %v", ip, port, err)
195+
}
196+
if !unreachable {
197+
framework.Failf("Was unexpectedly able to reach %s:%d", ip, port)
198+
}
199+
}

test/e2e/scheduling/taint_based_evictions.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,14 @@ var _ = SIGDescribe("TaintBasedEvictions [Serial]", func() {
128128
// host, err = framework.GetNodeInternalIP(&node)
129129
// }
130130
framework.ExpectNoError(err)
131-
master := framework.GetMasterAddress(cs)
131+
masterAddresses := framework.GetAllMasterAddresses(cs)
132132
taint := newUnreachableNoExecuteTaint()
133133

134134
defer func() {
135135
By(fmt.Sprintf("Unblocking traffic from node %s to the master", node.Name))
136-
framework.UnblockNetwork(host, master)
136+
for _, masterAddress := range masterAddresses {
137+
framework.UnblockNetwork(host, masterAddress)
138+
}
137139

138140
if CurrentGinkgoTestDescription().Failed {
139141
framework.Failf("Current e2e test has failed, so return from here.")
@@ -147,7 +149,9 @@ var _ = SIGDescribe("TaintBasedEvictions [Serial]", func() {
147149
framework.ExpectNoError(err)
148150
}()
149151

150-
framework.BlockNetwork(host, master)
152+
for _, masterAddress := range masterAddresses {
153+
framework.BlockNetwork(host, masterAddress)
154+
}
151155

152156
By(fmt.Sprintf("Expecting to see node %q becomes NotReady", nodeName))
153157
if !framework.WaitForNodeToBeNotReady(cs, nodeName, time.Minute*3) {

0 commit comments

Comments
 (0)