@@ -108,7 +108,22 @@ func (c *Controller) enqueueUpdateService(old, new interface{}) {
108
108
utilruntime .HandleError (err )
109
109
return
110
110
}
111
+
112
+ oldClusterIps := getVipIps (oldSvc )
113
+ newClusterIps := getVipIps (newSvc )
114
+ var ipsToDel []string
115
+ for _ , oldClusterIp := range oldClusterIps {
116
+ if ! util .ContainsString (newClusterIps , oldClusterIp ) {
117
+ ipsToDel = append (ipsToDel , oldClusterIp )
118
+ }
119
+ }
120
+
111
121
klog .V (3 ).Infof ("enqueue update service %s" , key )
122
+ if len (ipsToDel ) != 0 {
123
+ ipsToDelStr := strings .Join (ipsToDel , "," )
124
+ key = strings .Join ([]string {key , ipsToDelStr }, "#" )
125
+ }
126
+
112
127
c .updateServiceQueue .Add (key )
113
128
}
114
129
@@ -269,6 +284,14 @@ func (c *Controller) handleDeleteService(service *vpcService) error {
269
284
}
270
285
271
286
func (c * Controller ) handleUpdateService (key string ) error {
287
+ keys := strings .Split (key , "#" )
288
+ key = keys [0 ]
289
+ var ipsToDel []string
290
+ if len (keys ) == 2 {
291
+ ipsToDelStr := keys [1 ]
292
+ ipsToDel = strings .Split (ipsToDelStr , "," )
293
+ }
294
+
272
295
namespace , name , err := cache .SplitMetaNamespaceKey (key )
273
296
if err != nil {
274
297
utilruntime .HandleError (fmt .Errorf ("invalid resource key: %s" , key ))
@@ -283,12 +306,7 @@ func (c *Controller) handleUpdateService(key string) error {
283
306
return err
284
307
}
285
308
286
- var ips []string
287
- if vip , ok := svc .Annotations [util .SwitchLBRuleVipsAnnotation ]; ok {
288
- ips = strings .Split (vip , "," )
289
- } else {
290
- ips = util .ServiceClusterIPs (* svc )
291
- }
309
+ ips := getVipIps (svc )
292
310
293
311
vpcName := svc .Annotations [util .VpcAnnotation ]
294
312
if vpcName == "" {
@@ -340,7 +358,7 @@ func (c *Controller) handleUpdateService(key string) error {
340
358
}
341
359
}
342
360
for vip := range vips {
343
- if ip := parseVipAddr (vip ); util .ContainsString (ips , ip ) && ! util .IsStringIn (vip , svcVips ) {
361
+ if ip := parseVipAddr (vip ); ( util .ContainsString (ips , ip ) && ! util .IsStringIn (vip , svcVips )) || util . ContainsString ( ipsToDel , ip ) {
344
362
klog .Infof ("remove stale vip %s from LB %s" , vip , lb )
345
363
if err = c .ovnLegacyClient .DeleteLoadBalancerVip (vip , lb ); err != nil {
346
364
klog .Errorf ("failed to delete vip %s from LB %s: %v" , vip , lb , err )
@@ -354,7 +372,7 @@ func (c *Controller) handleUpdateService(key string) error {
354
372
}
355
373
klog .V (3 ).Infof ("existing vips of LB %s: %v" , oLb , vips )
356
374
for vip := range vips {
357
- if ip := parseVipAddr (vip ); util .ContainsString (ips , ip ) {
375
+ if ip := parseVipAddr (vip ); util .ContainsString (ips , ip ) || util . ContainsString ( ipsToDel , ip ) {
358
376
klog .Infof ("remove stale vip %s from LB %s" , vip , oLb )
359
377
if err = c .ovnLegacyClient .DeleteLoadBalancerVip (vip , oLb ); err != nil {
360
378
klog .Errorf ("failed to delete vip %s from LB %s: %v" , vip , oLb , err )
@@ -473,3 +491,13 @@ func (c *Controller) handleAddService(key string) error {
473
491
474
492
return nil
475
493
}
494
+
495
+ func getVipIps (svc * v1.Service ) []string {
496
+ var ips []string
497
+ if vip , ok := svc .Annotations [util .SwitchLBRuleVipsAnnotation ]; ok {
498
+ ips = strings .Split (vip , "," )
499
+ } else {
500
+ ips = util .ServiceClusterIPs (* svc )
501
+ }
502
+ return ips
503
+ }
0 commit comments