@@ -324,12 +324,12 @@ func (s *Controller) workloadEntryHandler(old, curr config.Config, event model.E
324
324
if event == model .EventAdd {
325
325
s .XdsUpdater .ProxyUpdate (s .Cluster (), wle .Address )
326
326
}
327
- s .edsUpdate (allInstances )
327
+ s .edsUpdate (allInstances , true )
328
328
return
329
329
}
330
330
331
331
// update eds cache only
332
- s .edsCacheUpdate (allInstances )
332
+ s .edsUpdate (allInstances , false )
333
333
334
334
pushReq := & model.PushRequest {
335
335
Full : true ,
@@ -451,7 +451,7 @@ func (s *Controller) serviceEntryHandler(old, curr config.Config, event model.Ev
451
451
fullPush := len (configsUpdated ) > 0
452
452
// if not full push needed, at least one service unchanged
453
453
if ! fullPush {
454
- s .edsUpdate (serviceInstances )
454
+ s .edsUpdate (serviceInstances , true )
455
455
return
456
456
}
457
457
@@ -468,7 +468,7 @@ func (s *Controller) serviceEntryHandler(old, curr config.Config, event model.Ev
468
468
keys .Insert (instancesKey {hostname : svc .Hostname , namespace : curr .Namespace })
469
469
}
470
470
471
- s .queueEdsEvent (keys , s . doEdsCacheUpdate )
471
+ s .queueEdsEvent (keys , false )
472
472
473
473
pushReq := & model.PushRequest {
474
474
Full : true ,
@@ -604,7 +604,7 @@ func (s *Controller) WorkloadInstanceHandler(wi *model.WorkloadInstance, event m
604
604
605
605
s .mutex .Unlock ()
606
606
607
- s .edsUpdate (append (instances , instancesDeleted ... ))
607
+ s .edsUpdate (append (instances , instancesDeleted ... ), true )
608
608
609
609
// ServiceEntry with WorkloadEntry results in STRICT_DNS cluster with hardcoded endpoints
610
610
// need to update CDS to refresh endpoints
@@ -691,7 +691,7 @@ func (s *Controller) ResyncEDS() {
691
691
s .mutex .RLock ()
692
692
allInstances := s .serviceInstances .getAll ()
693
693
s .mutex .RUnlock ()
694
- s .edsUpdate (allInstances )
694
+ s .edsUpdate (allInstances , true )
695
695
// HACK to workaround Service syncing after WorkloadEntry: https://github.com/istio/istio/issues/45114
696
696
s .workloadInstances .ForEach (func (wi * model.WorkloadInstance ) {
697
697
if wi .Kind == model .WorkloadEntryKind {
@@ -703,35 +703,27 @@ func (s *Controller) ResyncEDS() {
703
703
// edsUpdate triggers an EDS push serially such that we can prevent all instances
704
704
// got at t1 can accidentally override that got at t2 if multiple threads are
705
705
// running this function. Queueing ensures latest updated wins.
706
- func (s * Controller ) edsUpdate (instances []* model.ServiceInstance ) {
706
+ func (s * Controller ) edsUpdate (instances []* model.ServiceInstance , pushEds bool ) {
707
707
// Find all keys we need to lookup
708
708
keys := sets.NewWithLength [instancesKey ](len (instances ))
709
709
for _ , i := range instances {
710
710
keys .Insert (makeInstanceKey (i ))
711
711
}
712
- s .queueEdsEvent (keys , s .doEdsUpdate )
713
- }
714
-
715
- // edsCacheUpdate updates eds cache serially such that we can prevent allinstances
716
- // got at t1 can accidentally override that got at t2 if multiple threads are
717
- // running this function. Queueing ensures latest updated wins.
718
- func (s * Controller ) edsCacheUpdate (instances []* model.ServiceInstance ) {
719
- // Find all keys we need to lookup
720
- keys := map [instancesKey ]struct {}{}
721
- for _ , i := range instances {
722
- keys [makeInstanceKey (i )] = struct {}{}
723
- }
724
- s .queueEdsEvent (keys , s .doEdsCacheUpdate )
712
+ s .queueEdsEvent (keys , pushEds )
725
713
}
726
714
727
715
// queueEdsEvent processes eds events sequentially for the passed keys and invokes the passed function.
728
- func (s * Controller ) queueEdsEvent (keys sets.Set [instancesKey ], edsFn func ( keys sets. Set [ instancesKey ]) ) {
716
+ func (s * Controller ) queueEdsEvent (keys sets.Set [instancesKey ], pushEds bool ) {
729
717
// wait for the cache update finished
730
718
waitCh := make (chan struct {})
731
719
// trigger update eds endpoint shards
732
720
s .edsQueue .Push (func () error {
733
721
defer close (waitCh )
734
- edsFn (keys )
722
+ xdsUpdateFn := s .XdsUpdater .EDSCacheUpdate
723
+ if pushEds {
724
+ xdsUpdateFn = s .XdsUpdater .EDSUpdate
725
+ }
726
+ s .doEdsUpdate (keys , xdsUpdateFn )
735
727
return nil
736
728
})
737
729
select {
@@ -744,34 +736,17 @@ func (s *Controller) queueEdsEvent(keys sets.Set[instancesKey], edsFn func(keys
744
736
}
745
737
}
746
738
747
- // doEdsCacheUpdate invokes XdsUpdater's EDSCacheUpdate to update endpoint shards.
748
- func (s * Controller ) doEdsCacheUpdate (keys sets.Set [instancesKey ]) {
739
+ func (s * Controller ) doEdsUpdate (keys sets.Set [instancesKey ], xdsUpdateFn model.EdsUpdateFn ) {
749
740
endpoints := s .buildEndpoints (keys )
750
741
shard := model .ShardKeyFromRegistry (s )
751
742
752
743
for k := range keys {
753
744
if eps , ok := endpoints [k ]; ok {
754
745
// Update the cache with the generated endpoints.
755
- s .XdsUpdater .EDSCacheUpdate (shard , string (k .hostname ), k .namespace , eps )
756
- } else {
757
- // Handle deletions by sending a nil endpoints update.
758
- s .XdsUpdater .EDSCacheUpdate (shard , string (k .hostname ), k .namespace , nil )
759
- }
760
- }
761
- }
762
-
763
- // doEdsUpdate invokes XdsUpdater's eds update to trigger eds push.
764
- func (s * Controller ) doEdsUpdate (keys sets.Set [instancesKey ]) {
765
- endpoints := s .buildEndpoints (keys )
766
- shard := model .ShardKeyFromRegistry (s )
767
-
768
- for k := range keys {
769
- if eps , ok := endpoints [k ]; ok {
770
- // Update with the generated endpoints.
771
- s .XdsUpdater .EDSUpdate (shard , string (k .hostname ), k .namespace , eps )
746
+ xdsUpdateFn (shard , string (k .hostname ), k .namespace , eps )
772
747
} else {
773
748
// Handle deletions by sending a nil endpoints update.
774
- s . XdsUpdater . EDSUpdate (shard , string (k .hostname ), k .namespace , nil )
749
+ xdsUpdateFn (shard , string (k .hostname ), k .namespace , nil )
775
750
}
776
751
}
777
752
}
0 commit comments