Compare commits

...

10 commits

Author SHA1 Message Date
Zhaofeng Li
cd65ef7a25
Merge pull request #199 from Janik-Haag/hive-module
make eval.nix more convnient to use for non-flake user
2024-03-25 11:05:53 -06:00
Janik H.
bb642e43f9
make eval.nix more convnient to use for non-flake user 2024-03-24 03:51:58 +01:00
Zhaofeng Li
7997ab7187
Merge pull request #197 from minhuw/main
Support adding extra ssh options on node configurations
2024-03-23 14:05:35 -06:00
minhuw
afa7439c58 Support adding extra ssh options on node configurations 2024-03-09 13:54:21 +08:00
Zhaofeng Li
c84ccd0a7a
Merge pull request #191 from pkel/main
Set exit code > 0 when colmena exec fails
2024-01-28 23:21:51 -07:00
Patrik Keller
bf690423ea Set error code > 0 when colmena exec fails 2024-01-15 15:02:20 +01:00
Zhaofeng Li
665603956a Fix lint 2023-11-05 01:05:28 -07:00
Zhaofeng Li
15a95d6de5 Fix shell completion generation
Generating shell completions shouldn't require any Hive config.
Now `colmena gen-completions` gets included in the completions which
will be fixed later.
2023-11-05 01:00:05 -07:00
Zhaofeng Li
3538f18b30
Merge pull request #169 from i1i1/clap-derive
Switch to clap derive
2023-10-24 12:51:57 +02:00
i1i1
95ded7fddb Add node filter to build and upload-keys 2023-10-23 14:31:30 -06:00
9 changed files with 58 additions and 18 deletions

View file

@ -278,6 +278,11 @@ pub async fn run() {
set_color_pref(&opts.color);
init_logging();
if let Command::GenCompletions { shell } = opts.command {
print_completions(shell, &mut Opts::command());
return;
}
let hive = get_hive(&opts).await.expect("Failed to get flake or hive");
use crate::troubleshooter::run_wrapped as r;
@ -296,7 +301,6 @@ pub async fn run() {
let args = command::apply::Opts {
deploy,
goal: crate::nix::Goal::Build,
node_filter: Default::default(),
};
r(command::apply::run(hive, args), opts.config).await
}
@ -304,21 +308,20 @@ pub async fn run() {
let args = command::apply::Opts {
deploy,
goal: crate::nix::Goal::UploadKeys,
node_filter: Default::default(),
};
r(command::apply::run(hive, args), opts.config).await
}
Command::GenCompletions { shell } => print_completions(shell, &mut Opts::command()),
Command::GenCompletions { .. } => unreachable!(),
}
}
fn print_completions(shell: Shell, cmd: &mut clap::Command) {
clap_complete::generate(
shell,
cmd,
cmd.get_name().to_string(),
&mut std::io::stdout(),
);
let bin_name = cmd
.get_bin_name()
.expect("Must have a bin_name")
.to_string();
clap_complete::generate(shell, cmd, bin_name, &mut std::io::stdout());
}
fn set_color_pref(when: &ColorWhen) {

View file

@ -113,6 +113,8 @@ will treat deployment.replaceUnknownProfiles as though it was set true and perfo
This is an experimental feature."#
)]
evaluator: EvaluatorType,
#[command(flatten)]
node_filter: NodeFilterOpts,
}
#[derive(Debug, Args)]
@ -136,8 +138,6 @@ Same as the targets for switch-to-configuration, with the following extra pseudo
pub goal: Goal,
#[command(flatten)]
pub deploy: DeployOpts,
#[command(flatten)]
pub node_filter: NodeFilterOpts,
}
pub async fn run(hive: Hive, opts: Opts) -> Result<(), ColmenaError> {
@ -159,8 +159,8 @@ pub async fn run(hive: Hive, opts: Opts) -> Result<(), ColmenaError> {
no_build_on_target,
force_replace_unknown_profiles,
evaluator,
node_filter,
},
node_filter,
} = opts;
if node_filter.on.is_none() && goal != Goal::Build {

View file

@ -110,9 +110,18 @@ pub async fn run(
}));
}
join_all(futures).await;
let results: Vec<Result<(), ColmenaError>> = join_all(futures).await;
Ok(())
let mut failed: usize = 0;
for x in results {
match x {
Err(_) => failed += 1,
Ok(_) => (),
}
}
Ok(failed)
});
let (meta, monitor, output) = tokio::join!(
@ -121,9 +130,13 @@ pub async fn run(
output.run_until_completion(),
);
meta?;
let failed = meta?;
monitor?;
output?;
Ok(())
if failed > 0 {
Err(ColmenaError::ExecError { n_hosts: failed })
} else {
Ok(())
}
}

View file

@ -75,6 +75,9 @@ pub enum ColmenaError {
#[snafu(display("Unknown error: {}", message))]
Unknown { message: String },
#[snafu(display("Exec failed on {} hosts", n_hosts))]
ExecError { n_hosts: usize },
}
impl From<std::io::Error> for ColmenaError {

View file

@ -1,8 +1,8 @@
{ rawHive ? null # Colmena Hive attrset
, rawFlake ? null # Nix Flake attrset with `outputs.colmena`
, hermetic ? rawFlake != null # Whether we are allowed to use <nixpkgs>
, colmenaOptions
, colmenaModules
, colmenaOptions ? import ./options.nix
, colmenaModules ? import ./modules.nix
}:
with builtins;
let

View file

@ -208,6 +208,13 @@ with builtins; rec {
type = types.listOf types.str;
default = [ "sudo" "-H" "--" ];
};
sshOptions = lib.mkOption {
description = mdDoc ''
Extra SSH options to pass to the SSH command.
'';
type = types.listOf types.str;
default = [];
};
};
};
};

View file

@ -33,6 +33,9 @@ pub struct Ssh {
/// Command to elevate privileges with.
privilege_escalation_command: Vec<String>,
/// extra SSH options
extra_ssh_options: Vec<String>,
/// Whether to use the experimental `nix copy` command.
use_nix3_copy: bool,
@ -189,6 +192,7 @@ impl Ssh {
port: None,
ssh_config: None,
privilege_escalation_command: Vec::new(),
extra_ssh_options: Vec::new(),
use_nix3_copy: false,
job: None,
}
@ -206,6 +210,10 @@ impl Ssh {
self.privilege_escalation_command = command;
}
pub fn set_extra_ssh_options(&mut self, options: Vec<String>) {
self.extra_ssh_options = options;
}
pub fn set_use_nix3_copy(&mut self, enable: bool) {
self.use_nix3_copy = enable;
}
@ -346,6 +354,7 @@ impl Ssh {
]
.iter()
.map(|s| s.to_string())
.chain(self.extra_ssh_options.clone())
.collect();
if let Some(port) = self.port {

View file

@ -78,6 +78,9 @@ pub struct NodeConfig {
#[serde(rename = "privilegeEscalationCommand")]
privilege_escalation_command: Vec<String>,
#[serde(rename = "sshOptions")]
extra_ssh_options: Vec<String>,
#[validate(custom = "validate_keys")]
keys: HashMap<String, Key>,
}
@ -181,6 +184,7 @@ impl NodeConfig {
self.target_host.as_ref().map(|target_host| {
let mut host = Ssh::new(self.target_user.clone(), target_host.clone());
host.set_privilege_escalation_command(self.privilege_escalation_command.clone());
host.set_extra_ssh_options(self.extra_ssh_options.clone());
if let Some(target_port) = self.target_port {
host.set_port(target_port);

View file

@ -248,6 +248,7 @@ mod tests {
build_on_target: false,
replace_unknown_profiles: false,
privilege_escalation_command: vec![],
extra_ssh_options: vec![],
keys: HashMap::new(),
};