@@ -4285,10 +4285,6 @@ func (lbc *LoadBalancerController) addInternalRouteServer() {
4285
4285
}
4286
4286
4287
4287
func (lbc * LoadBalancerController ) processVSWeightChangesDynamicReload (vsOld * conf_v1.VirtualServer , vsNew * conf_v1.VirtualServer ) {
4288
- if lbc .haltIfVSConfigInvalid (vsNew ) {
4289
- return
4290
- }
4291
-
4292
4288
var weightUpdates []configs.WeightUpdate
4293
4289
var splitClientsIndex int
4294
4290
variableNamer := configs .NewVSVariableNamer (vsNew )
@@ -4298,7 +4294,7 @@ func (lbc *LoadBalancerController) processVSWeightChangesDynamicReload(vsOld *co
4298
4294
for j , matchNew := range routeNew .Matches {
4299
4295
matchOld := routeOld .Matches [j ]
4300
4296
if len (matchNew .Splits ) == 2 {
4301
- if matchNew .Splits [0 ].Weight != matchOld .Splits [0 ].Weight && matchNew .Splits [1 ].Weight != matchOld .
E880
Splits [1 ].Weight {
4297
+ if matchNew .Splits [0 ].Weight != matchOld .Splits [0 ].Weight || matchNew .Splits [1 ].Weight != matchOld .Splits [1 ].Weight {
4302
4298
weightUpdates = append (weightUpdates , configs.WeightUpdate {
4303
4299
Zone : variableNamer .GetNameOfKeyvalZoneForSplitClientIndex (splitClientsIndex ),
4304
4300
Key : variableNamer .GetNameOfKeyvalKeyForSplitClientIndex (splitClientsIndex ),
@@ -4311,7 +4307,7 @@ func (lbc *LoadBalancerController) processVSWeightChangesDynamicReload(vsOld *co
4311
4307
}
4312
4308
}
4313
4309
if len (routeNew .Splits ) == 2 {
4314
- if routeNew .Splits [0 ].Weight != routeOld .Splits [0 ].Weight && routeNew .Splits [1 ].Weight != routeOld .Splits [1 ].Weight {
4310
+ if routeNew .Splits [0 ].Weight != routeOld .Splits [0 ].Weight || routeNew .Splits [1 ].Weight != routeOld .Splits [1 ].Weight {
4315
4311
weightUpdates = append (weightUpdates , configs.WeightUpdate {
4316
4312
Zone : variableNamer .GetNameOfKeyvalZoneForSplitClientIndex (splitClientsIndex ),
4317
4313
Key : variableNamer .GetNameOfKeyvalKeyForSplitClientIndex (splitClientsIndex ),
@@ -4324,14 +4320,39 @@ func (lbc *LoadBalancerController) processVSWeightChangesDynamicReload(vsOld *co
4324
4320
splitClientsIndex ++
4325
4321
}
4326
4322
}
4323
+
4324
+ if len (weightUpdates ) == 0 {
4325
+ return
4326
+ }
4327
+
4328
+ if vsOld .Status .State == conf_v1 .StateInvalid {
4329
+ lbc .AddSyncQueue (vsNew )
4330
+ return
4331
+ }
4332
+
4333
+ if lbc .haltIfVSConfigInvalid (vsNew ) {
4334
+ return
4335
+ }
4336
+
4327
4337
for _ , weight := range weightUpdates {
4328
4338
lbc .configurator .UpsertSplitClientsKeyVal (weight .Zone , weight .Key , weight .Value )
4329
4339
}
4330
4340
}
4331
4341
4332
4342
func (lbc * LoadBalancerController ) processVSRWeightChangesDynamicReload (vsrOld * conf_v1.VirtualServerRoute , vsrNew * conf_v1.VirtualServerRoute ) {
4343
+ if ! lbc .vsrHasWeightChanges (vsrOld , vsrNew ) {
4344
+ return
4345
+ }
4346
+
4347
+ if vsrOld .Status .State == conf_v1 .StateInvalid {
4348
+ changes , problems := lbc .configuration .AddOrUpdateVirtualServerRoute (vsrNew )
4349
+ lbc .processProblems (problems )
4350
+ lbc .processChanges (changes )
4351
+ return
4352
+ }
4353
+
4333
4354
halt , vsEx := lbc .haltIfVSRConfigInvalid (vsrNew )
4334
- if halt {
4355
+ if vsEx == nil {
4335
4356
return
4336
4357
}
4337
4358
@@ -4346,7 +4367,7 @@ func (lbc *LoadBalancerController) processVSRWeightChangesDynamicReload(vsrOld *
4346
4367
for j , matchNew := range routeNew .Matches {
4347
4368
matchOld := routeOld .Matches [j ]
4348
4369
if len (matchNew .Splits ) == 2 {
4349
- if matchNew .Splits [0 ].Weight != matchOld .Splits [0 ].Weight && matchNew .Splits [1 ].Weight != matchOld .Splits [1 ].Weight {
4370
+ if matchNew .Splits [0 ].Weight != matchOld .Splits [0 ].Weight || matchNew .Splits [1 ].Weight != matchOld .Splits [1 ].Weight {
4350
4371
weightUpdates = append (weightUpdates , configs.WeightUpdate {
4351
4372
Zone : variableNamer .GetNameOfKeyvalZoneForSplitClientIndex (splitClientsIndex ),
4352
4373
Key : variableNamer .GetNameOfKeyvalKeyForSplitClientIndex (splitClientsIndex ),
@@ -4359,7 +4380,7 @@ func (lbc *LoadBalancerController) processVSRWeightChangesDynamicReload(vsrOld *
4359
4380
}
4360
4381
}
4361
4382
if len (routeNew .Splits ) == 2 {
4362
- if routeNew .Splits [0 ].Weight != routeOld .Splits [0 ].Weight && routeNew .Splits [1 ].Weight != routeOld .Splits [1 ].Weight {
4383
+ if routeNew .Splits [0 ].Weight != routeOld .Splits [0 ].Weight || routeNew .Splits [1 ].Weight != routeOld .Splits [1 ].Weight {
4363
4384
weightUpdates = append (weightUpdates , configs.WeightUpdate {
4364
4385
Zone : variableNamer .GetNameOfKeyvalZoneForSplitClientIndex (splitClientsIndex ),
4365
4386
Key : variableNamer .GetNameOfKeyvalKeyForSplitClientIndex (splitClientsIndex ),
@@ -4371,6 +4392,11 @@ func (lbc *LoadBalancerController) processVSRWeightChangesDynamicReload(vsrOld *
4371
4392
splitClientsIndex ++
4372
4393
}
4373
4394
}
4395
+
4396
+ if halt {
4397
+ return
4398
+ }
4399
+
4374
4400
for _ , weight := range weightUpdates {
4375
4401
lbc .configurator .UpsertSplitClientsKeyVal (weight .Zone , weight .Key , weight .Value )
4376
4402
}
@@ -4432,9 +4458,27 @@ func (lbc *LoadBalancerController) haltIfVSConfigInvalid(vsNew *conf_v1.VirtualS
4432
4458
4433
4459
changes , problems := lbc .configuration .rebuildHosts ()
4434
4460
4461
+ if validationError != nil {
4462
+
4463
+ kind := getResourceKeyWithKind (virtualServerKind , & vsNew .ObjectMeta )
4464
+ for i := range changes {
4465
+ k := changes [i ].Resource .GetKeyWithKind ()
4466
+
4467
+ if k == kind {
4468
+ changes [i ].Error = validationError .Error ()
4469
+ }
4470
+ }
4471
+ p := ConfigurationProblem {
4472
+ Object : vsNew ,
4473
+ IsError : true ,
4474
+ Reason : "Rejected" ,
4475
+ Message : fmt .Sprintf ("VirtualServer %s was rejected with error: %s" , getResourceKey (& vsNew .ObjectMeta ), validationError .Error ()),
4476
+ }
4477
+ problems = append (problems , p )
4478
+ }
4479
+
4435
4480
if len (problems ) > 0 {
4436
4481
lbc .processProblems (problems )
4437
- return true
4438
4482
}
4439
4483
4440
4484
if len (changes ) == 0 {
@@ -4447,11 +4491,34 @@ func (lbc *LoadBalancerController) haltIfVSConfigInvalid(vsNew *conf_v1.VirtualS
4447
4491
case * VirtualServerConfiguration :
4448
4492
lbc .updateVirtualServerStatusAndEvents (impl , configs.Warnings {}, nil )
4449
4493
}
4494
+ } else if c .Op == Delete {
4495
+ switch impl := c .Resource .(type ) {
4496
+ case * VirtualServerConfiguration :
4497
+ key := getResourceKey (& impl .VirtualServer .ObjectMeta )
4498
+
4499
+ deleteErr := lbc .configurator .DeleteVirtualServer (key , false )
4500
+ if deleteErr != nil {
4501
+ glog .Errorf ("Error when deleting configuration for VirtualServer %v: %v" , key , deleteErr )
4502
+ }
4503
+
4504
+ var vsExists bool
4505
+ var err error
4506
+
4507
+ ns , _ , _ := cache .SplitMetaNamespaceKey (key )
4508
+ _ , vsExists , err = lbc .getNamespacedInformer (ns ).virtualServerLister .GetByKey (key )
4509
+ if err != nil {
4510
+ glog .Errorf ("Error when getting VirtualServer for %v: %v" , key , err )
4511
+ }
4512
+
4513
+ if vsExists {
4514
+ lbc .UpdateVirtualServerStatusAndEventsOnDelete (impl , c .Error , deleteErr )
4515
+ }
4516
+ }
4450
4517
}
4451
4518
}
4452
4519
4453
4520
lbc .configuration .virtualServers [key ] = vsNew
4454
- return false
4521
+ return len ( problems ) > 0
4455
4522
}
4456
4523
4457
4524
func (lbc * LoadBalancerController ) haltIfVSRConfigInvalid (vsrNew * conf_v1.VirtualServerRoute ) (bool , * configs.VirtualServerEx ) {
@@ -4462,17 +4529,13 @@ func (lbc *LoadBalancerController) haltIfVSRConfigInvalid(vsrNew *conf_v1.Virtua
4462
4529
4463
4530
validationError := lbc .configuration .virtualServerValidator .ValidateVirtualServerRoute (vsrNew )
4464
4531
if validationError != nil {
4465
- delete (lbc .configuration .virtualServerRoutes , key )
4532
+ lbc .AddSyncQueue (vsrNew )
4533
+ return true , nil
4466
4534
} else {
4467
4535
lbc .configuration .virtualServerRoutes [key ] = vsrNew
4468
4536
}
4469
4537
4470
- changes , problems := lbc .configuration .rebuildHosts ()
4471
-
4472
- if len (problems ) > 0 {
4473
- lbc .processProblems (problems )
4474
- return true , nil
4475
- }
4538
+ changes , _ := lbc .configuration .rebuildHosts ()
4476
4539
4477
4540
if len (changes ) == 0 {
4478
4541
return true , nil
@@ -4496,3 +4559,19 @@ func (lbc *LoadBalancerController) haltIfVSRConfigInvalid(vsrNew *conf_v1.Virtua
4496
4559
lbc .configuration .virtualServerRoutes [key ] = vsrNew
4497
4560
return false , vsEx
4498
4561
}
4562
+
4563
+ func (lbc * LoadBalancerController ) vsrHasWeightChanges (vsrOld * conf_v1.VirtualServerRoute , vsrNew * conf_v1.VirtualServerRoute ) bool {
4564
+ for i , routeNew := range vsrNew .Spec .Subroutes {
4565
+ routeOld := vsrOld .Spec .Subroutes [i ]
4566
+ for j , matchNew := range routeNew .Matches {
4567
+ matchOld := routeOld .Matches [j ]
4568
+ if len (matchNew .Splits ) == 2 && (matchNew .Splits [0 ].Weight != matchOld .Splits [0 ].Weight || matchNew .Splits [1 ].Weight != matchOld .Splits [1 ].Weight ) {
4569
+ return true
4570
+ }
4571
+ }
4572
+ if len (routeNew .Splits ) == 2 && (routeNew .Splits [0 ].Weight != routeOld .Splits [0 ].Weight || routeNew .Splits [1 ].Weight != routeOld .Splits [1 ].Weight ) {
4573
+ return true
4574
+ }
4575
+ }
4576
+ return false
4577
+ }
0 commit comments