Skip to content

Commit

Permalink
chore(riklet): deprecate config ifnet and ifnet_ip parameters
Browse files Browse the repository at this point in the history
* Remove usage of ifnet parameter
* Remove usage of ifnet_ip parameter
* Mark fields as deprecated in the CLI

Signed-off-by: AlexandreBrg <[email protected]>
  • Loading branch information
alexandrebrg committed Apr 26, 2023
1 parent 67c677a commit f1b5cdb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
6 changes: 1 addition & 5 deletions riklet/src/cli/function_config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{net::Ipv4Addr, path::PathBuf};
use std::path::PathBuf;

use super::CliConfiguration;
use clap::Parser;
Expand All @@ -7,17 +7,13 @@ use clap::Parser;
pub struct FnConfiguration {
pub firecracker_location: PathBuf,
pub kernel_location: PathBuf,
pub ifnet: String,
pub ifnet_ip: Ipv4Addr,
}

impl From<CliConfiguration> for FnConfiguration {
fn from(cli: CliConfiguration) -> Self {
FnConfiguration {
firecracker_location: cli.firecracker_path,
kernel_location: cli.kernel_path,
ifnet: cli.ifnet,
ifnet_ip: cli.ifnet_ip,
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions riklet/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct CliConfiguration {
/// If set and there is a config file, values defined by the CLI will override values of the configuration file.
#[arg(long)]
pub override_config: bool,
/// Path to the firecarcker binary.
/// Path to a firecracker binary on your system
#[arg(
long,
value_name = "FIRECRACKER_LOCATION",
Expand All @@ -36,15 +36,19 @@ pub struct CliConfiguration {
default_value = "vmlinux.bin"
)]
pub kernel_path: PathBuf,
/// Network interface connected to internet.
/// DEPRECATED: Network interface that is used to connect to internet
///
/// It was previously used to configure iptables, it is not the case anymore
#[arg(long, value_name = "IFNET", env = "IFNET", default_value = "eth0")]
pub ifnet: String,
/// IP of the network interface
pub ifnet: Option<String>,
/// DEPRECATED: IP of the network interface
///
/// It was previously used to configure iptables, it is not the case anymore.
#[arg(
long,
value_name = "IFNET_IP",
env = "IFNET_IP",
value_parser = value_parser!(Ipv4Addr)
)]
pub ifnet_ip: Ipv4Addr,
pub ifnet_ip: Option<Ipv4Addr>,
}
8 changes: 8 additions & 0 deletions riklet/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ pub struct Riklet {
// Can be pod or function runtimes
// The key is the instance id
runtimes: HashMap<String, Box<dyn Runtime>>,
/// Holds the global network configuration which includes basic iptables
/// rules and chains used by all workloads
///
/// WARN: Even though it is not read by the system and it raises a warning,
/// it is necessary to keep ownership of this field so that the [Drop] trait
/// is not called too early, but only when [Riklet] is dropped
network: GlobalRuntimeNetwork,
}

impl Riklet {
Expand Down Expand Up @@ -207,6 +214,7 @@ impl Riklet {
stream,
runtimes: HashMap::<String, Box<dyn Runtime>>::new(),
config,
network: global_runtime_network,
})
}
}
13 changes: 1 addition & 12 deletions riklet/src/runtime/network/function_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use tracing::debug;
use crate::constants::DEFAULT_FIRECRACKER_NETWORK_MASK;
use crate::net_utils::{self, get_iptables_riklet_chain};
use crate::{
cli::function_config::FnConfiguration,
iptables::{rule::Rule, Iptables, MutateIptables, Table},
structs::WorkloadDefinition,
};
Expand All @@ -23,7 +22,6 @@ pub struct FunctionRuntimeNetwork {
pub guest_ip: Ipv4Addr,
/// Host tap interface IP
pub host_ip: Ipv4Addr,
pub function_config: FnConfiguration,
/// A mapping of exposed port to internal port
pub port_mapping: Vec<(u16, u16)>,
/// A unique name for the tap interface
Expand Down Expand Up @@ -66,7 +64,6 @@ impl FunctionRuntimeNetwork {
Ok(FunctionRuntimeNetwork {
mask_long: mask_long.to_string(),
host_ip,
function_config: FnConfiguration::load(),
guest_ip,
identifier: workload.instance_id.clone(),
port_mapping: workload_definition.get_port_mapping(),
Expand Down Expand Up @@ -169,13 +166,12 @@ impl RuntimeNetwork for FunctionRuntimeNetwork {

#[cfg(test)]
mod tests {
use std::{net::Ipv4Addr, path::PathBuf, process::Command};
use std::{net::Ipv4Addr, process::Command};

use serial_test::serial;
use tracing::trace;

use crate::{
cli::function_config::FnConfiguration,
iptables::{rule::Rule, Iptables, MutateIptables, Table},
net_utils::get_iptables_riklet_chain,
runtime::network::{GlobalRuntimeNetwork, RuntimeNetwork},
Expand Down Expand Up @@ -223,18 +219,11 @@ mod tests {
tap_name: &str,
port_mapping: &Vec<(u16, u16)>,
) -> FunctionRuntimeNetwork {
let fn_config = FnConfiguration {
ifnet: tap_name.to_string(),
ifnet_ip: Ipv4Addr::new(10, 0, 0, 1),
firecracker_location: PathBuf::new(),
kernel_location: PathBuf::new(),
};
FunctionRuntimeNetwork {
identifier: "test".to_string(),
mask_long: "255.255.255.200".to_string(),
host_ip: Ipv4Addr::new(10, 0, 0, 2),
guest_ip: Ipv4Addr::new(10, 0, 0, 1),
function_config: fn_config,
port_mapping: port_mapping.clone(),
tap: Some(tap_name.to_string()),
iptables: Iptables::new(true).unwrap(),
Expand Down

0 comments on commit f1b5cdb

Please sign in to comment.