Skip to content

Commit ca82063

Browse files
authored
Merge pull request #5225 from martinkennelly/e2e-reduce-env-vars
Lookup supported IP family via kapi.
2 parents afd53ab + 6018f47 commit ca82063

11 files changed

+193
-132
lines changed

test/e2e/egressip.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ var _ = ginkgo.DescribeTableSubtree("e2e egress IP validation", feature.EgressIP
702702
if len(nodes.Items) < 3 {
703703
framework.Failf("Test requires >= 3 Ready nodes, but there are only %v nodes", len(nodes.Items))
704704
}
705+
netConfigParams.cidr = filterCIDRsAndJoin(f.ClientSet, netConfigParams.cidr)
705706
if isSupported, reason := isNetworkSupported(nodes, netConfigParams); !isSupported {
706707
ginkgo.Skip(reason)
707708
}
@@ -3193,13 +3194,13 @@ spec:
31933194
ginkgo.Entry("L3 Primary UDN", networkAttachmentConfigParams{
31943195
name: "l3primary",
31953196
topology: types.Layer3Topology,
3196-
cidr: correctCIDRFamily("30.10.0.0/16", "2014:100:200::0/60"),
3197+
cidr: joinCIDRs("30.10.0.0/16", "2014:100:200::0/60"),
31973198
role: "primary",
31983199
}),
31993200
ginkgo.Entry("L2 Primary UDN", networkAttachmentConfigParams{
32003201
name: "l2primary",
32013202
topology: types.Layer2Topology,
3202-
cidr: correctCIDRFamily("10.10.0.0/16", "2014:100:200::0/60"),
3203+
cidr: joinCIDRs("10.10.0.0/16", "2014:100:200::0/60"),
32033204
role: "primary",
32043205
}),
32053206
)

test/e2e/kubevirt.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,8 +1699,8 @@ write_files:
16991699
namespace = fr.Namespace.Name
17001700

17011701
networkName := ""
1702-
cidrs := generateL2Subnets(cidrIPv4, cidrIPv6)
1703-
cudn, networkName = kubevirt.GenerateCUDN(namespace, "net1", td.topology, td.role, cidrs)
1702+
dualCIDRs := filterDualStackCIDRs(fr.ClientSet, []udnv1.CIDR{udnv1.CIDR(cidrIPv4), udnv1.CIDR(cidrIPv6)})
1703+
cudn, networkName = kubevirt.GenerateCUDN(namespace, "net1", td.topology, td.role, dualCIDRs)
17041704

17051705
if td.topology == udnv1.NetworkTopologyLocalnet {
17061706
By("setting up the localnet underlay")
@@ -1809,7 +1809,7 @@ ip route add %[3]s via %[4]s
18091809

18101810
// expect 2 addresses on dual-stack deployments; 1 on single-stack
18111811
step = by(vmi.Name, "Wait for addresses at the virtual machine")
1812-
expectedNumberOfAddresses := len(cidrs)
1812+
expectedNumberOfAddresses := len(dualCIDRs)
18131813
expectedAddreses := virtualMachineAddressesFromStatus(vmi, expectedNumberOfAddresses)
18141814
expectedAddresesAtGuest := expectedAddreses
18151815
testPodsIPs := podsMultusNetworkIPs(iperfServerTestPods, podNetworkStatusByNetConfigPredicate(namespace, cudn.Name, strings.ToLower(string(td.role))))
@@ -1836,7 +1836,7 @@ ip route add %[3]s via %[4]s
18361836
checkEastWestIperfTraffic(vmi, testPodsIPs, step)
18371837

18381838
if td.role == udnv1.NetworkRolePrimary {
1839-
if isIPv6Supported() && isInterconnectEnabled() {
1839+
if isIPv6Supported(fr.ClientSet) && isInterconnectEnabled() {
18401840
step = by(vmi.Name, fmt.Sprintf("Checking IPv6 gateway before %s %s", td.resource.description, td.test.description))
18411841

18421842
nodeRunningVMI, err := fr.ClientSet.CoreV1().Nodes().Get(context.Background(), vmi.Status.NodeName, metav1.GetOptions{})
@@ -1906,7 +1906,7 @@ ip route add %[3]s via %[4]s
19061906
}
19071907

19081908
if td.role == udnv1.NetworkRolePrimary && td.test.description == liveMigrate.description && isInterconnectEnabled() {
1909-
if isIPv4Supported() {
1909+
if isIPv4Supported(fr.ClientSet) {
19101910
step = by(vmi.Name, fmt.Sprintf("Checking IPv4 gateway cached mac after %s %s", td.resource.description, td.test.description))
19111911
Expect(crClient.Get(context.TODO(), crclient.ObjectKeyFromObject(vmi), vmi)).To(Succeed())
19121912

@@ -1923,7 +1923,7 @@ ip route add %[3]s via %[4]s
19231923
WithPolling(time.Second).
19241924
Should(Equal(expectedGatewayMAC), step)
19251925
}
1926-
if isIPv6Supported() {
1926+
if isIPv6Supported(fr.ClientSet) {
19271927
step = by(vmi.Name, fmt.Sprintf("Checking IPv6 gateway after %s %s", td.resource.description, td.test.description))
19281928

19291929
targetNode, err := fr.ClientSet.CoreV1().Nodes().Get(context.Background(), vmi.Status.MigrationState.TargetNode, metav1.GetOptions{})
@@ -2055,8 +2055,8 @@ ip route add %[3]s via %[4]s
20552055
})
20562056
fr.Namespace = ns
20572057
namespace = fr.Namespace.Name
2058-
cidrs := generateL2Subnets(cidrIPv4, cidrIPv6)
2059-
cudn, _ := kubevirt.GenerateCUDN(namespace, "net1", udnv1.NetworkTopologyLayer2, udnv1.NetworkRolePrimary, cidrs)
2058+
dualCIDRs := filterDualStackCIDRs(fr.ClientSet, []udnv1.CIDR{udnv1.CIDR(cidrIPv4), udnv1.CIDR(cidrIPv6)})
2059+
cudn, _ := kubevirt.GenerateCUDN(namespace, "net1", udnv1.NetworkTopologyLayer2, udnv1.NetworkRolePrimary, dualCIDRs)
20602060
cudn.Spec.Network.Layer2.MTU = 1300
20612061
createCUDN(cudn)
20622062

@@ -2097,7 +2097,7 @@ ip route add %[3]s via %[4]s
20972097
Get(context.Background(), config.Kubernetes.DNSServiceName, metav1.GetOptions{})
20982098
Expect(err).NotTo(HaveOccurred())
20992099

2100-
if isIPv4Supported() {
2100+
if isIPv4Supported(fr.ClientSet) {
21012101
expectedIP, err := matchIPv4StringFamily(primaryUDNNetworkStatus.IPs)
21022102
Expect(err).NotTo(HaveOccurred())
21032103

@@ -2125,7 +2125,7 @@ ip route add %[3]s via %[4]s
21252125
Expect(primaryUDNValueForDevice("GENERAL.MTU")).To(ConsistOf("1300"))
21262126
}
21272127

2128-
if isIPv6Supported() {
2128+
if isIPv6Supported(fr.ClientSet) {
21292129
expectedIP, err := matchIPv6StringFamily(primaryUDNNetworkStatus.IPs)
21302130
Expect(err).NotTo(HaveOccurred())
21312131
Eventually(primaryUDNValueFor).
@@ -2164,7 +2164,7 @@ ip route add %[3]s via %[4]s
21642164
vmiIPv4 = "10.128.0.100/24"
21652165
vmiIPv6 = "2010:100:200::100/60"
21662166
vmiMAC = "0A:58:0A:80:00:64"
2167-
cidr = selectCIDRs(ipv4CIDR, ipv6CIDR)
2167+
cidrs = []string{ipv4CIDR, ipv6CIDR}
21682168
staticIPsNetworkData = func(ips []string) (string, error) {
21692169
type Ethernet struct {
21702170
Addresses []string `json:"addresses,omitempty"`
@@ -2213,10 +2213,10 @@ chpasswd: { expire: False }
22132213
selectedNodes = workerNodeList.Items
22142214
Expect(selectedNodes).NotTo(BeEmpty())
22152215

2216-
iperfServerTestPods, err = createIperfServerPods(selectedNodes, cudn.Name, cudn.Spec.Network.Localnet.Role, cidr)
2216+
iperfServerTestPods, err = createIperfServerPods(selectedNodes, cudn.Name, cudn.Spec.Network.Localnet.Role, filterCIDRs(fr.ClientSet, cidrs...))
22172217
Expect(err).NotTo(HaveOccurred())
22182218

2219-
networkData, err := staticIPsNetworkData(selectCIDRs(vmiIPv4, vmiIPv6))
2219+
networkData, err := staticIPsNetworkData(filterCIDRs(fr.ClientSet, vmiIPv4, vmiIPv6))
22202220
Expect(err).NotTo(HaveOccurred())
22212221

22222222
vmi := fedoraWithTestToolingVMI(nil /*labels*/, nil /*annotations*/, nil /*nodeSelector*/, kubevirtv1.NetworkSource{

test/e2e/multihoming_utils.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,33 @@ func netCIDR(netCIDR string, netPrefixLengthPerNode int) string {
2929
return fmt.Sprintf("%s/%d", netCIDR, netPrefixLengthPerNode)
3030
}
3131

32-
// takes ipv4 and ipv6 cidrs and returns the correct type for the cluster under test
33-
func correctCIDRFamily(ipv4CIDR, ipv6CIDR string) string {
34-
return strings.Join(selectCIDRs(ipv4CIDR, ipv6CIDR), ",")
32+
func joinCIDRs(cidrs ...string) string {
33+
return strings.Join(cidrs, ",")
3534
}
3635

37-
// takes ipv4 and ipv6 cidrs and returns the correct type for the cluster under test
38-
func selectCIDRs(ipv4CIDR, ipv6CIDR string) []string {
39-
// dual stack cluster
40-
if isIPv6Supported() && isIPv4Supported() {
41-
return []string{ipv4CIDR, ipv6CIDR}
36+
func splitCIDRs(cidrs string) []string {
37+
if cidrs == "" {
38+
return []string{}
4239
}
43-
// is an ipv6 only cluster
44-
if isIPv6Supported() {
45-
return []string{ipv6CIDR}
40+
return strings.Split(cidrs, ",")
41+
}
42+
43+
func filterCIDRsAndJoin(cs clientset.Interface, cidrs string) string {
44+
if cidrs == "" {
45+
return "" // we may not always set CIDR - i.e. CDN
4646
}
47+
return joinCIDRs(filterCIDRs(cs, splitCIDRs(cidrs)...)...)
48+
}
4749

48-
//ipv4 only cluster
49-
return []string{ipv4CIDR}
50+
func filterCIDRs(cs clientset.Interface, cidrs ...string) []string {
51+
var supportedCIDRs []string
52+
for _, cidr := range cidrs {
53+
if !isCIDRIPFamilySupported(cs, cidr) {
54+
continue
55+
}
56+
supportedCIDRs = append(supportedCIDRs, cidr)
57+
}
58+
return supportedCIDRs
5059
}
5160

5261
func getNetCIDRSubnet(netCIDR string) (string, error) {

0 commit comments

Comments
 (0)