Skip to content

Commit 861bfc2

Browse files
committed
USe #[schemars(deny_unknown_fields)]
1 parent 2ae3ac9 commit 861bfc2

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

crates/stackable-operator/src/commons/affinity.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use k8s_openapi::{
66
},
77
apimachinery::pkg::apis::meta::v1::LabelSelector,
88
};
9-
use schemars::{schema::Schema, JsonSchema};
9+
use schemars::JsonSchema;
1010
use serde::{Deserialize, Serialize};
1111
use stackable_operator_derive::Fragment;
1212

@@ -39,8 +39,6 @@ pub struct StackableAffinity {
3939
pub pod_affinity: Option<PodAffinity>,
4040
pub pod_anti_affinity: Option<PodAntiAffinity>,
4141
pub node_affinity: Option<NodeAffinity>,
42-
#[schemars(schema_with = "optional_stackable_node_selector_schema")]
43-
#[fragment_attrs(schemars(schema_with = "optional_stackable_node_selector_schema"))]
4442
pub node_selector: Option<StackableNodeSelector>,
4543
}
4644

@@ -49,22 +47,20 @@ pub struct StackableAffinity {
4947
/// [`BTreeMap<String, String>`].
5048
///
5149
/// We `#[serde(flatten)]` the contained [`BTreeMap<String, String>`], so `serde_yaml` can deserialize everything as
52-
/// expected. However the generated JsonSchema will be wrong, so we need to provide our custom one (see
53-
/// <https://github.com/stackabletech/issues/issues/554> for details).
54-
#[derive(Clone, Debug, Eq, Deserialize, PartialEq, Serialize)]
50+
/// expected.
51+
// FIXME: However, the generated JsonSchema will be wrong, so we need to use `#[schemars(deny_unknown_fields)]`.
52+
// See https://github.com/stackabletech/operator-rs/pull/752#issuecomment-2017630433 and
53+
// https://github.com/GREsau/schemars/issues/259 for details.
54+
#[derive(Clone, Debug, Eq, Deserialize, JsonSchema, PartialEq, Serialize)]
5555
#[serde(rename_all = "camelCase")]
56+
#[schemars(deny_unknown_fields)]
5657
pub struct StackableNodeSelector {
5758
#[serde(flatten)]
5859
pub node_selector: BTreeMap<String, String>,
5960
}
6061

6162
impl Atomic for StackableNodeSelector {}
6263

63-
/// We need a custom JsonSchema for [`StackableNodeSelector`], please have a look at the documentation there.
64-
pub fn optional_stackable_node_selector_schema(gen: &mut schemars::gen::SchemaGenerator) -> Schema {
65-
Option::<BTreeMap<String, String>>::json_schema(gen)
66-
}
67-
6864
/// Creates a `WeightedPodAffinityTerm`, which expresses a affinity towards all Pods of the given product (`app_name`) instance (`cluster_name`) role (`role`).
6965
/// This affinity can be used to attract towards (affinity) or away (anti-affinity) from the specified role.
7066
/// One common example would be to use this to distribute all the Pods of a certain role, e.g. hdfs datanodes.

0 commit comments

Comments
 (0)