Skip to content

Commit

Permalink
ntp: Add setting to configure options
Browse files Browse the repository at this point in the history
  • Loading branch information
domgoodwin committed Apr 4, 2024
1 parent c5c4767 commit cfcc095
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 2 deletions.
1 change: 1 addition & 0 deletions Release.toml
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,5 @@ version = "1.20.0"
"migrate_v1.20.0_corndog-services-cfg-v0-1-0.lz4",
"migrate_v1.20.0_bootstrap-containers-config-file-v0-1-0.lz4",
"migrate_v1.20.0_bootstrap-containers-services-cfg-v0-1-0.lz4",
"migrate_v1.20.0_add-ntp-default-options-v0-1-0.lz4",
]
2 changes: 1 addition & 1 deletion packages/chrony/chrony-conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ntp = "v1"
+++
{{#each settings.ntp.time-servers}}
pool {{this}} iburst
pool {{this}}{{#each ../settings.ntp.options}} {{this}}{{/each}}
{{/each}}
driftfile /var/lib/chrony/drift
makestep 1.0 3
Expand Down
7 changes: 7 additions & 0 deletions sources/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sources/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ members = [
"api/migration/migrations/v1.20.0/corndog-services-cfg-v0-1-0",
"api/migration/migrations/v1.20.0/bootstrap-containers-config-file-v0-1-0",
"api/migration/migrations/v1.20.0/bootstrap-containers-services-cfg-v0-1-0",
"api/migration/migrations/v1.20.0/add-ntp-default-options-v0-1-0",

"bloodhound",

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "add-ntp-default-options-v0-1-0"
version = "0.1.0"
authors = ["Dom Goodwin <[email protected]>"]
license = "Apache-2.0 OR MIT"
edition = "2021"
publish = false

[dependencies]
migration-helpers = { path = "../../../migration-helpers", version = "0.1.0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use migration_helpers::common_migrations::AddSettingsMigration;
use migration_helpers::{migrate, Result};
use std::process;

/// We added the ability to set additional options for NTP
fn run() -> Result<()> {
migrate(AddSettingsMigration(&["settings.ntp.options"]))
}

// Returning a Result from main makes it print a Debug representation of the error, but with Snafu
// we have nice Display representations of the error, so we wrap "main" (run) and print any error.
// https://github.com/shepmaster/snafu/issues/110
fn main() {
if let Err(e) = run() {
eprintln!("{}", e);
process::exit(1);
}
}
4 changes: 4 additions & 0 deletions sources/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ components:
type: array
items:
type: string
options:
type: array
items:
type: string
network:
type: object
properties:
Expand Down
1 change: 1 addition & 0 deletions sources/models/shared-defaults/defaults.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ template-path = "/usr/share/templates/hosts"

[settings.ntp]
time-servers = ["169.254.169.123", "2.amazon.pool.ntp.org"]
options = ["iburst"]

[services.ntp]
configuration-files = ["chrony-conf"]
Expand Down
18 changes: 17 additions & 1 deletion sources/settings-extensions/ntp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::convert::Infallible;
#[model(impl_default = true)]
pub struct NtpSettingsV1 {
time_servers: Vec<Url>,
options: Vec<String>,
}

type Result<T> = std::result::Result<T, Infallible>;
Expand Down Expand Up @@ -64,7 +65,8 @@ mod test {
assert_eq!(
NtpSettingsV1::generate(None, None),
Ok(GenerateResult::Complete(NtpSettingsV1 {
time_servers: None
time_servers: None,
options: None,
}))
)
}
Expand All @@ -85,4 +87,18 @@ mod test {
let results = serde_json::to_string(&ntp).unwrap();
assert_eq!(results, test_json);
}

#[test]
fn test_options_ntp() {
let test_json = r#"{"time-servers":["https://example.net","http://www.example.com"],"options":["minpoll","1","maxpoll","2"]}"#;

let ntp: NtpSettingsV1 = serde_json::from_str(test_json).unwrap();
assert_eq!(
ntp.options.clone().unwrap(),
vec!("minpoll", "1", "maxpoll", "2",)
);

let results = serde_json::to_string(&ntp).unwrap();
assert_eq!(results, test_json);
}
}

0 comments on commit cfcc095

Please sign in to comment.