Skip to content

Commit

Permalink
Fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
IAvecilla committed Feb 8, 2024
1 parent cf48dff commit 7b5d264
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 51 deletions.
7 changes: 6 additions & 1 deletion node/tools/src/bin/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ async fn deploy(nodes: usize) -> anyhow::Result<()> {
NAMESPACE,
)
.await?;
k8s::create_or_reuse_service(&client, &format!("consensus-node-{i:0>2}"), &format!("consensus-node-{i:0>2}")).await?;
k8s::create_or_reuse_service(
&client,
&format!("consensus-node-{i:0>2}"),
&format!("consensus-node-{i:0>2}"),
)
.await?;
}

// // Waiting 15 secs to allow the pods to start
Expand Down
84 changes: 42 additions & 42 deletions node/tools/src/k8s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ use serde_json::json;
use std::collections::HashMap;
use tracing::log::info;
use zksync_protobuf::serde::Serde;
use kube::{
api::{DeleteParams},
runtime::wait::{await_condition, conditions::is_pod_running},
};

/// Get a kube client
pub async fn get_client() -> anyhow::Result<Client> {
Expand Down Expand Up @@ -53,48 +49,52 @@ pub async fn create_or_reuse_namespace(client: &Client, name: &str) -> anyhow::R
}

/// Creates a namespace in k8s cluster
pub async fn create_or_reuse_service(client: &Client, name: &str, node_name: &str) -> anyhow::Result<()> {
let services: Api<Service> = Api::namespaced(client.clone(), "consensus");
let example_service = services.get_opt(name).await?;
if example_service.is_none() {
let service: Service = serde_json::from_value(json!({
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": name,
"namespace": "consensus",
"labels": {
"app": node_name
}
},
"spec": {
"type": "NodePort",
"ports": [
{
"port": 80,
"targetPort": 3154,
"protocol": "TCP",
pub async fn create_or_reuse_service(
client: &Client,
name: &str,
node_name: &str,
) -> anyhow::Result<()> {
let services: Api<Service> = Api::namespaced(client.clone(), "consensus");
let example_service = services.get_opt(name).await?;
if example_service.is_none() {
let service: Service = serde_json::from_value(json!({
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": name,
"namespace": "consensus",
"labels": {
"app": node_name
}
],
"selector": {
"app": node_name
},
}
}))?;
"spec": {
"type": "NodePort",
"ports": [
{
"port": 80,
"targetPort": 3154,
"protocol": "TCP",
}
],
"selector": {
"app": node_name
},
}
}))?;

let services: Api<Service> = Api::namespaced(client.clone(), "consensus");
let post_params = PostParams::default();
let result = services.create(&post_params, &service).await?;
let services: Api<Service> = Api::namespaced(client.clone(), "consensus");
let post_params = PostParams::default();
let result = services.create(&post_params, &service).await?;

info!("Service: {} ,created", result.metadata.name.unwrap());
Ok(())
} else {
info!(
"Service: {} ,already exists",
example_service.unwrap().metadata.name.unwrap()
);
Ok(())
}
info!("Service: {} ,created", result.metadata.name.unwrap());
Ok(())
} else {
info!(
"Service: {} ,already exists",
example_service.unwrap().metadata.name.unwrap()
);
Ok(())
}
}

pub async fn create_deployment(
Expand Down
13 changes: 5 additions & 8 deletions node/tools/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,12 @@ async fn main() -> anyhow::Result<()> {
.context("config_paths().load()")?;

// Add gossipStaticOutbound pairs from cli to config
if let Some(go) = args.add_gossip_static_outbound {
configs.app.gossip_static_outbound.extend(
go
.0
.into_iter()
.map(|e| (e.0.key, e.0.addr)),
);
if let Some(outbound) = args.add_gossip_static_outbound {
configs
.app
.gossip_static_outbound
.extend(outbound.0.into_iter().map(|e| (e.0.key, e.0.addr)));
}


let (executor, runner) = configs
.make_executor(ctx)
Expand Down

0 comments on commit 7b5d264

Please sign in to comment.