Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced plain json with structs in Namespace and Deployment definition (BFT-430) #68

Merged
merged 106 commits into from
Feb 28, 2024
Merged
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
6bd6170
Add dockerfile for executable node
IAvecilla Jan 10, 2024
b2fb9ab
Add compose file for testing purposes
IAvecilla Jan 10, 2024
e768bc6
Add entrypoint for node consensus dockerfile
IAvecilla Jan 12, 2024
e6b6487
Add some comments and improve compose test file
IAvecilla Jan 12, 2024
4ca7fdc
Add new makefile commands to run dockerized consensus node
IAvecilla Jan 12, 2024
28df58b
Update readme with docs to run consensus node in docker
IAvecilla Jan 12, 2024
3e4b881
Delete unnecesary building dependency in compose file
IAvecilla Jan 15, 2024
febcafc
Rename docker image
IAvecilla Jan 15, 2024
b2e7e9c
Set container names manually in compose file
IAvecilla Jan 15, 2024
5e27e6e
Separate config directory for nodes running in docker
IAvecilla Jan 15, 2024
6e2236a
Fix node configuration for docker consensus example
IAvecilla Jan 15, 2024
810a4b5
Improve command to run a node in a container
IAvecilla Jan 15, 2024
4088c0a
Generate the node configs in release mode
IAvecilla Jan 15, 2024
4475489
Fix docker cleanup to force deletion
IAvecilla Jan 15, 2024
689b6d5
Remove unnecesary copies to container
IAvecilla Jan 15, 2024
99dc691
Add target dir to docker ignore
IAvecilla Jan 16, 2024
a3b270d
Move every docker related config file to the project root
IAvecilla Jan 16, 2024
f93890f
Fix typo in README
IAvecilla Jan 17, 2024
f3893cf
Fix typo in makefile command
IAvecilla Jan 17, 2024
1c721c8
Make the path to makefile be the same for local and docker
IAvecilla Jan 17, 2024
8cac863
disabled clipply lint
pompon0 Jan 17, 2024
d24c8bc
fixed lint, updated deps
pompon0 Jan 17, 2024
9520c4c
Change file name for the docker entrypoint and add comment to the script
IAvecilla Jan 18, 2024
54c72ce
Move version to latest for rust image
IAvecilla Jan 18, 2024
13e61e1
Change name of command and dir generation for node config
IAvecilla Jan 18, 2024
3b8d299
Add command to stop dockerized nodes
IAvecilla Jan 18, 2024
2d09c1d
Add example file with local address for node configuration
IAvecilla Jan 18, 2024
c287c56
Update README with new updates
IAvecilla Jan 18, 2024
e66cec9
Write a general overview on the README
IAvecilla Jan 18, 2024
eb7077e
Add tonic as dependency
IAvecilla Jan 19, 2024
058418e
Create test proto file with helathcheck endpoint
IAvecilla Jan 19, 2024
f323873
Add basic rpc server implementation
IAvecilla Jan 19, 2024
d0d9b13
Add basic rpc client implementation to use with CLI
IAvecilla Jan 19, 2024
a332327
Run RPC server for the standalone node
IAvecilla Jan 19, 2024
8e2d83c
Update docker config files to expose rpc server
IAvecilla Jan 19, 2024
96e18b7
Replace tonic crate for jsonrpsee
IAvecilla Jan 23, 2024
6b57f2a
Delete protobuff related files
IAvecilla Jan 23, 2024
c0aaa9b
Delete unnecesary RPC client
IAvecilla Jan 23, 2024
88a5b23
Add new jsonrpsee server and health endpoint
IAvecilla Jan 23, 2024
890bdee
Add inner docs for new rpc module
IAvecilla Jan 23, 2024
8f806bc
quick and dirty k8s deployment scripts for test framework
ElFantasma Jan 23, 2024
7592041
Merge branch 'main' into rpc_test_layer
IAvecilla Jan 23, 2024
23b8ea4
Merge branch 'rpc_test_layer' into k8s_deploy_script
IAvecilla Jan 23, 2024
438a2b8
Change name for generated config folders
IAvecilla Jan 24, 2024
19d7fcc
Update localnet config bin
IAvecilla Jan 24, 2024
b49af96
Delete old docker entrypoint file
IAvecilla Jan 24, 2024
2fd8061
Update k8s deployment manifest adding node env var
IAvecilla Jan 24, 2024
758ff9e
Add new stage in dockerfile to generate executor binary
IAvecilla Jan 25, 2024
addacc8
Build correct target in compose file
IAvecilla Jan 25, 2024
e263eb6
Update Makefile with all new targets
IAvecilla Jan 25, 2024
9503f05
Add addresses example file for docker config
IAvecilla Jan 25, 2024
8bcdb88
Remove docker config dir from clean command
IAvecilla Jan 25, 2024
2323211
Added some utility targets to Makefile
ElFantasma Jan 25, 2024
2720e74
Make rpc port a CLI argument for the executor
IAvecilla Jan 25, 2024
af1caaa
Change param type to run the server
IAvecilla Jan 25, 2024
77591f3
Merge branch 'rpc_test_layer' into k8s_deploy_script
IAvecilla Jan 25, 2024
24cddea
Add config generation for k8s node deployer
IAvecilla Jan 25, 2024
2cfaff4
Add makefile target to clean k8s config
IAvecilla Jan 25, 2024
4ed83cc
Improve config generation struct
IAvecilla Jan 26, 2024
00a008a
Use new config app functions to build localent and k8s config
IAvecilla Jan 26, 2024
4ce804b
Add kube as dependency for tools crate
IAvecilla Jan 26, 2024
b723715
Fix node config generation
IAvecilla Jan 29, 2024
83589a1
Add k8s-openapi as dependency
IAvecilla Jan 29, 2024
6248277
Add subcommands to generate config and deploy pods
IAvecilla Jan 29, 2024
87d9def
Override entrypoint to run node in k8s pod
IAvecilla Jan 29, 2024
251052f
Add makefile target to run k8s pods
IAvecilla Jan 29, 2024
09484fd
Merge branch 'main' into rpc_test_layer
IAvecilla Jan 30, 2024
ac145ee
Merge branch 'rpc_test_layer' into k8s_deploy_script
IAvecilla Jan 30, 2024
10ba6d6
Update nodes argument type to generate nodes config
IAvecilla Jan 30, 2024
991a8ac
Fix deployer config generation after merge
IAvecilla Jan 30, 2024
926b387
Fix clippy and format warnings
IAvecilla Jan 30, 2024
5fca6b8
Improve RPC server API to scale it easier
IAvecilla Jan 30, 2024
0726aff
Fix concurrency management for rpc server
IAvecilla Jan 30, 2024
21fb1c6
Add missing docs to solve clippy warnings
IAvecilla Jan 30, 2024
41ec845
Revert change for executor new flag
IAvecilla Jan 30, 2024
7ba8cb3
shutting down server when context is cancelled
pompon0 Jan 31, 2024
d859f39
Removed k8s yml files and modularized kube.rs access
ElFantasma Feb 1, 2024
95ec2b7
Update consensus docker example with new rpc ports
IAvecilla Feb 1, 2024
d697cc1
Add new endpoint to get peers of the node
IAvecilla Feb 1, 2024
7fe6ed9
Fix format and linter
IAvecilla Feb 1, 2024
57f600a
Update cargo.lock
IAvecilla Feb 1, 2024
8ffa0c0
Delete unnecesary features in added crates
IAvecilla Feb 1, 2024
44c979e
Added k8s module
ElFantasma Feb 1, 2024
5257592
Add old crate versions to deny.toml file
IAvecilla Feb 2, 2024
75cd2cf
Use new app config api for test in tools crate
IAvecilla Feb 2, 2024
958954f
Merge branch 'rpc_test_layer' into k8s_deploy_script
IAvecilla Feb 2, 2024
b0803dc
Deploying seed peers in a different phase
ElFantasma Feb 5, 2024
3a249dc
Retrieving seed peers IPs and using it in the rest of the peers
ElFantasma Feb 5, 2024
d612889
Busy waiting for pods to start to obtain their IPs
ElFantasma Feb 7, 2024
6bd5394
Revert change to have node ips as directory names for local config
IAvecilla Feb 8, 2024
1d58431
Making cli argument optional and forwarding arguments in entrypoint …
ElFantasma Feb 9, 2024
960ff13
Merge branch 'main' into k8s_deploy_script
ElFantasma Feb 9, 2024
c864f51
Fixed compiler warnings
ElFantasma Feb 9, 2024
b5b5ee6
Consensus node now can obtain it's public address from an ENV VAR. Al…
ElFantasma Feb 14, 2024
702a587
Added config RPC endpoint
ElFantasma Feb 15, 2024
1ef6877
Corrected k8s_entrypoint.sh script to forward cli arguments
ElFantasma Feb 15, 2024
5e8b011
Several corrections on naming and coding style
ElFantasma Feb 15, 2024
c62f0b4
Fixed deny.toml for kube.rs
ElFantasma Feb 16, 2024
2e89af8
Fixed clippy suggestions
ElFantasma Feb 19, 2024
fb0c345
Added amount of seed nodes as cli argument
ElFantasma Feb 19, 2024
3b1256f
Merge branch 'main' into k8s_deploy_script
ElFantasma Feb 19, 2024
23a7761
Added brief description for k8s deployment in README.md
ElFantasma Feb 20, 2024
7dbf270
Unified node_name and node_id values
ElFantasma Feb 20, 2024
336a28b
Replaced plain json with k8s_openapi structs in Namespace and Deploym…
ElFantasma Feb 21, 2024
8ec4af5
Fixed clippy suggestions
ElFantasma Feb 21, 2024
5cfde6b
Merge branch 'main' into replace_json_k8s
ElFantasma Feb 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 99 additions & 85 deletions node/tools/src/k8s.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
use crate::{config, NodeAddr};
use anyhow::{anyhow, Context};
use k8s_openapi::api::{
apps::v1::Deployment,
core::v1::{Namespace, Pod},
use k8s_openapi::{
api::{
apps::v1::{Deployment, DeploymentSpec},
core::v1::{
Container, ContainerPort, EnvVar, EnvVarSource, HTTPGetAction, Namespace,
ObjectFieldSelector, Pod, PodSpec, PodTemplateSpec, Probe,
},
},
apimachinery::pkg::{apis::meta::v1::LabelSelector, util::intstr::IntOrString::Int},
};
use kube::{
api::{ListParams, PostParams},
core::ObjectList,
core::{ObjectList, ObjectMeta},
Api, Client, ResourceExt,
};
use serde_json::json;
use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};
use tokio_retry::strategy::FixedInterval;
use tokio_retry::Retry;
use tracing::log::info;
Expand All @@ -26,16 +31,14 @@ pub async fn create_or_reuse_namespace(client: &Client, name: &str) -> anyhow::R
let namespaces: Api<Namespace> = Api::all(client.clone());
match namespaces.get_opt(name).await? {
None => {
let namespace: Namespace = serde_json::from_value(json!({
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"name": name,
"labels": {
"name": name
}
}
}))?;
let namespace = Namespace {
metadata: ObjectMeta {
name: Some(name.to_owned()),
labels: Some(BTreeMap::from([("name".to_owned(), name.to_owned())])),
..Default::default()
},
..Default::default()
};

let namespaces: Api<Namespace> = Api::all(client.clone());
let post_params = PostParams::default();
Expand Down Expand Up @@ -73,76 +76,87 @@ pub async fn deploy_node(
) -> anyhow::Result<()> {
let cli_args = get_cli_args(peers);
let node_name = format!("consensus-node-{node_index:0>2}");
let deployment: Deployment = serde_json::from_value(json!({
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": node_name,
"namespace": namespace
},
"spec": {
"selector": {
"matchLabels": {
"app": node_name
}
let deployment = Deployment {
metadata: ObjectMeta {
name: Some(node_name.to_owned()),
namespace: Some(namespace.to_owned()),
..Default::default()
},
spec: Some(DeploymentSpec {
selector: LabelSelector {
match_labels: Some(BTreeMap::from([("app".to_owned(), node_name.to_owned())])),
..Default::default()
},
"replicas": 1,
"template": {
"metadata": {
"labels": {
"app": node_name,
"id": node_name,
"seed": is_seed.to_string()
}
},
"spec": {
"containers": [
{
"name": node_name,
"image": "consensus-node",
"env": [
{
"name": "NODE_ID",
"value": node_name
},
{
"name": "PUBLIC_ADDR",
"valueFrom": {
"fieldRef": {
"fieldPath": "status.podIP"
}
}
}
],
"command": ["./k8s_entrypoint.sh"],
"args": cli_args,
"imagePullPolicy": "Never",
"ports": [
{
"containerPort": config::NODES_PORT
},
{
"containerPort": 3154
}
],
"livenessProbe": {
"httpGet": {
"path": "/health",
"port": 3154
}
},
"readinessProbe": {
"httpGet": {
"path": "/health",
"port": 3154
}
}
}
]
}
}
}
}))?;
replicas: Some(1),
template: PodTemplateSpec {
metadata: Some(ObjectMeta {
labels: Some(BTreeMap::from([
("app".to_owned(), node_name.to_owned()),
("id".to_owned(), node_name.to_owned()),
("seed".to_owned(), is_seed.to_string()),
])),
..Default::default()
}),
spec: Some(PodSpec {
containers: vec![Container {
name: node_name.to_owned(),
image: Some("consensus-node".to_owned()),
env: Some(vec![
EnvVar {
name: "NODE_ID".to_owned(),
value: Some(node_name.to_owned()),
..Default::default()
},
EnvVar {
name: "PUBLIC_ADDR".to_owned(),
value_from: Some(EnvVarSource {
field_ref: Some(ObjectFieldSelector {
field_path: "status.podIP".to_owned(),
..Default::default()
}),
..Default::default()
}),
..Default::default()
},
]),
command: Some(vec!["./k8s_entrypoint.sh".to_owned()]),
args: Some(cli_args),
image_pull_policy: Some("Never".to_owned()),
ports: Some(vec![
ContainerPort {
container_port: i32::from(config::NODES_PORT),
..Default::default()
},
ContainerPort {
container_port: 3154,
..Default::default()
},
]),
liveness_probe: Some(Probe {
http_get: Some(HTTPGetAction {
path: Some("/health".to_owned()),
port: Int(3154),
..Default::default()
}),
..Default::default()
}),
readiness_probe: Some(Probe {
http_get: Some(HTTPGetAction {
path: Some("/health".to_owned()),
port: Int(3154),
..Default::default()
}),
..Default::default()
}),
..Default::default()
}],
..Default::default()
}),
},
..Default::default()
}),
..Default::default()
};

let deployments: Api<Deployment> = Api::namespaced(client.clone(), namespace);
let post_params = PostParams::default();
Expand Down
Loading