Skip to content

Commit 391b427

Browse files
authored
feat: Improve insufficient CPU warning message (#104)
* feat: Improve insufficient CPU warning message * update Cargo.toml
1 parent fc84b2e commit 391b427

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/stackable-cockpit/src/platform/cluster/resource_request.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::fmt::Display;
22

3+
use rand::Rng;
34
#[cfg(feature = "openapi")]
45
use utoipa::ToSchema;
56

@@ -63,12 +64,13 @@ pub enum ResourceRequestsError {
6364
#[derive(Debug, Snafu)]
6465
pub enum ResourceRequestsValidationError {
6566
#[snafu(display(
66-
"The {object_name} requires {} CPU cores, but there are only {} CPU cores available in the cluster", required.as_cpu_count(), available.as_cpu_count()
67+
"The {object_name} requires {} CPU cores, but there are only {} CPU cores available in the cluster{}", required.as_cpu_count(), available.as_cpu_count(), help_message.clone().unwrap_or_default()
6768
))]
6869
InsufficientCpu {
6970
available: CpuQuantity,
7071
required: CpuQuantity,
7172
object_name: String,
73+
help_message: Option<String>,
7274
},
7375

7476
#[snafu(display(
@@ -104,10 +106,12 @@ impl ResourceRequests {
104106
let mut errors = Vec::new();
105107

106108
if stack_cpu > cluster_info.untainted_allocatable_cpu {
109+
let mut rng = rand::thread_rng();
107110
errors.push(ResourceRequestsValidationError::InsufficientCpu {
108111
available: cluster_info.untainted_allocatable_cpu,
109112
object_name: object_name.to_string(),
110113
required: stack_cpu,
114+
help_message: (rng.gen::<f32>() < 0.005).then_some(". Have a look at https://github.com/torvalds/linux/blob/f7757129e3dea336c407551c98f50057c22bb266/include/math-emu/double.h#L29 for a possible solution".to_string()),
111115
});
112116
}
113117

rust/stackablectl/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dotenvy.workspace = true
2020
indexmap.workspace = true
2121
lazy_static.workspace = true
2222
nu-ansi-term.workspace = true
23+
rand.workspace = true
2324
reqwest.workspace = true
2425
semver.workspace = true
2526
serde_json.workspace = true

0 commit comments

Comments
 (0)