Skip to content
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/stackable-operator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ futures.workspace = true
http.workspace = true
indexmap.workspace = true
jiff.workspace = true
json-patch.workspace = true
json-patch = { workspace = true, features = ["schemars"] }
k8s-openapi.workspace = true
kube.workspace = true
product-config.workspace = true
Expand Down
1 change: 1 addition & 0 deletions crates/stackable-operator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub mod role_utils;
pub mod status;
pub mod test_utils;
pub mod utils;
pub mod v2;
pub mod validation;

// External re-exports
Expand Down
60 changes: 35 additions & 25 deletions crates/stackable-operator/src/v2/config_overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use std::collections::BTreeMap;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::json;
use stackable_operator::{
use tracing::warn;

use crate::{
config::merge::Merge, k8s_openapi::DeepMerge, schemars, utils::crds::raw_object_schema,
};
use tracing::warn;

// Variant of [`stackable_operator::config_overrides::KeyValueConfigOverrides`] that implements
// Merge
Expand All @@ -15,6 +16,7 @@ use tracing::warn;
/// This is backwards-compatible with the existing flat key-value YAML format
/// used by `HashMap<String, String>`.
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, Merge, PartialEq, Serialize)]
#[merge(path_overrides(merge = "crate::config::merge"))]
pub struct KeyValueConfigOverrides {
#[serde(flatten)]
pub overrides: BTreeMap<String, Option<String>>,
Expand Down Expand Up @@ -96,31 +98,31 @@ impl Default for JsonConfigOverrides {
// `JsonConfigOverrides::Sequence(vec![])`. As this is exposed as the default in the CRD,
// an empty JSON merge patch is returned, because JSON merge patches are the preferred way
// to override the configuration.
JsonConfigOverrides::JsonMergePatch(json!({}))
Self::JsonMergePatch(json!({}))
}
}

impl Merge for JsonConfigOverrides {
fn merge(&mut self, defaults: &Self) {
let mut sequence = if let JsonConfigOverrides::Sequence(sequence) = self {
let mut sequence = if let Self::Sequence(sequence) = self {
sequence.clone()
} else {
vec![self.clone()]
};

if let JsonConfigOverrides::Sequence(base) = defaults {
if let Self::Sequence(base) = defaults {
sequence.extend(base.clone());
} else {
sequence.push(defaults.clone());
}

*self = JsonConfigOverrides::Sequence(sequence);
*self = Self::Sequence(sequence);
}
}

impl From<KeyValueConfigOverrides> for JsonConfigOverrides {
fn from(value: KeyValueConfigOverrides) -> Self {
JsonConfigOverrides::JsonMergePatch(value.overrides.into_iter().collect())
Self::JsonMergePatch(value.overrides.into_iter().collect())
}
}

Expand All @@ -132,32 +134,40 @@ impl From<KeyValueConfigOverrides> for JsonConfigOverrides {
///
/// Example for key-value pairs:
///
/// stringProperty: new value
/// booleanProperty: "true"
/// ```yaml
/// stringProperty: new value
/// booleanProperty: "true"
/// ```
///
/// Example for a JSON merge patch:
///
/// jsonMergePatch:
/// stringProperty: new value
/// booleanProperty: true
/// nestedProperty:
/// key: value
/// ```yaml
/// jsonMergePatch:
/// stringProperty: new value
/// booleanProperty: true
/// nestedProperty:
/// key: value
/// ```
///
/// Example for a JSON patch:
///
/// jsonPatch:
/// - op: replace
/// path: /stringProperty
/// value: new value
/// ```yaml
/// jsonPatch:
/// - op: replace
/// path: /stringProperty
/// value: new value
/// ```
///
/// Example for a JSON object:
///
/// userProvided:
/// stringProperty: new value
/// booleanProperty: true
/// nestedProperty:
/// key: value
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
/// ```yaml
/// userProvided:
/// stringProperty: new value
/// booleanProperty: true
/// nestedProperty:
/// key: value
/// ```
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
#[serde(untagged)]
#[schemars(schema_with = "raw_object_schema")]
pub enum JsonOrKeyValueConfigOverrides {
Expand Down Expand Up @@ -196,9 +206,9 @@ impl Merge for JsonOrKeyValueConfigOverrides {
#[cfg(test)]
mod tests {
use serde_json::json;
use stackable_operator::config::merge;

use super::*;
use crate::config::merge;

#[test]
fn test_json_config_overrides_apply() {
Expand Down
1 change: 1 addition & 0 deletions crates/stackable-operator/src/v2/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod config_overrides;
Loading