isothrum_runner/run/update.rs
1//! Bringing a running run up to date with its manifest. The embedder regenerated the manifest
2//! (a machine added to the run or taken out of it, a set-up changed) and opened the run on it;
3//! `up`'s steps run again against what is up, with the params the run was started with, so each
4//! engine converges: Terraform makes and removes what changed, Compose starts new services,
5//! Vagrant brings up new VMs. Then, as at `up`, the guests' secrets, the ready conditions, the
6//! outputs and the message.
7//!
8//! What an update won't remove itself the embedder retires before calling it
9//! ([`Running::retire`]): a VM taken out (Vagrant forgets a define the Vagrantfile no longer
10//! has), a Compose service taken out or moved out of the default start.
11//!
12//! A machine that was running keeps what it was given: the guests' secrets go to new machines
13//! only (an update carries no launch's values, which a run never keeps).
14//!
15//! A sealed run stays sealed: its recorded seal is replayed, so a machine added to an
16//! `internet: false` network sets itself up without the internet.
17//!
18//! A running VM whose boot-time settings changed is restarted first ([`super::boot`]).
19
20use super::Running;
21use super::operation::Done;
22use crate::Result;
23use crate::events::{Emitter, Events};
24use crate::options::RunOptions;
25use crate::secrets::check_secrets;
26use crate::state::Op;
27use crate::status::Started;
28use crate::tools;
29
30impl Running<'_> {
31 /// Brings the running run up to date with its manifest (see the module doc): `up`'s steps
32 /// again, with the run's recorded params and `opts`' secrets, then what follows `up`.
33 ///
34 /// # Errors
35 ///
36 /// Fails with `not_running` when no member machine runs, when a secret or tool is missing,
37 /// and as `up` does for a step, a ready condition or the run's state.
38 pub async fn update(&self, opts: &RunOptions, events: &dyn Events) -> Result<Started> {
39 self.operate(Op::Update, opts, events, async |connected: &RunOptions, e: &Emitter<'_>| {
40 self.update_work(connected, e).await
41 })
42 .await
43 }
44
45 async fn update_work(&self, opts: &RunOptions, events: &Emitter<'_>) -> Result<Done<Started>> {
46 let (mut record, mut cx) = self.existing(opts, events).await?;
47 // The run's own provider, as recorded, decides which slots it needs, not the one given.
48 check_secrets(self.manifest(), &opts.secrets, &cx.scope)?;
49 tools::probe(&cx).await?;
50 let observed = self.observe_running(&mut cx).await?;
51 // What runs now keeps what it was given: only a machine new to the run gets its secrets.
52 cx.set_up = observed.machines.iter().filter(|m| m.state.runs()).map(|m| m.name.clone()).collect();
53 self.reload_changed(&cx, &record.vm_boot_digests, &observed).await?;
54 self.runs_from_this(&mut record);
55 self.begin(&mut record, Op::Update)?;
56 // The manifest may name new state files, or new entries in them (a new machine's inputs).
57 crate::executor::state_files::write(&cx, true)?;
58 self.driver.before_change(&cx).await?;
59 self.converge(&mut cx).await?;
60 self.driver.after_change(&cx).await?;
61 self.ready(&mut cx, record).await
62 }
63}