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

Sanity Test for nodes running in k8s (BFT-394) #63

Merged
merged 151 commits into from
Mar 7, 2024

Conversation

IAvecilla
Copy link
Contributor

@IAvecilla IAvecilla commented Feb 6, 2024

What ❔

Add a first sanity test to check node liveness running with the new Kubernetes script.

Why ❔

We need this basic test to see how to address the test suite development and have a layer used to communicate a local environment (like CI) with the nodes running in kubernetes.

IAvecilla and others added 30 commits January 10, 2024 18:34
Co-authored-by: Bruno França <[email protected]>
// This way we can run the test from every directory and also inside kubernetes pod.
let manifest_path = std::env::var("CARGO_MANIFEST_DIR");
if let Ok(manifest) = manifest_path {
format!("{}/config.txt", manifest)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Path::new(manifest_path.unwrap_or("")).join("config.txt")

.open(&config_file_path)?;
for addr in pods_ip {
config_file
.write_all(format!("{}\n", addr.to_string()).as_bytes())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write!(config_file,"{addr}\n").context("...")?;

for ip in node_ips.lines() {
let url: String = format!("http://{}:3154", ip);
let nodes_socket = fs::read_to_string(config_file_path).unwrap();
for socket in nodes_socket.lines() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first parse the ips, rather than blindly turning them into urls

let pod_running_container = pod_spec
.containers
.first()
.context("Failed to get pod container")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context().ok() doesn't make sense, because ok() is dropping the error altogether. In this case, it actually made more sense to first filter() and then map(), where map might return an error (now we just silently drop all the errors here).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, you're correct that returning a Result from this function is no longer useful when using filter_map. I made the change using filter followed by map, but the errors that arise in the filter closure are still being ignored because it requires a boolean and using ? to return a Result is not possible. Let me know if this is acceptable. In the map closure, the errors should now be handled correctly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you need to return an error from filter, then just use a regular loop over the elements instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up including everything in the for loop instead of having the for loop only for filtering and then mapping. I chose this solution mainly because:

  • I can reuse some pod variables instead of retrieving them twice, once for filtering and then again for mapping and address parsing.
  • This way, I only iterate over all the pods once. With the separate map approach, I had to create an empty vector, push all the filtered pods into it, and then convert it to an iterator for the address parsing part.

Let me know what you think.

ensure!(
!pod_addresses.is_empty(),
"No consensus pods found in the k8s cluster"
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: that should be rather checked by the caller, who will inspect the result

Base automatically changed from k8s_deploy_script to main February 27, 2024 13:19
@IAvecilla IAvecilla requested a review from pompon0 March 1, 2024 20:25
let mut node_rpc_addresses: Vec<SocketAddr> = Vec::new();
for pod in pods.into_iter() {
let pod_container = pod
.clone()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec.as_ref().context()

.context("Failed to get pod spec")?
.containers
.first()
.cloned()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first().as_ref().context()

@IAvecilla IAvecilla merged commit 2bc31fc into main Mar 7, 2024
4 checks passed
@IAvecilla IAvecilla deleted the k8s_node_communication_test branch March 7, 2024 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants