Skip to content

Commit 2563bd2

Browse files
authored
fix: make config_overrides public (#1210)
fix(config_overrides): make config_overrides public, fix clippy & doc checks
1 parent 713ca9c commit 2563bd2

5 files changed

Lines changed: 39 additions & 26 deletions

File tree

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.

crates/stackable-operator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ futures.workspace = true
3636
http.workspace = true
3737
indexmap.workspace = true
3838
jiff.workspace = true
39-
json-patch.workspace = true
39+
json-patch = { workspace = true, features = ["schemars"] }
4040
k8s-openapi.workspace = true
4141
kube.workspace = true
4242
product-config.workspace = true

crates/stackable-operator/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub mod role_utils;
3333
pub mod status;
3434
pub mod test_utils;
3535
pub mod utils;
36+
pub mod v2;
3637
pub mod validation;
3738

3839
// External re-exports

crates/stackable-operator/src/v2/config_overrides.rs

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ use std::collections::BTreeMap;
33
use schemars::JsonSchema;
44
use serde::{Deserialize, Serialize};
55
use serde_json::json;
6-
use stackable_operator::{
6+
use tracing::warn;
7+
8+
use crate::{
79
config::merge::Merge, k8s_openapi::DeepMerge, schemars, utils::crds::raw_object_schema,
810
};
9-
use tracing::warn;
1011

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

103105
impl Merge for JsonConfigOverrides {
104106
fn merge(&mut self, defaults: &Self) {
105-
let mut sequence = if let JsonConfigOverrides::Sequence(sequence) = self {
107+
let mut sequence = if let Self::Sequence(sequence) = self {
106108
sequence.clone()
107109
} else {
108110
vec![self.clone()]
109111
};
110112

111-
if let JsonConfigOverrides::Sequence(base) = defaults {
113+
if let Self::Sequence(base) = defaults {
112114
sequence.extend(base.clone());
113115
} else {
114116
sequence.push(defaults.clone());
115117
}
116118

117-
*self = JsonConfigOverrides::Sequence(sequence);
119+
*self = Self::Sequence(sequence);
118120
}
119121
}
120122

121123
impl From<KeyValueConfigOverrides> for JsonConfigOverrides {
122124
fn from(value: KeyValueConfigOverrides) -> Self {
123-
JsonConfigOverrides::JsonMergePatch(value.overrides.into_iter().collect())
125+
Self::JsonMergePatch(value.overrides.into_iter().collect())
124126
}
125127
}
126128

@@ -132,32 +134,40 @@ impl From<KeyValueConfigOverrides> for JsonConfigOverrides {
132134
///
133135
/// Example for key-value pairs:
134136
///
135-
/// stringProperty: new value
136-
/// booleanProperty: "true"
137+
/// ```yaml
138+
/// stringProperty: new value
139+
/// booleanProperty: "true"
140+
/// ```
137141
///
138142
/// Example for a JSON merge patch:
139143
///
140-
/// jsonMergePatch:
141-
/// stringProperty: new value
142-
/// booleanProperty: true
143-
/// nestedProperty:
144-
/// key: value
144+
/// ```yaml
145+
/// jsonMergePatch:
146+
/// stringProperty: new value
147+
/// booleanProperty: true
148+
/// nestedProperty:
149+
/// key: value
150+
/// ```
145151
///
146152
/// Example for a JSON patch:
147153
///
148-
/// jsonPatch:
149-
/// - op: replace
150-
/// path: /stringProperty
151-
/// value: new value
154+
/// ```yaml
155+
/// jsonPatch:
156+
/// - op: replace
157+
/// path: /stringProperty
158+
/// value: new value
159+
/// ```
152160
///
153161
/// Example for a JSON object:
154162
///
155-
/// userProvided:
156-
/// stringProperty: new value
157-
/// booleanProperty: true
158-
/// nestedProperty:
159-
/// key: value
160-
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
163+
/// ```yaml
164+
/// userProvided:
165+
/// stringProperty: new value
166+
/// booleanProperty: true
167+
/// nestedProperty:
168+
/// key: value
169+
/// ```
170+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
161171
#[serde(untagged)]
162172
#[schemars(schema_with = "raw_object_schema")]
163173
pub enum JsonOrKeyValueConfigOverrides {
@@ -196,9 +206,9 @@ impl Merge for JsonOrKeyValueConfigOverrides {
196206
#[cfg(test)]
197207
mod tests {
198208
use serde_json::json;
199-
use stackable_operator::config::merge;
200209

201210
use super::*;
211+
use crate::config::merge;
202212

203213
#[test]
204214
fn test_json_config_overrides_apply() {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod config_overrides;

0 commit comments

Comments
 (0)