@@ -419,18 +419,34 @@ func (sc *StackContainer) updateStackResources() error {
419419}
420420
421421func (sc * StackContainer ) updateFromResources () {
422- sc .stackReplicas = effectiveReplicas (sc .Stack .Spec .StackSpec .Replicas )
422+ _ , clusterMigration := sc .Stack .Annotations [forwardBackendAnnotation ]
423+
424+ if clusterMigration {
425+ // we do not use these so reduce wasted resources!
426+ sc .stackReplicas = 1
427+ } else {
428+ sc .stackReplicas = effectiveReplicas (sc .Stack .Spec .StackSpec .Replicas )
429+ }
423430
424431 var deploymentUpdated , serviceUpdated , ingressUpdated , routeGroupUpdated , hpaUpdated bool
425432 var ingressSegmentUpdated , routeGroupSegmentUpdated bool
426433
427434 // deployment
428435 if sc .Resources .Deployment != nil {
429436 deployment := sc .Resources .Deployment
430- sc .deploymentReplicas = effectiveReplicas (deployment .Spec .Replicas )
431- sc .createdReplicas = deployment .Status .Replicas
432- sc .readyReplicas = deployment .Status .ReadyReplicas
433- sc .updatedReplicas = deployment .Status .UpdatedReplicas
437+
438+ if clusterMigration {
439+ // we do not use these so reduce wasted resources!
440+ sc .deploymentReplicas = 1
441+ sc .createdReplicas = 1
442+ sc .readyReplicas = 1
443+ sc .updatedReplicas = 1
444+ } else {
445+ sc .deploymentReplicas = effectiveReplicas (deployment .Spec .Replicas )
446+ sc .createdReplicas = deployment .Status .Replicas
447+ sc .readyReplicas = deployment .Status .ReadyReplicas
448+ sc .updatedReplicas = deployment .Status .UpdatedReplicas
449+ }
434450 deploymentUpdated = IsResourceUpToDate (sc .Stack , sc .Resources .Deployment .ObjectMeta ) && deployment .Status .ObservedGeneration == deployment .Generation
435451 }
436452
@@ -442,13 +458,20 @@ func (sc *StackContainer) updateFromResources() {
442458 // the per-stack ingress must either be present and up-to-date, or not present and not expected.
443459 // the per-stack ingress is not expected if the stack has no hostnames matching the cluster domain.
444460 if sc .Resources .Ingress != nil {
461+ if clusterMigration {
462+ sc .Resources .Ingress .Annotations ["zalando.org/skipper-backend" ] = "forward"
463+ }
445464 ingressUpdated = IsResourceUpToDate (sc .Stack , sc .Resources .Ingress .ObjectMeta )
446465 } else {
447466 hostnames := sc .stackHostnames (sc .ingressSpec , false )
448467 ingressUpdated = len (hostnames ) == 0
449468 }
450- ingressSegmentUpdated = sc .Resources .IngressSegment != nil &&
451- IsResourceUpToDate (sc .Stack , sc .Resources .IngressSegment .ObjectMeta )
469+ if sc .Resources .IngressSegment != nil {
470+ if clusterMigration {
471+ sc .Resources .IngressSegment .Annotations ["zalando.org/skipper-backend" ] = "forward"
472+ }
473+ ingressSegmentUpdated = IsResourceUpToDate (sc .Stack , sc .Resources .IngressSegment .ObjectMeta )
474+ }
452475 } else {
453476 // ignore if ingress is not set
454477 ingressUpdated = sc .Resources .Ingress == nil
@@ -460,24 +483,33 @@ func (sc *StackContainer) updateFromResources() {
460483 // the per-stack route group must either be present and up-to-date, or not present and not expected.
461484 // the per-stack route group is not expected if the stack has no hostnames matching the cluster domain.
462485 if sc .Resources .RouteGroup != nil {
486+ if clusterMigration {
487+ patchForwardBackend (& sc .Resources .RouteGroup .Spec )
488+ }
463489 routeGroupUpdated = IsResourceUpToDate (sc .Stack , sc .Resources .RouteGroup .ObjectMeta )
464490 } else {
465491 hostnames := sc .stackHostnames (sc .routeGroupSpec , false )
466492 routeGroupUpdated = len (hostnames ) == 0
467493 }
468- routeGroupSegmentUpdated = sc .Resources .RouteGroupSegment != nil &&
469- IsResourceUpToDate (
494+
495+ if sc .Resources .RouteGroupSegment != nil {
496+ if clusterMigration {
497+ patchForwardBackend (& sc .Resources .RouteGroupSegment .Spec )
498+ }
499+
500+ routeGroupSegmentUpdated = IsResourceUpToDate (
470501 sc .Stack ,
471502 sc .Resources .RouteGroupSegment .ObjectMeta ,
472503 )
504+ }
473505 } else {
474506 // ignore if route group is not set
475507 routeGroupUpdated = sc .Resources .RouteGroup == nil
476508 routeGroupSegmentUpdated = sc .Resources .RouteGroupSegment == nil
477509 }
478510
479- // hpa
480- if sc .IsAutoscaled () {
511+ // hpa not used if we migrate cluster to reduce wasted resources
512+ if sc .IsAutoscaled () && ! clusterMigration {
481513 hpaUpdated = sc .Resources .HPA != nil && IsResourceUpToDate (sc .Stack , sc .Resources .HPA .ObjectMeta )
482514 } else {
483515 hpaUpdated = sc .Resources .HPA == nil
@@ -494,10 +526,27 @@ func (sc *StackContainer) updateFromResources() {
494526
495527 status := sc .Stack .Status
496528 sc .noTrafficSince = unwrapTime (status .NoTrafficSince )
497- if status .Prescaling .Active {
529+ // do not prescale on cluste rmigration to reduce wasted resources
530+ if status .Prescaling .Active && ! clusterMigration {
498531 sc .prescalingActive = true
499532 sc .prescalingReplicas = status .Prescaling .Replicas
500533 sc .prescalingDesiredTrafficWeight = status .Prescaling .DesiredTrafficWeight
501534 sc .prescalingLastTrafficIncrease = unwrapTime (status .Prescaling .LastTrafficIncrease )
502535 }
503536}
537+
538+ func patchForwardBackend (rg * rgv1.RouteGroupSpec ) {
539+ rg .Backends = []rgv1.RouteGroupBackend {
540+ {
541+ Name : forwardBackendName ,
542+ Type : rgv1 .ForwardRouteGroupBackend ,
543+ },
544+ }
545+ for _ , route := range rg .Routes {
546+ route .Backends = []rgv1.RouteGroupBackendReference {
547+ {
548+ BackendName : forwardBackendName ,
549+ },
550+ }
551+ }
552+ }
0 commit comments