Skip to content

Commit

Permalink
fix(clusters): gracefully handle node not found (#1099)
Browse files Browse the repository at this point in the history
<!-- Please make sure there is an issue that this PR is correlated to. -->

## Changes

<!-- If there are frontend changes, please include screenshots. -->
  • Loading branch information
MasterPtato committed Aug 29, 2024
1 parent a5d98e3 commit b460374
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
4 changes: 3 additions & 1 deletion lib/bolt/cli/src/commands/cluster/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,9 @@ mod render {
pub public_ip: Option<String>,
}

pub fn servers(servers: Vec<models::AdminClustersServer>) {
pub fn servers(mut servers: Vec<models::AdminClustersServer>) {
servers.sort_by_key(|s| (s.datacenter_id, s.pool_type, s.public_ip.clone()));

let rows = servers.iter().map(|s| ServerTableRow {
server_id: s.server_id,
datacenter_id: s.datacenter_id,
Expand Down
18 changes: 11 additions & 7 deletions svc/pkg/cluster/src/ops/datacenter/topology_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,18 @@ pub async fn cluster_datacenter_topology_get(
}
}

// Get node resource limits
let node = unwrap!(
node_info.iter().find(|node| node
.ID
// Gracefully handle if node does not exist in API response
let Some(node) = node_info.iter().find(|node| {
node.ID
.as_ref()
.map_or(false, |node_id| node_id == &server.nomad_node_id)),
format!("node not found {}", server.nomad_node_id)
);
.map_or(false, |node_id| node_id == &server.nomad_node_id)
}) else {
tracing::error!(%server.nomad_node_id, "node not found in nomad response");

continue;
};

// Get node resource limits
let resources = unwrap_ref!(node.node_resources);
let limits = Stats {
cpu: unwrap!(unwrap_ref!(resources.cpu).cpu_shares) as u64,
Expand Down
8 changes: 6 additions & 2 deletions svc/pkg/cluster/src/ops/server/lost_list.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use std::{net::IpAddr, collections::HashSet, convert::{TryFrom, TryInto}};
use std::{
collections::HashSet,
convert::{TryFrom, TryInto},
net::IpAddr,
};

use chirp_workflow::prelude::*;
use linode::util::client;
use reqwest::header;
use serde_json::json;

use super::get::ServerRow;
use crate::types::{Filter, Server, Provider};
use crate::types::{Filter, Provider, Server};

#[derive(Deserialize)]
struct GetLinodesResponse {
Expand Down
2 changes: 1 addition & 1 deletion svc/pkg/cluster/src/ops/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ pub mod destroy_with_filter;
pub mod get;
pub mod list;
pub mod lost_list;
pub mod prune_with_filter;
pub mod resolve_for_ip;
pub mod taint_with_filter;
pub mod prune_with_filter;
14 changes: 7 additions & 7 deletions svc/pkg/cluster/src/ops/server/prune_with_filter.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::{convert::TryFrom, collections::HashSet};
use std::{collections::HashSet, convert::TryFrom};

use chirp_workflow::prelude::*;
use serde_json::json;
use linode::util::{api, client};
use reqwest::header;
use serde_json::json;

use crate::{types::{Server, Filter, Provider}};
use crate::types::{Filter, Provider, Server};

#[derive(Debug)]
pub struct Input {
Expand All @@ -21,7 +21,7 @@ pub async fn cluster_server_prune_with_filter(
input: &Input,
) -> GlobalResult<Output> {
let linode_token = util::env::read_secret(&["linode", "token"]).await?;

let servers_res = ctx
.op(crate::ops::server::lost_list::Input {
filter: input.filter.clone(),
Expand Down Expand Up @@ -80,7 +80,7 @@ pub async fn cluster_server_prune_with_filter(
}
}
}

Ok(Output {})
}

Expand All @@ -102,9 +102,9 @@ async fn run_for_linode_account(
}

api::delete_instance(&client, linode_id).await?;

// NOTE: Does not delete ssh keys
}

Ok(())
}
}

0 comments on commit b460374

Please sign in to comment.