-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update: add support for netavark update command
Netavark update allows container managers to update network scoped DNS servers of any configured network and notify running `aarvark-dns` about it. ```console netavark-update Updates network dns servers for an already configured network USAGE: netavark update --network-dns-servers <NETWORK_DNS_SERVERS> <NETWORK_NAME> ARGS: <NETWORK_NAME> Network name to update OPTIONS: -h, --help Print help information -n, --network-dns-servers <NETWORK_DNS_SERVERS> DNS Servers to update for the network ``` Signed-off-by: Aditya R <[email protected]>
- Loading branch information
Showing
5 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod setup; | ||
pub mod teardown; | ||
pub mod update; | ||
pub mod version; |
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,80 @@ | ||
use crate::dns::aardvark::Aardvark; | ||
use crate::error::{NetavarkError, NetavarkErrorList, NetavarkResult}; | ||
|
||
use clap::Parser; | ||
use log::debug; | ||
use std::env; | ||
use std::path::Path; | ||
|
||
#[derive(Parser, Debug)] | ||
pub struct Update { | ||
/// Network name to update | ||
#[clap(forbid_empty_values = true, required = true)] | ||
network_name: String, | ||
/// DNS Servers to update for the network | ||
#[clap(short, long, required = true, forbid_empty_values = true)] | ||
network_dns_servers: Vec<String>, | ||
} | ||
|
||
impl Update { | ||
/// Updates network dns servers for an already configured network | ||
pub fn new(network_name: String, network_dns_servers: Vec<String>) -> Self { | ||
Self { | ||
network_name, | ||
network_dns_servers, | ||
} | ||
} | ||
|
||
pub fn exec( | ||
&self, | ||
config_dir: String, | ||
aardvark_bin: String, | ||
rootless: bool, | ||
) -> NetavarkResult<()> { | ||
let mut error_list = NetavarkErrorList::new(); | ||
let dns_port = match env::var("NETAVARK_DNS_PORT") { | ||
Ok(port_string) => match port_string.parse() { | ||
Ok(port) => port, | ||
Err(e) => { | ||
return Err(NetavarkError::Message(format!( | ||
"Invalid NETAVARK_DNS_PORT {}: {}", | ||
port_string, e | ||
))) | ||
} | ||
}, | ||
Err(_) => 53, | ||
}; | ||
|
||
println!( | ||
"config {:?}, aardvarl_bind {:?}, rootless {:?}", | ||
config_dir, aardvark_bin, rootless | ||
); | ||
println!( | ||
"network_name {:?}, network dns server {:?}", | ||
&self.network_name, &self.network_dns_servers | ||
); | ||
if Path::new(&aardvark_bin).exists() { | ||
let path = Path::new(&config_dir).join("aardvark-dns"); | ||
if let Ok(path_string) = path.into_os_string().into_string() { | ||
let mut aardvark_interface = | ||
Aardvark::new(path_string, rootless, aardvark_bin, dns_port); | ||
if let Err(err) = aardvark_interface | ||
.modify_network_dns_servers(&self.network_name, &self.network_dns_servers) | ||
{ | ||
error_list.push(err.into()); | ||
} | ||
} else { | ||
error_list.push(NetavarkError::msg( | ||
"Unable to parse aardvark config directory", | ||
)); | ||
} | ||
} | ||
|
||
if !error_list.is_empty() { | ||
return Err(NetavarkError::List(error_list)); | ||
} | ||
|
||
debug!("{:?}", "Update complete"); | ||
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
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