-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sled-agent] Separate CockroachDB "start" from CockroachDB "init" (#2954
) Co-authored-by: David Pacheco <[email protected]>
- Loading branch information
1 parent
cdf91f2
commit b884c76
Showing
17 changed files
with
633 additions
and
133 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "internal-dns-cli" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license = "MPL-2.0" | ||
|
||
[dependencies] | ||
anyhow.workspace = true | ||
clap.workspace = true | ||
dropshot.workspace = true | ||
internal-dns.workspace = true | ||
omicron-common.workspace = true | ||
slog.workspace = true | ||
tokio.workspace = true | ||
trust-dns-resolver.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Resolves DNS names within the Oxide control plane | ||
use anyhow::Context; | ||
use anyhow::Result; | ||
use clap::Parser; | ||
use clap::ValueEnum; | ||
use internal_dns::resolver::ResolveError; | ||
use internal_dns::resolver::Resolver; | ||
use slog::{info, warn}; | ||
use std::net::SocketAddr; | ||
|
||
#[derive(Debug, Parser)] | ||
#[clap(name = "dnswait", about = "Resolves DNS names in the control plane")] | ||
struct Opt { | ||
/// Nameserver(s) to query | ||
/// | ||
/// If unspecified, uses the system configuration (usually the nameservers | ||
/// configured in /etc/resolv.conf). | ||
#[clap(long, action)] | ||
nameserver_addresses: Vec<SocketAddr>, | ||
|
||
/// service name to be resolved (should be the target of a DNS name) | ||
#[arg(value_enum)] | ||
srv_name: ServiceName, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, ValueEnum)] | ||
#[value(rename_all = "kebab-case")] | ||
enum ServiceName { | ||
Cockroach, | ||
} | ||
|
||
impl From<ServiceName> for internal_dns::ServiceName { | ||
fn from(value: ServiceName) -> Self { | ||
match value { | ||
ServiceName::Cockroach => internal_dns::ServiceName::Cockroach, | ||
} | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let opt = Opt::parse(); | ||
let log = dropshot::ConfigLogging::File { | ||
path: "/dev/stderr".into(), | ||
level: dropshot::ConfigLoggingLevel::Info, | ||
if_exists: dropshot::ConfigLoggingIfExists::Append, | ||
} | ||
.to_logger("dnswait") | ||
.context("creating log")?; | ||
|
||
let resolver = if opt.nameserver_addresses.is_empty() { | ||
info!(&log, "using system configuration"); | ||
let async_resolver = | ||
trust_dns_resolver::AsyncResolver::tokio_from_system_conf() | ||
.context("initializing resolver from system configuration")?; | ||
Resolver::new_with_resolver(log.clone(), async_resolver) | ||
} else { | ||
let addrs = opt.nameserver_addresses; | ||
info!(&log, "using explicit nameservers"; "nameservers" => ?addrs); | ||
Resolver::new_from_addrs(log.clone(), addrs) | ||
.context("creating resolver with explicit nameserver addresses")? | ||
}; | ||
|
||
let result = omicron_common::backoff::retry_notify( | ||
omicron_common::backoff::retry_policy_internal_service(), | ||
|| async { | ||
let dns_name = internal_dns::ServiceName::from(opt.srv_name); | ||
resolver.lookup_srv(dns_name).await.map_err(|error| match error { | ||
ResolveError::Resolve(_) | ||
| ResolveError::NotFound(_) | ||
| ResolveError::NotFoundByString(_) => { | ||
omicron_common::backoff::BackoffError::transient(error) | ||
} | ||
}) | ||
}, | ||
|error, delay| { | ||
warn!( | ||
&log, | ||
"DNS query failed; will try again"; | ||
"error" => format!("{:#}", error), | ||
"delay" => ?delay, | ||
); | ||
}, | ||
) | ||
.await | ||
.context("unexpectedly gave up")?; | ||
|
||
for ip in result { | ||
println!("{}", ip) | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.