Skip to content

Commit 8d7f40f

Browse files
test: Test JsonConfigOverrides in the DummyCluster instead of a unit test
1 parent 267de29 commit 8d7f40f

3 files changed

Lines changed: 22 additions & 138 deletions

File tree

crates/stackable-operator/crds/DummyCluster.yaml

Lines changed: 16 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ spec:
979979
- required:
980980
- jsonMergePatch
981981
- required:
982-
- jsonPatches
982+
- jsonPatch
983983
- required:
984984
- userProvided
985985
properties:
@@ -989,50 +989,26 @@ spec:
989989
[RFC 7396](https://datatracker.ietf.org/doc/html/rfc7396) JSON merge patch.
990990
type: object
991991
x-kubernetes-preserve-unknown-fields: true
992-
jsonPatches:
992+
jsonPatch:
993993
description: |-
994-
List of [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902) JSON patches.
994+
An [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902) JSON patch.
995995
996996
Can be used when more flexibility is needed, e.g. to only modify elements
997997
in a list based on a condition.
998998
999999
A patch looks something like
10001000
1001-
`{"op": "test", "path": "/0/name", "value": "Andrew"}`
1001+
`- {"op": "test", "path": "/0/name", "value": "Andrew"}`
10021002
10031003
or
10041004
1005-
`{"op": "add", "path": "/0/happy", "value": true}`
1005+
`- {"op": "add", "path": "/0/happy", "value": true}`
10061006
items:
1007-
type: string
1007+
type: object
1008+
x-kubernetes-preserve-unknown-fields: true
10081009
type: array
10091010
userProvided:
1010-
description: |-
1011-
Override the entire config file with the specified JSON document.
1012-
1013-
Please note that you can in-line JSON into YAML as follows:
1014-
1015-
```yaml
1016-
# ... other YAML content
1017-
userProvided: {
1018-
"myString": "test",
1019-
"myList": ["test"],
1020-
"myBool": true,
1021-
"my": {"nested.field.with.dots": 42}
1022-
}
1023-
```
1024-
1025-
As an alternative you can also stick to YAML:
1026-
1027-
```yaml
1028-
# ... other YAML content
1029-
userProvided:
1030-
myString: test
1031-
myList: [test]
1032-
myBool: true
1033-
my:
1034-
nested.field.with.dots: 42
1035-
```
1011+
description: Override the entire config file with the specified JSON value.
10361012
type: object
10371013
x-kubernetes-preserve-unknown-fields: true
10381014
type: object
@@ -1657,7 +1633,7 @@ spec:
16571633
- required:
16581634
- jsonMergePatch
16591635
- required:
1660-
- jsonPatches
1636+
- jsonPatch
16611637
- required:
16621638
- userProvided
16631639
properties:
@@ -1667,50 +1643,26 @@ spec:
16671643
[RFC 7396](https://datatracker.ietf.org/doc/html/rfc7396) JSON merge patch.
16681644
type: object
16691645
x-kubernetes-preserve-unknown-fields: true
1670-
jsonPatches:
1646+
jsonPatch:
16711647
description: |-
1672-
List of [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902) JSON patches.
1648+
An [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902) JSON patch.
16731649
16741650
Can be used when more flexibility is needed, e.g. to only modify elements
16751651
in a list based on a condition.
16761652
16771653
A patch looks something like
16781654
1679-
`{"op": "test", "path": "/0/name", "value": "Andrew"}`
1655+
`- {"op": "test", "path": "/0/name", "value": "Andrew"}`
16801656
16811657
or
16821658
1683-
`{"op": "add", "path": "/0/happy", "value": true}`
1659+
`- {"op": "add", "path": "/0/happy", "value": true}`
16841660
items:
1685-
type: string
1661+
type: object
1662+
x-kubernetes-preserve-unknown-fields: true
16861663
type: array
16871664
userProvided:
1688-
description: |-
1689-
Override the entire config file with the specified JSON document.
1690-
1691-
Please note that you can in-line JSON into YAML as follows:
1692-
1693-
```yaml
1694-
# ... other YAML content
1695-
userProvided: {
1696-
"myString": "test",
1697-
"myList": ["test"],
1698-
"myBool": true,
1699-
"my": {"nested.field.with.dots": 42}
1700-
}
1701-
```
1702-
1703-
As an alternative you can also stick to YAML:
1704-
1705-
```yaml
1706-
# ... other YAML content
1707-
userProvided:
1708-
myString: test
1709-
myList: [test]
1710-
myBool: true
1711-
my:
1712-
nested.field.with.dots: 42
1713-
```
1665+
description: Override the entire config file with the specified JSON value.
17141666
type: object
17151667
x-kubernetes-preserve-unknown-fields: true
17161668
type: object

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

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -254,83 +254,11 @@ impl Merge for JsonOrKeyValueConfigOverrides {
254254

255255
#[cfg(test)]
256256
mod tests {
257-
use indoc::indoc;
258-
use kube::core::schema::StructuralSchemaRewriter;
259-
use schemars::generate::SchemaSettings;
260257
use serde_json::json;
261258

262259
use super::*;
263260
use crate::config::merge;
264261

265-
#[test]
266-
fn test_json_config_overrides_schema() {
267-
let schema = SchemaSettings::default()
268-
.with_transform(StructuralSchemaRewriter)
269-
.into_generator()
270-
.into_root_schema_for::<JsonConfigOverrides>();
271-
272-
assert_eq!(
273-
json!({
274-
"$schema": "https://json-schema.org/draft/2020-12/schema",
275-
"description": "ConfigOverrides that can be applied to a JSON file.",
276-
"oneOf": [
277-
{
278-
"required": [
279-
"jsonMergePatch"
280-
]
281-
},
282-
{
283-
"required": [
284-
"jsonPatch"
285-
]
286-
},
287-
{
288-
"required": [
289-
"userProvided"
290-
]
291-
}
292-
],
293-
"properties": {
294-
"jsonMergePatch": {
295-
"description": indoc!("
296-
Can be set to arbitrary YAML content, which is converted to JSON and used as
297-
[RFC 7396](https://datatracker.ietf.org/doc/html/rfc7396) JSON merge patch."),
298-
"type": "object",
299-
"x-kubernetes-preserve-unknown-fields": true
300-
},
301-
"jsonPatch": {
302-
"description": indoc!(r#"
303-
An [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902) JSON patch.
304-
305-
Can be used when more flexibility is needed, e.g. to only modify elements
306-
in a list based on a condition.
307-
308-
A patch looks something like
309-
310-
`- {"op": "test", "path": "/0/name", "value": "Andrew"}`
311-
312-
or
313-
314-
`- {"op": "add", "path": "/0/happy", "value": true}`"#),
315-
"items": {
316-
"type": "object",
317-
"x-kubernetes-preserve-unknown-fields": true
318-
},
319-
"type": "array"
320-
},
321-
"userProvided": {
322-
"description": "Override the entire config file with the specified JSON value.",
323-
"type": "object",
324-
"x-kubernetes-preserve-unknown-fields": true
325-
}
326-
},
327-
"title": "JsonConfigOverrides",
328-
"type": "object"
329-
}),
330-
schema
331-
);
332-
}
333-
334262
#[test]
335263
fn test_json_config_overrides_apply() {
336264
let base = json!({

crates/xtask/src/crd/dummy.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ use serde::{Deserialize, Serialize};
44
use stackable_operator::{
55
commons::resources::{JvmHeapLimits, Resources},
66
config::fragment::Fragment,
7-
config_overrides::{JsonConfigOverrides, KeyValueConfigOverrides, KeyValueOverridesProvider},
8-
crd::{authentication, authentication::oidc, git_sync::v1alpha2::GitSync},
7+
config_overrides::{KeyValueConfigOverrides, KeyValueOverridesProvider},
8+
crd::{
9+
authentication::{self, oidc},
10+
git_sync::v1alpha2::GitSync,
11+
},
912
database_connections::{
1013
databases::{
1114
derby::DerbyConnection, mysql::MysqlConnection, postgresql::PostgresqlConnection,
@@ -21,6 +24,7 @@ use stackable_operator::{
2124
role_utils::Role,
2225
schemars::JsonSchema,
2326
status::condition::ClusterCondition,
27+
v2::config_overrides::JsonConfigOverrides,
2428
versioned::versioned,
2529
};
2630
use strum::EnumIter;

0 commit comments

Comments
 (0)