8000 Cherrypick: fix status for invalid vs and vsr, for weight changes dyn… · nginx/kubernetes-ingress@f78a46b · GitHub
[go: up one dir, main page]

Skip to content

Commit f78a46b

Browse files
author
Jim Ryan
authored
Cherrypick: fix status for invalid vs and vsr, for weight changes dynamic reload … (#5464)
fix status for invalid vs and vsr, for weight changes dynamic reload (#5375)
1 parent 3b191c7 commit f78a46b

File tree

1 file changed

+97
-18
lines changed

1 file changed

+97
-18
lines changed

internal/k8s/controller.go

Lines changed: 97 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4285,10 +4285,6 @@ func (lbc *LoadBalancerController) addInternalRouteServer() {
42854285
}
42864286

42874287
func (lbc *LoadBalancerController) processVSWeightChangesDynamicReload(vsOld *conf_v1.VirtualServer, vsNew *conf_v1.VirtualServer) {
4288-
if lbc.haltIfVSConfigInvalid(vsNew) {
4289-
return
4290-
}
4291-
42924288
var weightUpdates []configs.WeightUpdate
42934289
var splitClientsIndex int
42944290
variableNamer := configs.NewVSVariableNamer(vsNew)
@@ -4298,7 +4294,7 @@ func (lbc *LoadBalancerController) processVSWeightChangesDynamicReload(vsOld *co
42984294
for j, matchNew := range routeNew.Matches {
42994295
matchOld := routeOld.Matches[j]
43004296
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 {
43024298
weightUpdates = append(weightUpdates, configs.WeightUpdate{
43034299
Zone: variableNamer.GetNameOfKeyvalZoneForSplitClientIndex(splitClientsIndex),
43044300
Key: variableNamer.GetNameOfKeyvalKeyForSplitClientIndex(splitClientsIndex),
@@ -4311,7 +4307,7 @@ func (lbc *LoadBalancerController) processVSWeightChangesDynamicReload(vsOld *co
43114307
}
43124308
}
43134309
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 {
43154311
weightUpdates = append(weightUpdates, configs.WeightUpdate{
43164312
Zone: variableNamer.GetNameOfKeyvalZoneForSplitClientIndex(splitClientsIndex),
43174313
Key: variableNamer.GetNameOfKeyvalKeyForSplitClientIndex(splitClientsIndex),
@@ -4324,14 +4320,39 @@ func (lbc *LoadBalancerController) processVSWeightChangesDynamicReload(vsOld *co
43244320
splitClientsIndex++
43254321
}
43264322
}
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+
43274337
for _, weight := range weightUpdates {
43284338
lbc.configurator.UpsertSplitClientsKeyVal(weight.Zone, weight.Key, weight.Value)
43294339
}
43304340
}
43314341

43324342
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+
43334354
halt, vsEx := lbc.haltIfVSRConfigInvalid(vsrNew)
4334-
if halt {
4355+
if vsEx == nil {
43354356
return
43364357
}
43374358

@@ -4346,7 +4367,7 @@ func (lbc *LoadBalancerController) processVSRWeightChangesDynamicReload(vsrOld *
43464367
for j, matchNew := range routeNew.Matches {
43474368
matchOld := routeOld.Matches[j]
43484369
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 {
43504371
weightUpdates = append(weightUpdates, configs.WeightUpdate{
43514372
Zone: variableNamer.GetNameOfKeyvalZoneForSplitClientIndex(splitClientsIndex),
43524373
Key: variableNamer.GetNameOfKeyvalKeyForSplitClientIndex(splitClientsIndex),
@@ -4359,7 +4380,7 @@ func (lbc *LoadBalancerController) processVSRWeightChangesDynamicReload(vsrOld *
43594380
}
43604381
}
43614382
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 {
43634384
weightUpdates = append(weightUpdates, configs.WeightUpdate{
43644385
Zone: variableNamer.GetNameOfKeyvalZoneForSplitClientIndex(splitClientsIndex),
43654386
Key: variableNamer.GetNameOfKeyvalKeyForSplitClientIndex(splitClientsIndex),
@@ -4371,6 +4392,11 @@ func (lbc *LoadBalancerController) processVSRWeightChangesDynamicReload(vsrOld *
43714392
splitClientsIndex++
43724393
}
43734394
}
4395+
4396+
if halt {
4397+
return
4398+
}
4399+
43744400
for _, weight := range weightUpdates {
43754401
lbc.configurator.UpsertSplitClientsKeyVal(weight.Zone, weight.Key, weight.Value)
43764402
}
@@ -4432,9 +4458,27 @@ func (lbc *LoadBalancerController) haltIfVSConfigInvalid(vsNew *conf_v1.VirtualS
44324458

44334459
changes, problems := lbc.configuration.rebuildHosts()
44344460

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+
44354480
if len(problems) > 0 {
44364481
lbc.processProblems(problems)
4437-
return true
44384482
}
44394483

44404484
if len(changes) == 0 {
@@ -4447,11 +4491,34 @@ func (lbc *LoadBalancerController) haltIfVSConfigInvalid(vsNew *conf_v1.VirtualS
44474491
case *VirtualServerConfiguration:
44484492
lbc.updateVirtualServerStatusAndEvents(impl, configs.Warnings{}, nil)
44494493
}
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+
}
44504517
}
44514518
}
44524519

44534520
lbc.configuration.virtualServers[key] = vsNew
4454-
return false
4521+
return len(problems) > 0
44554522
}
44564523

44574524
func (lbc *LoadBalancerController) haltIfVSRConfigInvalid(vsrNew *conf_v1.VirtualServerRoute) (bool, *configs.VirtualServerEx) {
@@ -4462,17 +4529,13 @@ func (lbc *LoadBalancerController) haltIfVSRConfigInvalid(vsrNew *conf_v1.Virtua
44624529

44634530
validationError := lbc.configuration.virtualServerValidator.ValidateVirtualServerRoute(vsrNew)
44644531
if validationError != nil {
4465-
delete(lbc.configuration.virtualServerRoutes, key)
4532+
lbc.AddSyncQueue(vsrNew)
4533+
return true, nil
44664534
} else {
44674535
lbc.configuration.virtualServerRoutes[key] = vsrNew
44684536
}
44694537

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()
44764539

44774540
if len(changes) == 0 {
44784541
return true, nil
@@ -4496,3 +4559,19 @@ func (lbc *LoadBalancerController) haltIfVSRConfigInvalid(vsrNew *conf_v1.Virtua
44964559
lbc.configuration.virtualServerRoutes[key] = vsrNew
44974560
return false, vsEx
44984561
}
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

Comments
 (0)
0