diff --git a/CHANGELOG.md b/CHANGELOG.md index 18356dae5..9d6535ecf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/commons/resources.rs b/src/commons/resources.rs index de2ef937c..c6ae7bdb4 100644 --- a/src/commons/resources.rs +++ b/src/commons/resources.rs @@ -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 @@ -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, + pub limit: Option, // Additional options that may be required #[serde(default)] pub runtime_limits: T, @@ -117,9 +117,9 @@ pub struct NoRuntimeLimits {} #[merge(path_overrides(merge = "crate::config::merge"))] #[serde(rename_all = "camelCase")] pub struct JvmHeapLimits { - pub max: Option, + pub max: Option, #[serde(default, skip_serializing_if = "Option::is_none")] - pub min: Option, + pub min: Option, } // Cpu limits @@ -128,8 +128,8 @@ pub struct JvmHeapLimits { #[merge(path_overrides(merge = "crate::config::merge"))] #[serde(rename_all = "camelCase")] pub struct CpuLimits { - pub min: Option, - pub max: Option, + pub min: Option, + pub max: Option, } // Struct that exposes the values for a PVC which the user should be able to influence @@ -137,7 +137,7 @@ pub struct CpuLimits { #[merge(path_overrides(merge = "crate::config::merge"))] #[serde(rename_all = "camelCase")] pub struct PvcConfig { - pub capacity: Option, + pub capacity: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub storage_class: Option, #[serde(default, skip_serializing_if = "Option::is_none")] @@ -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 }), @@ -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 { diff --git a/src/config/merge.rs b/src/config/merge.rs index aa7f62637..324c87a0d 100644 --- a/src/config/merge.rs +++ b/src/config/merge.rs @@ -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, @@ -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 {}