Skip to content

Commit d8ca8a4

Browse files
authored
Merge pull request #2857 from gauravkghildiyal/rename-endpointgroupinfo-to-neglocation
Rename epGroupInfo to negLocation for a better representation of the concept
2 parents 3ff2050 + 9049e79 commit d8ca8a4

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

pkg/neg/syncers/dualstack/migrator_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,16 @@ func TestFilter_FunctionalTest(t *testing.T) {
299299
removeEndpoints := make(map[types.NEGLocation]types.NetworkEndpointSet) // Contains single-stack endpoints which are to be removed from the NEG.
300300
committedEndpoints := make(map[types.NEGLocation]types.NetworkEndpointSet) // Initially empty.
301301
for i := 0; i < tc.initialNEGEndpointsCount; i++ {
302-
epGroupInfo := types.NEGLocation{Zone: fmt.Sprintf("zone-%v", i%tc.zonesCount), Subnet: defaultTestSubnet}
302+
negLocation := types.NEGLocation{Zone: fmt.Sprintf("zone-%v", i%tc.zonesCount), Subnet: defaultTestSubnet}
303303
ipv4 := fmt.Sprintf("ipv4-%v", 2*i+1)
304304
ipv6 := fmt.Sprintf("ipv6-%v", 2*i+2)
305-
if addEndpoints[epGroupInfo] == nil {
306-
addEndpoints[epGroupInfo] = types.NewNetworkEndpointSet()
307-
removeEndpoints[epGroupInfo] = types.NewNetworkEndpointSet()
308-
committedEndpoints[epGroupInfo] = types.NewNetworkEndpointSet()
305+
if addEndpoints[negLocation] == nil {
306+
addEndpoints[negLocation] = types.NewNetworkEndpointSet()
307+
removeEndpoints[negLocation] = types.NewNetworkEndpointSet()
308+
committedEndpoints[negLocation] = types.NewNetworkEndpointSet()
309309
}
310-
addEndpoints[epGroupInfo].Insert(types.NetworkEndpoint{IP: ipv4, IPv6: ipv6})
311-
removeEndpoints[epGroupInfo].Insert(types.NetworkEndpoint{IP: ipv4})
310+
addEndpoints[negLocation].Insert(types.NetworkEndpoint{IP: ipv4, IPv6: ipv6})
311+
removeEndpoints[negLocation].Insert(types.NetworkEndpoint{IP: ipv4})
312312
}
313313

314314
tc.migrator.errorStateChecker.(*fakeErrorStateChecker).errorState = tc.errorState

pkg/neg/syncers/transaction.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -629,18 +629,18 @@ func (s *transactionSyncer) syncNetworkEndpoints(addEndpoints, removeEndpoints m
629629
}
630630

631631
// attachNetworkEndpoints runs operation for attaching network endpoints.
632-
func (s *transactionSyncer) attachNetworkEndpoints(epGroupInfo negtypes.NEGLocation, networkEndpointMap map[negtypes.NetworkEndpoint]*composite.NetworkEndpoint) {
633-
s.logger.V(2).Info("Attaching endpoints to NEG.", "countOfEndpointsBeingAttached", len(networkEndpointMap), "negSyncerKey", s.NegSyncerKey.String(), "zone", epGroupInfo.Zone, "subnet", epGroupInfo.Subnet)
634-
err := s.operationInternal(attachOp, epGroupInfo, networkEndpointMap, s.logger)
632+
func (s *transactionSyncer) attachNetworkEndpoints(negLocation negtypes.NEGLocation, networkEndpointMap map[negtypes.NetworkEndpoint]*composite.NetworkEndpoint) {
633+
s.logger.V(2).Info("Attaching endpoints to NEG.", "countOfEndpointsBeingAttached", len(networkEndpointMap), "negSyncerKey", s.NegSyncerKey.String(), "zone", negLocation.Zone, "subnet", negLocation.Subnet)
634+
err := s.operationInternal(attachOp, negLocation, networkEndpointMap, s.logger)
635635

636636
// WARNING: commitTransaction must be called at last for analyzing the operation result
637637
s.commitTransaction(err, networkEndpointMap)
638638
}
639639

640640
// detachNetworkEndpoints runs operation for detaching network endpoints.
641-
func (s *transactionSyncer) detachNetworkEndpoints(epGroupInfo negtypes.NEGLocation, networkEndpointMap map[negtypes.NetworkEndpoint]*composite.NetworkEndpoint, hasMigrationDetachments bool) {
642-
s.logger.V(2).Info("Detaching endpoints from NEG.", "countOfEndpointsBeingDetached", len(networkEndpointMap), "negSyncerKey", s.NegSyncerKey.String(), "zone", epGroupInfo.Zone, "subnet", epGroupInfo.Subnet)
643-
err := s.operationInternal(detachOp, epGroupInfo, networkEndpointMap, s.logger)
641+
func (s *transactionSyncer) detachNetworkEndpoints(negLocation negtypes.NEGLocation, networkEndpointMap map[negtypes.NetworkEndpoint]*composite.NetworkEndpoint, hasMigrationDetachments bool) {
642+
s.logger.V(2).Info("Detaching endpoints from NEG.", "countOfEndpointsBeingDetached", len(networkEndpointMap), "negSyncerKey", s.NegSyncerKey.String(), "zone", negLocation.Zone, "subnet", negLocation.Subnet)
643+
err := s.operationInternal(detachOp, negLocation, networkEndpointMap, s.logger)
644644

645645
if hasMigrationDetachments {
646646
// Unpause the migration since the ongoing migration-detachments have
@@ -655,14 +655,14 @@ func (s *transactionSyncer) detachNetworkEndpoints(epGroupInfo negtypes.NEGLocat
655655
// operationInternal executes NEG API call and commits the transactions
656656
// It will record events when operations are completed
657657
// If error occurs or any transaction entry requires reconciliation, it will trigger resync
658-
func (s *transactionSyncer) operationInternal(operation transactionOp, epGroupInfo negtypes.NEGLocation, networkEndpointMap map[negtypes.NetworkEndpoint]*composite.NetworkEndpoint, logger klog.Logger) error {
658+
func (s *transactionSyncer) operationInternal(operation transactionOp, negLocation negtypes.NEGLocation, networkEndpointMap map[negtypes.NetworkEndpoint]*composite.NetworkEndpoint, logger klog.Logger) error {
659659
var err error
660660
start := time.Now()
661661
networkEndpoints := []*composite.NetworkEndpoint{}
662662
for _, ne := range networkEndpointMap {
663663
networkEndpoints = append(networkEndpoints, ne)
664664
}
665-
zone := epGroupInfo.Zone
665+
zone := negLocation.Zone
666666
negName := s.NegSyncerKey.NegName
667667
if flags.F.EnableMultiSubnetClusterPhase1 {
668668
defaultSubnet, err := utils.KeyName(s.networkInfo.SubnetworkURL)
@@ -676,8 +676,8 @@ func (s *transactionSyncer) operationInternal(operation transactionOp, epGroupIn
676676
// (epGroupInfo.Subnet) is not the defaultSubnet, we are dealing with
677677
// the Multi-Subnet Cluster use case, wherein the name of the NEG would
678678
// need to be different.
679-
if s.networkInfo.IsDefault && epGroupInfo.Subnet != defaultSubnet {
680-
negName, err = s.getNonDefaultSubnetNEGName(epGroupInfo.Subnet)
679+
if s.networkInfo.IsDefault && negLocation.Subnet != defaultSubnet {
680+
negName, err = s.getNonDefaultSubnetNEGName(negLocation.Subnet)
681681
if err != nil {
682682
s.logger.Error(err, "Errored getting non-default subnet NEG name when updating NEG endpoints")
683683
return err

pkg/neg/syncers/utils.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,16 @@ func toZoneNetworkEndpointMap(eds []negtypes.EndpointsData, zoneGetter *zonegett
288288
continue
289289
}
290290
globalEPCount[negtypes.Total] += 1
291-
epGroupInfo, _, getEpGroupInfoErr := getEndpointZoneSubnet(endpointAddress, zoneGetter, logger)
292-
if getEpGroupInfoErr != nil {
293-
metrics.PublishNegControllerErrorCountMetrics(getEpGroupInfoErr, true)
294-
if enableMultiSubnetCluster && errors.Is(getEpGroupInfoErr, zonegetter.ErrNodeNotInDefaultSubnet) {
295-
epLogger.Error(getEpGroupInfoErr, "Detected endpoint not from default subnet. Skipping")
291+
negLocation, _, getNegLocationErr := getEndpointZoneSubnet(endpointAddress, zoneGetter, logger)
292+
if getNegLocationErr != nil {
293+
metrics.PublishNegControllerErrorCountMetrics(getNegLocationErr, true)
294+
if enableMultiSubnetCluster && errors.Is(getNegLocationErr, zonegetter.ErrNodeNotInDefaultSubnet) {
295+
epLogger.Error(getNegLocationErr, "Detected endpoint not from default subnet. Skipping")
296296
localEPCount[negtypes.NodeInNonDefaultSubnet]++
297297
continue
298298
}
299-
epLogger.Error(getEpGroupInfoErr, "Detected unexpected error when getting zone for endpoint")
300-
return ZoneNetworkEndpointMapResult{}, fmt.Errorf("unexpected error when getting zone for endpoint %q in endpoint slice %s/%s: %w", endpointAddress.Addresses, ed.Meta.Namespace, ed.Meta.Name, getEpGroupInfoErr)
299+
epLogger.Error(getNegLocationErr, "Detected unexpected error when getting zone for endpoint")
300+
return ZoneNetworkEndpointMapResult{}, fmt.Errorf("unexpected error when getting zone for endpoint %q in endpoint slice %s/%s: %w", endpointAddress.Addresses, ed.Meta.Namespace, ed.Meta.Name, getNegLocationErr)
301301
}
302302

303303
_, _, getPodErr := getEndpointPod(endpointAddress, podLister)
@@ -311,8 +311,8 @@ func toZoneNetworkEndpointMap(eds []negtypes.EndpointsData, zoneGetter *zonegett
311311
epLogger.V(2).Info("Endpoint does not have an associated pod. Skipping")
312312
continue
313313
}
314-
if zoneNetworkEndpointMap[epGroupInfo] == nil {
315-
zoneNetworkEndpointMap[epGroupInfo] = negtypes.NewNetworkEndpointSet()
314+
if zoneNetworkEndpointMap[negLocation] == nil {
315+
zoneNetworkEndpointMap[negLocation] = negtypes.NewNetworkEndpointSet()
316316
}
317317

318318
podIPs := ipsForPod[types.NamespacedName{Namespace: endpointAddress.TargetRef.Namespace, Name: endpointAddress.TargetRef.Name}]
@@ -331,7 +331,7 @@ func toZoneNetworkEndpointMap(eds []negtypes.EndpointsData, zoneGetter *zonegett
331331
// Non-GCP network endpoints don't have associated nodes.
332332
networkEndpoint.Node = ""
333333
}
334-
zoneNetworkEndpointMap[epGroupInfo].Insert(networkEndpoint)
334+
zoneNetworkEndpointMap[negLocation].Insert(networkEndpoint)
335335

336336
// if existing name is alphabetically lower than current one, continue and don't replace
337337
if existingPod, contains := networkEndpointPodMap[networkEndpoint]; contains {
@@ -484,9 +484,9 @@ func toZoneNetworkEndpointMapDegradedMode(eds []negtypes.EndpointsData, zoneGett
484484
localEPCount[negtypes.NodeNotFound]++
485485
continue
486486
}
487-
epGroupInfo := negtypes.NEGLocation{Zone: zone, Subnet: subnet}
488-
if zoneNetworkEndpointMap[epGroupInfo] == nil {
489-
zoneNetworkEndpointMap[epGroupInfo] = negtypes.NewNetworkEndpointSet()
487+
negLocation := negtypes.NEGLocation{Zone: zone, Subnet: subnet}
488+
if zoneNetworkEndpointMap[negLocation] == nil {
489+
zoneNetworkEndpointMap[negLocation] = negtypes.NewNetworkEndpointSet()
490490
}
491491

492492
podIPs := ipsForPod[types.NamespacedName{Namespace: endpointAddress.TargetRef.Namespace, Name: endpointAddress.TargetRef.Name}]
@@ -529,7 +529,7 @@ func toZoneNetworkEndpointMapDegradedMode(eds []negtypes.EndpointsData, zoneGett
529529
// Non-GCP network endpoints don't have associated nodes.
530530
networkEndpoint.Node = ""
531531
}
532-
zoneNetworkEndpointMap[epGroupInfo].Insert(networkEndpoint)
532+
zoneNetworkEndpointMap[negLocation].Insert(networkEndpoint)
533533

534534
// if existing name is alphabetically lower than current one, continue and don't replace
535535
if existingPod, contains := networkEndpointPodMap[networkEndpoint]; contains {

0 commit comments

Comments
 (0)