deployment: Move post-activation key upload after reboot

Ref: #113
This commit is contained in:
Zhaofeng Li 2022-09-01 18:42:37 -06:00
parent 3af3751d8e
commit f01f6ac197
2 changed files with 34 additions and 33 deletions

View file

@ -13,6 +13,7 @@
- The [`meta.nodeSpecialArgs`](./reference/meta.md#nodespecialargs) option has been added. It allows specifying node-specific `specialArgs` passed to NixOS modules ([#100](https://github.com/zhaofengli/colmena/pull/100)).
- The [`repl`](./reference/cli.html#colmena-repl) subcommand has been added. It allows you to start an [interactive REPL](./features/eval.md#interactive-repl) with access to the complete node configurations.
- The default goal for `colmena apply` is now `boot` if `--reboot` is specified, and `switch` otherwise ([#113](https://github.com/zhaofengli/colmena/issues/113)).
- Post-activation keys are now uploaded after the reboot if `--reboot` is specified ([#113](https://github.com/zhaofengli/colmena/issues/113)).
## [Release 0.3.1](https://github.com/zhaofengli/colmena/releases/tag/v0.3.1) (2022/08/18)

View file

@ -632,40 +632,8 @@ impl Deployment {
Ok(target)
}).await?;
// Upload post-activation keys
let mut target = if self.options.upload_keys {
let job = parent.create_job(JobType::UploadKeys, nodes.clone())?;
job.run_waiting(|job| async move {
let keys = target
.config
.keys
.iter()
.filter(|(_, v)| v.upload_at() == UploadKeyAt::PostActivation)
.map(|(k, v)| (k.clone(), v.clone()))
.collect::<HashMap<String, Key>>();
if keys.is_empty() {
job.noop("No post-activation keys to upload".to_string())?;
return Ok(target);
}
job.state(JobState::Running)?;
job.message("Uploading post-activation keys...".to_string())?;
let host = target.host.as_mut().unwrap();
host.set_job(Some(job.clone()));
host.upload_keys(&keys, true).await?;
job.success_with_message("Uploaded keys (post-activation)".to_string())?;
Ok(target)
})
.await?
} else {
target
};
// Reboot
if self.options.reboot {
let mut target = if self.options.reboot {
let job = parent.create_job(JobType::Reboot, nodes.clone())?;
let arc_self = self.clone();
job.run(|job| async move {
@ -684,6 +652,38 @@ impl Deployment {
host.reboot(options).await?;
Ok(target)
})
.await?
} else {
target
};
// Upload post-activation keys
if self.options.upload_keys {
let job = parent.create_job(JobType::UploadKeys, nodes.clone())?;
job.run_waiting(|job| async move {
let keys = target
.config
.keys
.iter()
.filter(|(_, v)| v.upload_at() == UploadKeyAt::PostActivation)
.map(|(k, v)| (k.clone(), v.clone()))
.collect::<HashMap<String, Key>>();
if keys.is_empty() {
job.noop("No post-activation keys to upload".to_string())?;
return Ok(());
}
job.state(JobState::Running)?;
job.message("Uploading post-activation keys...".to_string())?;
let host = target.host.as_mut().unwrap();
host.set_job(Some(job.clone()));
host.upload_keys(&keys, true).await?;
job.success_with_message("Uploaded keys (post-activation)".to_string())?;
Ok(())
})
.await?;