Skip to content

Commit

Permalink
chore(operators): purge rust operator from repo
Browse files Browse the repository at this point in the history
Remove the rust node operator from the tree as it will be rewritten in
 go and might not even live in this repo.
  • Loading branch information
tiagolobocastro committed Feb 22, 2021
1 parent ff97594 commit 48f846f
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 950 deletions.
485 changes: 9 additions & 476 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ members = [
"control-plane/mbus-api",
"composer",
"control-plane/rest",
"control-plane/operators",
"control-plane/macros",
"control-plane/deployer",
"control-plane/tests"
Expand Down
118 changes: 2 additions & 116 deletions control-plane/deployer/src/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,110 +115,6 @@ macro_rules! impl_ctrlp_agents {
};
}

#[macro_export]
macro_rules! impl_ctrlp_operators {
($($name:ident,)+) => {
/// List of Control Plane Operators to deploy
#[derive(Debug, Clone)]
pub struct ControlPlaneOperators(Vec<ControlPlaneOperator>);

/// All the Control Plane Operators
#[derive(Debug, Clone, StructOpt, ToString, EnumVariantNames)]
#[structopt(about = "Control Plane Operators")]
pub enum ControlPlaneOperator {
Empty(Empty),
$(
$name(paste!{[<$name Op>]}),
)+
}

paste! {
impl From<&ControlPlaneOperator> for Component {
fn from(ctrlp_svc: &ControlPlaneOperator) -> Self {
match ctrlp_svc {
ControlPlaneOperator::Empty(obj) => Component::Empty(obj.clone()),
$(ControlPlaneOperator::$name(obj) => Component::[<$name Op>](obj.clone()),)+
}
}
}
}

paste! {
impl FromStr for ControlPlaneOperator {
type Err = String;

fn from_str(source: &str) -> Result<Self, Self::Err> {
Ok(match source.trim().to_ascii_lowercase().as_str() {
"" => Self::Empty(Default::default()),
$(stringify!([<$name:lower>]) => Self::$name(<paste!{[<$name Op>]}>::default()),)+
_ => return Err(format!(
"\"{}\" is an invalid type of operator! Available types: {:?}",
source,
Self::VARIANTS
)),
})
}
}
}

$(#[async_trait]
impl ComponentAction for paste!{[<$name Op>]} {
fn configure(&self, options: &StartOptions, cfg: Builder) -> Result<Builder, Error> {
let name = format!("{}-op", stringify!($name).to_ascii_lowercase());
if options.build {
let status = std::process::Command::new("cargo")
.args(&["build", "-p", "operators", "--bin", &name])
.status()?;
build_error(&format!("the {} operator", name), status.code())?;
}
let rest = format!("http://rest.{}:8081", cfg.get_name());
let host_kube_config = match &options.kube_config {
Some(config) => config.clone(),
None => {
match std::env::var("USER") {
Ok(user) => format!("/home/{}/.kube/config", user),
Err(_) => "/root/.kube/config".to_string(),
}
}
};
let kube_config = match options.base_image {
Some(_) => "/root/.kube/config",
None => "/.kube/config",
};
Ok(if options.jaeger {
let jaeger_config = format!("jaeger.{}:6831", cfg.get_name());
cfg.add_container_spec(
ContainerSpec::from_binary(
&name,
Binary::from_dbg(&name)
.with_args(vec!["-r", &rest])
.with_args(vec!["-j", &jaeger_config]),
)
.with_bind(&host_kube_config, kube_config),
)
} else {
cfg.add_container_spec(
ContainerSpec::from_binary(
&name,
Binary::from_dbg(&name).with_args(vec!["-r", &rest])
)
.with_bind(&host_kube_config, kube_config),
)
})
}
async fn start(&self, _options: &StartOptions, cfg: &ComposeTest) -> Result<(), Error> {
// todo: wait for the rest server to be up
let name = format!("{}-op", stringify!($name).to_ascii_lowercase());
cfg.start(&name).await?;
Ok(())
}
})+
};
($($name:ident), +) => {
impl_ctrlp_operators!($($name,)+);
};
}

pub fn build_error(name: &str, status: Option<i32>) -> Result<(), Error> {
let make_error = |extra: &str| {
let error = format!("Failed to build {}: {}", name, extra);
Expand Down Expand Up @@ -321,22 +217,16 @@ macro_rules! impl_component {

impl Components {
pub fn push_generic_components(&mut self, name: &str, component: Component) {
if !ControlPlaneAgent::VARIANTS.iter().any(|&s| s == name) &&
!ControlPlaneOperator::VARIANTS.iter().any(|&s| &format!("{}Op", s) == name) {
if !ControlPlaneAgent::VARIANTS.iter().any(|&s| s == name) {
self.0.push(component);
}
}
pub fn new(options: StartOptions) -> Components {
let agents = options.agents.clone();
let operators = options.operators.clone().unwrap_or_default();
let mut components = agents
let components = agents
.iter()
.map(Component::from)
.collect::<Vec<Component>>();
components.extend(operators
.iter()
.map(Component::from)
.collect::<Vec<Component>>());

let mut components = Components(components, options.clone());
$(components.push_generic_components(stringify!($name), $name::default().into());)+
Expand Down Expand Up @@ -442,11 +332,7 @@ impl_component! {
Volume, 4,
JsonGrpc, 4,
Mayastor, 5,
NodeOp, 6,
}

// Message Bus Control Plane Agents
impl_ctrlp_agents!(Node, Pool, Volume, JsonGrpc);

// Kubernetes Mayastor Low-level Operators
impl_ctrlp_operators!(Node);
9 changes: 2 additions & 7 deletions control-plane/deployer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ pub struct StartOptions {
)]
pub agents: Vec<ControlPlaneAgent>,

/// Use the following Control Plane Operators
/// Specify one operator at a time or as a list
#[structopt(short, long, value_delimiter = ",")]
pub operators: Option<Vec<ControlPlaneOperator>>,

/// Kubernetes Config file if using operators
/// [default: "~/.kube/config"]
#[structopt(short, long)]
Expand Down Expand Up @@ -127,8 +122,8 @@ impl StartOptions {
self.build = build;
self
}
pub fn with_mayastors(mut self, mayastors: i32) -> Self {
self.mayastors = mayastors as u32;
pub fn with_mayastors(mut self, mayastors: u32) -> Self {
self.mayastors = mayastors;
self
}
pub fn with_show_info(mut self, show_info: bool) -> Self {
Expand Down
37 changes: 0 additions & 37 deletions control-plane/operators/Cargo.toml

This file was deleted.

Loading

0 comments on commit 48f846f

Please sign in to comment.