Skip to content

[Merged by Bors] - Use Quantity instead of String for resource definitions. #402

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ All notable changes to this project will be documented in this file.

[#397]: https://github.com/stackabletech/operator-rs/pull/397

### Changed

- BREAKING: Memory and CPU resource definitions use quantity instead of String ([#402])

[#402]: https://github.com/stackabletech/operator-rs/pull/402

## [0.19.0] - 2022-05-05

### Changed
Expand Down
24 changes: 12 additions & 12 deletions src/commons/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ where

// Defines memory limits to be set on the pods
// Is generic to enable adding custom configuration for specific runtimes or products
#[derive(Clone, Debug, Deserialize, Default, Merge, JsonSchema, PartialEq, Serialize, Eq)]
#[derive(Clone, Debug, Deserialize, Default, Merge, JsonSchema, PartialEq, Serialize)]
#[merge(path_overrides(merge = "crate::config::merge"))]
#[serde(rename_all = "camelCase")]
pub struct MemoryLimits<T>
Expand All @@ -98,7 +98,7 @@ where
{
// The maximum amount of memory that should be available
// Should in most cases be mapped to resources.limits.memory
pub limit: Option<String>,
pub limit: Option<Quantity>,
// Additional options that may be required
#[serde(default)]
pub runtime_limits: T,
Expand All @@ -117,9 +117,9 @@ pub struct NoRuntimeLimits {}
#[merge(path_overrides(merge = "crate::config::merge"))]
#[serde(rename_all = "camelCase")]
pub struct JvmHeapLimits {
pub max: Option<String>,
pub max: Option<Quantity>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub min: Option<String>,
pub min: Option<Quantity>,
}

// Cpu limits
Expand All @@ -128,16 +128,16 @@ pub struct JvmHeapLimits {
#[merge(path_overrides(merge = "crate::config::merge"))]
#[serde(rename_all = "camelCase")]
pub struct CpuLimits {
pub min: Option<String>,
pub max: Option<String>,
pub min: Option<Quantity>,
pub max: Option<Quantity>,
}

// Struct that exposes the values for a PVC which the user should be able to influence
#[derive(Clone, Debug, Default, Deserialize, Merge, JsonSchema, PartialEq, Serialize)]
#[merge(path_overrides(merge = "crate::config::merge"))]
#[serde(rename_all = "camelCase")]
pub struct PvcConfig {
pub capacity: Option<String>,
pub capacity: Option<Quantity>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub storage_class: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand All @@ -160,7 +160,7 @@ impl PvcConfig {
requests: Some({
let mut map = BTreeMap::new();
if let Some(capacity) = &self.capacity {
map.insert("storage".to_string(), Quantity(capacity.to_string()));
map.insert("storage".to_string(), capacity.clone());
}
map
}),
Expand All @@ -184,15 +184,15 @@ where
let mut limits = BTreeMap::new();
let mut requests = BTreeMap::new();
if let Some(memory_limit) = self.memory.limit {
limits.insert("memory".to_string(), Quantity(memory_limit.to_string()));
requests.insert("memory".to_string(), Quantity(memory_limit));
limits.insert("memory".to_string(), memory_limit.clone());
requests.insert("memory".to_string(), memory_limit);
}

if let Some(cpu_max) = self.cpu.max {
limits.insert("cpu".to_string(), Quantity(cpu_max));
limits.insert("cpu".to_string(), cpu_max);
}
if let Some(cpu_min) = self.cpu.min {
requests.insert("cpu".to_string(), Quantity(cpu_min));
requests.insert("cpu".to_string(), cpu_min);
}

ResourceRequirements {
Expand Down
3 changes: 2 additions & 1 deletion src/config/merge.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use k8s_openapi::apimachinery::pkg::apis::meta::v1::LabelSelector;
use k8s_openapi::apimachinery::pkg::{api::resource::Quantity, apis::meta::v1::LabelSelector};
use std::{
collections::{btree_map, hash_map, BTreeMap, HashMap},
hash::Hash,
Expand Down Expand Up @@ -131,6 +131,7 @@ impl Atomic for i128 {}
impl Atomic for isize {}
impl Atomic for bool {}
impl Atomic for String {}
impl Atomic for Quantity {}
impl<'a> Atomic for &'a str {}
impl Atomic for LabelSelector {}

Expand Down