Skip to content

Commit 24d1996

Browse files
fix(upgrades): run cleanup commands after adding scalers
Signed-off-by: Brooks Townsend <brooks@cosmonic.com>
1 parent 37dc530 commit 24d1996

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/workers/event.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ where
703703
.await;
704704
let scalers = self.scalers.scalers_for_manifest(&data.manifest);
705705

706-
if let Some(old_scalers) = old_scalers {
706+
let cleanup_commands = if let Some(old_scalers) = old_scalers {
707707
// This relies on the idea that an ID is a unique identifier for a scaler, and any
708708
// change in the ID is indicative of the fact that the scaler is outdated and should be cleaned up.
709709
let (_updated_component, outdated_component): (ScalerList, ScalerList) = old_scalers
@@ -714,18 +714,15 @@ where
714714
let futs = outdated_component
715715
.iter()
716716
.map(|s| async { s.cleanup().await });
717-
let commands = futures::future::join_all(futs)
717+
futures::future::join_all(futs)
718718
.await
719719
.into_iter()
720720
.filter_map(|res: Result<Vec<Command>>| res.ok())
721721
.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+
};
729726

730727
// Get the results of the first reconcilation pass before we store the scalers. Publish the
731728
// commands for the ones that succeeded (as those scalers will have entered backoff mode if
@@ -757,10 +754,19 @@ where
757754
warn!("Failed to set manifest status: {e:}");
758755
};
759756

760-
// Now handle the result from reconciliation
761757
trace!(?commands, "Publishing commands");
758+
// Handle the result from initial reconciliation
762759
self.command_publisher.publish_commands(commands).await?;
763760

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+
764770
res
765771
}
766772

0 commit comments

Comments
 (0)