@@ -703,7 +703,7 @@ where
703
703
. await ;
704
704
let scalers = self . scalers . scalers_for_manifest ( & data. manifest ) ;
705
705
706
- if let Some ( old_scalers) = old_scalers {
706
+ let cleanup_commands = if let Some ( old_scalers) = old_scalers {
707
707
// This relies on the idea that an ID is a unique identifier for a scaler, and any
708
708
// change in the ID is indicative of the fact that the scaler is outdated and should be cleaned up.
709
709
let ( _updated_component, outdated_component) : ( ScalerList , ScalerList ) = old_scalers
@@ -714,18 +714,15 @@ where
714
714
let futs = outdated_component
715
715
. iter ( )
716
716
. map ( |s| async { s. cleanup ( ) . await } ) ;
717
- let commands = futures:: future:: join_all ( futs)
717
+ futures:: future:: join_all ( futs)
718
718
. await
719
719
. into_iter ( )
720
720
. filter_map ( |res : Result < Vec < Command > > | res. ok ( ) )
721
721
. flatten ( )
722
- . collect :: < Vec < Command > > ( ) ;
723
-
724
- // Now handle the result from cleaning up old scalers
725
- if let Err ( e) = self . command_publisher . publish_commands ( commands) . await {
726
- warn ! ( error = ?e, "Failed to publish cleanup commands from old application, some resources may be left behind" ) ;
727
- } ;
728
- }
722
+ . collect :: < Vec < Command > > ( )
723
+ } else {
724
+ vec ! [ ]
725
+ } ;
729
726
730
727
// Get the results of the first reconcilation pass before we store the scalers. Publish the
731
728
// commands for the ones that succeeded (as those scalers will have entered backoff mode if
@@ -757,10 +754,19 @@ where
757
754
warn ! ( "Failed to set manifest status: {e:}" ) ;
758
755
} ;
759
756
760
- // Now handle the result from reconciliation
761
757
trace ! ( ?commands, "Publishing commands" ) ;
758
+ // Handle the result from initial reconciliation
762
759
self . command_publisher . publish_commands ( commands) . await ?;
763
760
761
+ // Handle the result from cleaning up old scalers
762
+ if let Err ( e) = self
763
+ . command_publisher
764
+ . publish_commands ( cleanup_commands)
765
+ . await
766
+ {
767
+ warn ! ( error = ?e, "Failed to publish cleanup commands from old application, some resources may be left behind" ) ;
768
+ }
769
+
764
770
res
765
771
}
766
772
0 commit comments