From d96f01d1896c44725d98d61949a7fe1c94f3f3c9 Mon Sep 17 00:00:00 2001 From: David Cheung Date: Mon, 4 Nov 2024 22:35:33 +0000 Subject: [PATCH] Ensure NEG Readiness Reflector commits endpoints from non-default subnets. --- pkg/neg/syncers/transaction.go | 17 +- pkg/neg/syncers/transaction_test.go | 399 +++++++++++++++++++--------- 2 files changed, 292 insertions(+), 124 deletions(-) diff --git a/pkg/neg/syncers/transaction.go b/pkg/neg/syncers/transaction.go index 1d2d351e2..727e2a457 100644 --- a/pkg/neg/syncers/transaction.go +++ b/pkg/neg/syncers/transaction.go @@ -738,9 +738,22 @@ func (s *transactionSyncer) commitPods(endpointMap map[negtypes.EndpointGroupInf } zoneEndpointMap[endpoint] = podName } - // TODO(sawsa307): Make sure commitPods is called for non-default subnet NEGs. + negName := s.NegSyncerKey.NegName + syncerKey := s.NegSyncerKey + if flags.F.EnableMultiSubnetClusterPhase1 { + defaultSubnet, err := utils.KeyName(s.networkInfo.SubnetworkURL) + if err != nil { + s.logger.Error(err, "Errored getting default subnet from NetworkInfo when commiting pods") + continue + } + + if endpointGroupInfo.Subnet != defaultSubnet { + negName = s.namer.NonDefaultSubnetNEG(s.NegSyncerKey.Namespace, s.NegSyncerKey.Name, endpointGroupInfo.Subnet, s.NegSyncerKey.PortTuple.Port) + } + syncerKey.NegName = negName + } // Only zone is needed because NEGs from non-default subnet have different names. - s.reflector.CommitPods(s.NegSyncerKey, s.NegSyncerKey.NegName, endpointGroupInfo.Zone, zoneEndpointMap) + s.reflector.CommitPods(syncerKey, negName, endpointGroupInfo.Zone, zoneEndpointMap) } } diff --git a/pkg/neg/syncers/transaction_test.go b/pkg/neg/syncers/transaction_test.go index b3fd8795d..7251d0a0b 100644 --- a/pkg/neg/syncers/transaction_test.go +++ b/pkg/neg/syncers/transaction_test.go @@ -839,8 +839,6 @@ func TestFilterEndpointByTransaction(t *testing.T) { } func TestCommitPods(t *testing.T) { - t.Parallel() - vals := gce.DefaultTestClusterValues() vals.SubnetworkURL = defaultTestSubnetURL _, transactionSyncer := newTestTransactionSyncer(negtypes.NewAdapter(gce.NewFakeGCECloud(vals)), negtypes.VmIpPortEndpointType, false) @@ -849,192 +847,349 @@ func TestCommitPods(t *testing.T) { syncerKey := transactionSyncer.NegSyncerKey negName := transactionSyncer.NegName + prevFlag := flags.F.EnableMultiSubnetClusterPhase1 + defer func() { flags.F.EnableMultiSubnetClusterPhase1 = prevFlag }() + + for _, enableMultiSubnetPhase1 := range []bool{true, false} { + flags.F.EnableMultiSubnetClusterPhase1 = enableMultiSubnetPhase1 + for _, tc := range []struct { + desc string + input func() (map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet, negtypes.EndpointPodMap) + expectOutput func() map[readiness.NegMeta]negtypes.EndpointPodMap + }{ + { + desc: "empty input", + input: func() (map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet, negtypes.EndpointPodMap) { + return nil, nil + }, + expectOutput: func() map[readiness.NegMeta]negtypes.EndpointPodMap { + return map[readiness.NegMeta]negtypes.EndpointPodMap{} + }, + }, + { + desc: "10 endpoints from 1 instance in 1 zone", + input: func() (map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet, negtypes.EndpointPodMap) { + endpointSet, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") + return map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet{{Zone: testZone1, Subnet: defaultTestSubnet}: endpointSet}, endpointMap + }, + expectOutput: func() map[readiness.NegMeta]negtypes.EndpointPodMap { + _, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") + return map[readiness.NegMeta]negtypes.EndpointPodMap{ + {SyncerKey: syncerKey, Name: negName, Zone: testZone1}: endpointMap, + } + }, + }, + { + desc: "40 endpoints from 4 instances in 2 zone", + input: func() (map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet, negtypes.EndpointPodMap) { + retSet := map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet{ + {Zone: testZone1, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), + {Zone: testZone2, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), + } + retMap := negtypes.EndpointPodMap{} + endpointSet, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") + retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}].Union(endpointSet) + retMap = unionEndpointMap(retMap, endpointMap) + endpointSet, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 10, testInstance2, "8080") + retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}].Union(endpointSet) + retMap = unionEndpointMap(retMap, endpointMap) + endpointSet, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 10, testInstance3, "8080") + retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}].Union(endpointSet) + retMap = unionEndpointMap(retMap, endpointMap) + endpointSet, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 10, testInstance4, "8080") + retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}].Union(endpointSet) + retMap = unionEndpointMap(retMap, endpointMap) + return retSet, retMap + }, + expectOutput: func() map[readiness.NegMeta]negtypes.EndpointPodMap { + retMap := map[readiness.NegMeta]negtypes.EndpointPodMap{ + {SyncerKey: syncerKey, Name: negName, Zone: testZone1}: {}, + {SyncerKey: syncerKey, Name: negName, Zone: testZone2}: {}, + } + _, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") + retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}], endpointMap) + _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 10, testInstance2, "8080") + retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}], endpointMap) + _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 10, testInstance3, "8080") + retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}], endpointMap) + _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 10, testInstance4, "8080") + retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}], endpointMap) + return retMap + }, + }, + { + desc: "40 endpoints from 4 instances in 2 zone, but half of the endpoints does not have corresponding pod mapping", + input: func() (map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet, negtypes.EndpointPodMap) { + retSet := map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet{ + {Zone: testZone1, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), + {Zone: testZone2, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), + } + retMap := negtypes.EndpointPodMap{} + + endpointSet, _ := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") + retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}].Union(endpointSet) + _, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 5, testInstance1, "8080") + retMap = unionEndpointMap(retMap, endpointMap) + + endpointSet, _ = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 10, testInstance2, "8080") + retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}].Union(endpointSet) + _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 5, testInstance2, "8080") + retMap = unionEndpointMap(retMap, endpointMap) + + endpointSet, _ = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 10, testInstance3, "8080") + retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}].Union(endpointSet) + _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 5, testInstance3, "8080") + retMap = unionEndpointMap(retMap, endpointMap) + + endpointSet, _ = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 10, testInstance4, "8080") + retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}].Union(endpointSet) + _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 5, testInstance4, "8080") + retMap = unionEndpointMap(retMap, endpointMap) + return retSet, retMap + }, + expectOutput: func() map[readiness.NegMeta]negtypes.EndpointPodMap { + retMap := map[readiness.NegMeta]negtypes.EndpointPodMap{ + {SyncerKey: syncerKey, Name: negName, Zone: testZone1}: {}, + {SyncerKey: syncerKey, Name: negName, Zone: testZone2}: {}, + } + _, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 5, testInstance1, "8080") + retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}], endpointMap) + _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 5, testInstance2, "8080") + retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}], endpointMap) + _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 5, testInstance3, "8080") + retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}], endpointMap) + _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 5, testInstance4, "8080") + retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}], endpointMap) + return retMap + }, + }, + { + desc: "40 endpoints from 4 instances in 2 zone, and more endpoints are in pod mapping", + input: func() (map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet, negtypes.EndpointPodMap) { + retSet := map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet{ + {Zone: testZone1, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), + {Zone: testZone2, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), + } + retMap := negtypes.EndpointPodMap{} + + endpointSet, _ := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") + retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}].Union(endpointSet) + _, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 15, testInstance1, "8080") + retMap = unionEndpointMap(retMap, endpointMap) + + endpointSet, _ = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 10, testInstance2, "8080") + retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}].Union(endpointSet) + _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 15, testInstance2, "8080") + retMap = unionEndpointMap(retMap, endpointMap) + + endpointSet, _ = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 10, testInstance3, "8080") + retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}].Union(endpointSet) + _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 15, testInstance3, "8080") + retMap = unionEndpointMap(retMap, endpointMap) + + endpointSet, _ = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 10, testInstance4, "8080") + retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}].Union(endpointSet) + _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 15, testInstance4, "8080") + retMap = unionEndpointMap(retMap, endpointMap) + return retSet, retMap + }, + expectOutput: func() map[readiness.NegMeta]negtypes.EndpointPodMap { + retMap := map[readiness.NegMeta]negtypes.EndpointPodMap{ + {SyncerKey: syncerKey, Name: negName, Zone: testZone1}: {}, + {SyncerKey: syncerKey, Name: negName, Zone: testZone2}: {}, + } + _, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") + retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}], endpointMap) + _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 10, testInstance2, "8080") + retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}], endpointMap) + _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 10, testInstance3, "8080") + retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}], endpointMap) + _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 10, testInstance4, "8080") + retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}], endpointMap) + return retMap + }, + }, + { + desc: "40 endpoints from 4 instances in 2 zone, but some nodes do not have endpoint pod mapping", + input: func() (map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet, negtypes.EndpointPodMap) { + retSet := map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet{ + {Zone: testZone1, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), + {Zone: testZone2, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), + } + retMap := negtypes.EndpointPodMap{} + endpointSet, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") + retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}].Union(endpointSet) + retMap = unionEndpointMap(retMap, endpointMap) + endpointSet, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 10, testInstance2, "8080") + retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}].Union(endpointSet) + endpointSet, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 10, testInstance3, "8080") + retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}].Union(endpointSet) + retMap = unionEndpointMap(retMap, endpointMap) + endpointSet, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 10, testInstance4, "8080") + retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}].Union(endpointSet) + return retSet, retMap + }, + expectOutput: func() map[readiness.NegMeta]negtypes.EndpointPodMap { + retMap := map[readiness.NegMeta]negtypes.EndpointPodMap{ + {SyncerKey: syncerKey, Name: negName, Zone: testZone1}: {}, + {SyncerKey: syncerKey, Name: negName, Zone: testZone2}: {}, + } + _, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") + retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}], endpointMap) + _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 10, testInstance3, "8080") + retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}], endpointMap) + return retMap + }, + }, + } { + reflector.Flush() + endpointMap, endpointPodMap := tc.input() + expectOutput := tc.expectOutput() + transactionSyncer.commitPods(endpointMap, endpointPodMap) + negNameSet := sets.NewString(reflector.negNames...) + if len(expectOutput) != 0 && !(negNameSet.Len() == 1 && negNameSet.Has(transactionSyncer.NegSyncerKey.NegName)) { + t.Errorf("For test case %q, expect neg name to be %v, but got %v", tc.desc, transactionSyncer.NegSyncerKey.NegName, negNameSet.List()) + } + + if !reflect.DeepEqual(expectOutput, reflector.pollMap) { + t.Errorf("For test case %q, expect endpoint map to be %v, but got %v", tc.desc, expectOutput, reflector.pollMap) + } + } + } +} + +func TestCommitPodsMSC(t *testing.T) { + vals := gce.DefaultTestClusterValues() + vals.SubnetworkURL = defaultTestSubnetURL + _, transactionSyncer := newTestTransactionSyncer(negtypes.NewAdapter(gce.NewFakeGCECloud(vals)), negtypes.VmIpPortEndpointType, false) + reflector := &testReflector{} + transactionSyncer.reflector = reflector + + prevFlag := flags.F.EnableMultiSubnetClusterPhase1 + defer func() { flags.F.EnableMultiSubnetClusterPhase1 = prevFlag }() + flags.F.EnableMultiSubnetClusterPhase1 = true + + defaultSubnetNegName := transactionSyncer.NegName + defaultSubnetSyncerKey := transactionSyncer.NegSyncerKey + + nonDefaultSubnetNegName := transactionSyncer.namer.NonDefaultSubnetNEG(transactionSyncer.NegSyncerKey.Namespace, transactionSyncer.NegSyncerKey.Name, additionalTestSubnet, transactionSyncer.NegSyncerKey.PortTuple.Port) + nonDefaultSubnetSyncerKey := transactionSyncer.NegSyncerKey + nonDefaultSubnetSyncerKey.NegName = nonDefaultSubnetNegName + for _, tc := range []struct { desc string input func() (map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet, negtypes.EndpointPodMap) expectOutput func() map[readiness.NegMeta]negtypes.EndpointPodMap }{ { - desc: "empty input", - input: func() (map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet, negtypes.EndpointPodMap) { - return nil, nil - }, - expectOutput: func() map[readiness.NegMeta]negtypes.EndpointPodMap { - return map[readiness.NegMeta]negtypes.EndpointPodMap{} - }, - }, - { - desc: "10 endpoints from 1 instance in 1 zone", - input: func() (map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet, negtypes.EndpointPodMap) { - endpointSet, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") - return map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet{{Zone: testZone1, Subnet: defaultTestSubnet}: endpointSet}, endpointMap - }, - expectOutput: func() map[readiness.NegMeta]negtypes.EndpointPodMap { - _, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") - return map[readiness.NegMeta]negtypes.EndpointPodMap{ - {SyncerKey: syncerKey, Name: negName, Zone: testZone1}: endpointMap, - } - }, - }, - { - desc: "40 endpoints from 4 instances in 2 zone", + desc: "20 endpoints from 2 instance in different subnets, in 1 zone", input: func() (map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet, negtypes.EndpointPodMap) { retSet := map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet{ - {Zone: testZone1, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), - {Zone: testZone2, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), + {Zone: testZone1, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), + {Zone: testZone1, Subnet: additionalTestSubnet}: negtypes.NewNetworkEndpointSet(), } retMap := negtypes.EndpointPodMap{} endpointSet, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}].Union(endpointSet) retMap = unionEndpointMap(retMap, endpointMap) endpointSet, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 10, testInstance2, "8080") - retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}].Union(endpointSet) - retMap = unionEndpointMap(retMap, endpointMap) - endpointSet, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 10, testInstance3, "8080") - retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}].Union(endpointSet) - retMap = unionEndpointMap(retMap, endpointMap) - endpointSet, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 10, testInstance4, "8080") - retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}].Union(endpointSet) + retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: additionalTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: additionalTestSubnet}].Union(endpointSet) retMap = unionEndpointMap(retMap, endpointMap) return retSet, retMap }, expectOutput: func() map[readiness.NegMeta]negtypes.EndpointPodMap { retMap := map[readiness.NegMeta]negtypes.EndpointPodMap{ - {SyncerKey: syncerKey, Name: negName, Zone: testZone1}: {}, - {SyncerKey: syncerKey, Name: negName, Zone: testZone2}: {}, + {SyncerKey: defaultSubnetSyncerKey, Name: defaultSubnetNegName, Zone: testZone1}: {}, + {SyncerKey: nonDefaultSubnetSyncerKey, Name: nonDefaultSubnetNegName, Zone: testZone1}: {}, } _, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") - retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}], endpointMap) + retMap[readiness.NegMeta{SyncerKey: defaultSubnetSyncerKey, Name: defaultSubnetNegName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: defaultSubnetSyncerKey, Name: defaultSubnetNegName, Zone: testZone1}], endpointMap) _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 10, testInstance2, "8080") - retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}], endpointMap) - _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 10, testInstance3, "8080") - retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}], endpointMap) - _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 10, testInstance4, "8080") - retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}], endpointMap) - return retMap - }, - }, - { - desc: "40 endpoints from 4 instances in 2 zone, but half of the endpoints does not have corresponding pod mapping", - input: func() (map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet, negtypes.EndpointPodMap) { - retSet := map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet{ - {Zone: testZone1, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), - {Zone: testZone2, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), - } - retMap := negtypes.EndpointPodMap{} - - endpointSet, _ := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") - retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}].Union(endpointSet) - _, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 5, testInstance1, "8080") - retMap = unionEndpointMap(retMap, endpointMap) - - endpointSet, _ = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 10, testInstance2, "8080") - retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}].Union(endpointSet) - _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 5, testInstance2, "8080") - retMap = unionEndpointMap(retMap, endpointMap) - - endpointSet, _ = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 10, testInstance3, "8080") - retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}].Union(endpointSet) - _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 5, testInstance3, "8080") - retMap = unionEndpointMap(retMap, endpointMap) - - endpointSet, _ = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 10, testInstance4, "8080") - retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}].Union(endpointSet) - _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 5, testInstance4, "8080") - retMap = unionEndpointMap(retMap, endpointMap) - return retSet, retMap - }, - expectOutput: func() map[readiness.NegMeta]negtypes.EndpointPodMap { - retMap := map[readiness.NegMeta]negtypes.EndpointPodMap{ - {SyncerKey: syncerKey, Name: negName, Zone: testZone1}: {}, - {SyncerKey: syncerKey, Name: negName, Zone: testZone2}: {}, - } - _, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 5, testInstance1, "8080") - retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}], endpointMap) - _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 5, testInstance2, "8080") - retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}], endpointMap) - _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 5, testInstance3, "8080") - retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}], endpointMap) - _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 5, testInstance4, "8080") - retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}], endpointMap) + retMap[readiness.NegMeta{SyncerKey: nonDefaultSubnetSyncerKey, Name: nonDefaultSubnetNegName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: nonDefaultSubnetSyncerKey, Name: nonDefaultSubnetNegName, Zone: testZone1}], endpointMap) return retMap }, }, { - desc: "40 endpoints from 4 instances in 2 zone, and more endpoints are in pod mapping", + desc: "40 endpoints from 4 instance in different subnets, in 2 zones", input: func() (map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet, negtypes.EndpointPodMap) { retSet := map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet{ - {Zone: testZone1, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), - {Zone: testZone2, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), + {Zone: testZone1, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), + {Zone: testZone1, Subnet: additionalTestSubnet}: negtypes.NewNetworkEndpointSet(), + {Zone: testZone2, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), + {Zone: testZone2, Subnet: additionalTestSubnet}: negtypes.NewNetworkEndpointSet(), } retMap := negtypes.EndpointPodMap{} - - endpointSet, _ := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") + endpointSet, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}].Union(endpointSet) - _, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 15, testInstance1, "8080") retMap = unionEndpointMap(retMap, endpointMap) - - endpointSet, _ = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 10, testInstance2, "8080") - retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}].Union(endpointSet) - _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 15, testInstance2, "8080") + endpointSet, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 10, testInstance2, "8080") + retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: additionalTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: additionalTestSubnet}].Union(endpointSet) retMap = unionEndpointMap(retMap, endpointMap) - - endpointSet, _ = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 10, testInstance3, "8080") + endpointSet, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 10, testInstance3, "8080") retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}].Union(endpointSet) - _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 15, testInstance3, "8080") retMap = unionEndpointMap(retMap, endpointMap) - - endpointSet, _ = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 10, testInstance4, "8080") - retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}].Union(endpointSet) - _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 15, testInstance4, "8080") + endpointSet, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 10, testInstance4, "8080") + retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: additionalTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: additionalTestSubnet}].Union(endpointSet) retMap = unionEndpointMap(retMap, endpointMap) return retSet, retMap }, expectOutput: func() map[readiness.NegMeta]negtypes.EndpointPodMap { retMap := map[readiness.NegMeta]negtypes.EndpointPodMap{ - {SyncerKey: syncerKey, Name: negName, Zone: testZone1}: {}, - {SyncerKey: syncerKey, Name: negName, Zone: testZone2}: {}, + {SyncerKey: defaultSubnetSyncerKey, Name: defaultSubnetNegName, Zone: testZone1}: {}, + {SyncerKey: nonDefaultSubnetSyncerKey, Name: nonDefaultSubnetNegName, Zone: testZone1}: {}, + {SyncerKey: defaultSubnetSyncerKey, Name: defaultSubnetNegName, Zone: testZone2}: {}, + {SyncerKey: nonDefaultSubnetSyncerKey, Name: nonDefaultSubnetNegName, Zone: testZone2}: {}, } _, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") - retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}], endpointMap) + retMap[readiness.NegMeta{SyncerKey: defaultSubnetSyncerKey, Name: defaultSubnetNegName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: defaultSubnetSyncerKey, Name: defaultSubnetNegName, Zone: testZone1}], endpointMap) _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 10, testInstance2, "8080") - retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}], endpointMap) + retMap[readiness.NegMeta{SyncerKey: nonDefaultSubnetSyncerKey, Name: nonDefaultSubnetNegName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: nonDefaultSubnetSyncerKey, Name: nonDefaultSubnetNegName, Zone: testZone1}], endpointMap) _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 10, testInstance3, "8080") - retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}], endpointMap) + retMap[readiness.NegMeta{SyncerKey: defaultSubnetSyncerKey, Name: defaultSubnetNegName, Zone: testZone2}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: defaultSubnetSyncerKey, Name: defaultSubnetNegName, Zone: testZone2}], endpointMap) _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 10, testInstance4, "8080") - retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}], endpointMap) + retMap[readiness.NegMeta{SyncerKey: nonDefaultSubnetSyncerKey, Name: nonDefaultSubnetNegName, Zone: testZone2}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: nonDefaultSubnetSyncerKey, Name: nonDefaultSubnetNegName, Zone: testZone2}], endpointMap) return retMap }, }, { - desc: "40 endpoints from 4 instances in 2 zone, but some nodes do not have endpoint pod mapping", + desc: "40 endpoints from 4 instance in different subnets, in 2 zones", input: func() (map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet, negtypes.EndpointPodMap) { retSet := map[negtypes.EndpointGroupInfo]negtypes.NetworkEndpointSet{ - {Zone: testZone1, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), - {Zone: testZone2, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), + {Zone: testZone1, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), + {Zone: testZone1, Subnet: additionalTestSubnet}: negtypes.NewNetworkEndpointSet(), + {Zone: testZone2, Subnet: defaultTestSubnet}: negtypes.NewNetworkEndpointSet(), + {Zone: testZone2, Subnet: additionalTestSubnet}: negtypes.NewNetworkEndpointSet(), } retMap := negtypes.EndpointPodMap{} endpointSet, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}].Union(endpointSet) retMap = unionEndpointMap(retMap, endpointMap) endpointSet, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 10, testInstance2, "8080") - retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: defaultTestSubnet}].Union(endpointSet) + retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: additionalTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone1, Subnet: additionalTestSubnet}].Union(endpointSet) + retMap = unionEndpointMap(retMap, endpointMap) endpointSet, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 10, testInstance3, "8080") retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}].Union(endpointSet) retMap = unionEndpointMap(retMap, endpointMap) endpointSet, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 10, testInstance4, "8080") - retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: defaultTestSubnet}].Union(endpointSet) + retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: additionalTestSubnet}] = retSet[negtypes.EndpointGroupInfo{Zone: testZone2, Subnet: additionalTestSubnet}].Union(endpointSet) + retMap = unionEndpointMap(retMap, endpointMap) return retSet, retMap }, expectOutput: func() map[readiness.NegMeta]negtypes.EndpointPodMap { retMap := map[readiness.NegMeta]negtypes.EndpointPodMap{ - {SyncerKey: syncerKey, Name: negName, Zone: testZone1}: {}, - {SyncerKey: syncerKey, Name: negName, Zone: testZone2}: {}, + {SyncerKey: defaultSubnetSyncerKey, Name: defaultSubnetNegName, Zone: testZone1}: {}, + {SyncerKey: nonDefaultSubnetSyncerKey, Name: nonDefaultSubnetNegName, Zone: testZone1}: {}, + {SyncerKey: defaultSubnetSyncerKey, Name: defaultSubnetNegName, Zone: testZone2}: {}, + {SyncerKey: nonDefaultSubnetSyncerKey, Name: nonDefaultSubnetNegName, Zone: testZone2}: {}, } _, endpointMap := generateEndpointSetAndMap(net.ParseIP("1.1.1.1"), 10, testInstance1, "8080") - retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone1}], endpointMap) + retMap[readiness.NegMeta{SyncerKey: defaultSubnetSyncerKey, Name: defaultSubnetNegName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: defaultSubnetSyncerKey, Name: defaultSubnetNegName, Zone: testZone1}], endpointMap) + _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.2.1"), 10, testInstance2, "8080") + retMap[readiness.NegMeta{SyncerKey: nonDefaultSubnetSyncerKey, Name: nonDefaultSubnetNegName, Zone: testZone1}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: nonDefaultSubnetSyncerKey, Name: nonDefaultSubnetNegName, Zone: testZone1}], endpointMap) _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.3.1"), 10, testInstance3, "8080") - retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: syncerKey, Name: negName, Zone: testZone2}], endpointMap) + retMap[readiness.NegMeta{SyncerKey: defaultSubnetSyncerKey, Name: defaultSubnetNegName, Zone: testZone2}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: defaultSubnetSyncerKey, Name: defaultSubnetNegName, Zone: testZone2}], endpointMap) + _, endpointMap = generateEndpointSetAndMap(net.ParseIP("1.1.4.1"), 10, testInstance4, "8080") + retMap[readiness.NegMeta{SyncerKey: nonDefaultSubnetSyncerKey, Name: nonDefaultSubnetNegName, Zone: testZone2}] = unionEndpointMap(retMap[readiness.NegMeta{SyncerKey: nonDefaultSubnetSyncerKey, Name: nonDefaultSubnetNegName, Zone: testZone2}], endpointMap) return retMap }, }, @@ -1044,8 +1199,8 @@ func TestCommitPods(t *testing.T) { expectOutput := tc.expectOutput() transactionSyncer.commitPods(endpointMap, endpointPodMap) negNameSet := sets.NewString(reflector.negNames...) - if len(expectOutput) != 0 && !(negNameSet.Len() == 1 && negNameSet.Has(transactionSyncer.NegSyncerKey.NegName)) { - t.Errorf("For test case %q, expect neg name to be %v, but got %v", tc.desc, transactionSyncer.NegSyncerKey.NegName, negNameSet.List()) + if len(expectOutput) != 0 && negNameSet.Len() != 2 { + t.Errorf("For test case %q, expect two negs, but got %v", tc.desc, negNameSet.List()) } if !reflect.DeepEqual(expectOutput, reflector.pollMap) {