Skip to content

Commit 12395a0

Browse files
authored
fix: Invalid CRD schema for StackableAffinity contents (#836)
* fix: Invalid CRD schema for StackableAffinity contents * changelog * changelog
1 parent e8e401a commit 12395a0

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

crates/stackable-operator/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ All notable changes to this project will be documented in this file.
88

99
- Rollout tracker for `StatefulSet` ([#833]).
1010

11+
### Fixed
12+
13+
- Invalid CRD schema for `StackableAffinity` contents. This was caused by the fields being optional and defaulting to `null`, while the custom schema marked the field as required ([#836]).
14+
1115
[#833]: https://github.com/stackabletech/operator-rs/pull/833
16+
[#836]: https://github.com/stackabletech/operator-rs/pull/836
1217

1318
## [0.72.0] - 2024-08-05
1419

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use stackable_operator_derive::Fragment;
1313
use crate::{
1414
config::merge::{Atomic, Merge},
1515
kvp::consts::{K8S_APP_COMPONENT_KEY, K8S_APP_INSTANCE_KEY, K8S_APP_NAME_KEY},
16-
utils::crds::raw_object_schema,
16+
utils::crds::raw_optional_object_schema,
1717
};
1818

1919
pub const TOPOLOGY_KEY_HOSTNAME: &str = "kubernetes.io/hostname";
@@ -38,15 +38,15 @@ pub const TOPOLOGY_KEY_HOSTNAME: &str = "kubernetes.io/hostname";
3838
)]
3939
pub struct StackableAffinity {
4040
/// Same as the `spec.affinity.podAffinity` field on the Pod, see the [Kubernetes docs](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node)
41-
#[fragment_attrs(schemars(schema_with = "raw_object_schema"))]
41+
#[fragment_attrs(schemars(schema_with = "raw_optional_object_schema"))]
4242
pub pod_affinity: Option<PodAffinity>,
4343

4444
/// Same as the `spec.affinity.podAntiAffinity` field on the Pod, see the [Kubernetes docs](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node)
45-
#[fragment_attrs(schemars(schema_with = "raw_object_schema"))]
45+
#[fragment_attrs(schemars(schema_with = "raw_optional_object_schema"))]
4646
pub pod_anti_affinity: Option<PodAntiAffinity>,
4747

4848
/// Same as the `spec.affinity.nodeAffinity` field on the Pod, see the [Kubernetes docs](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node)
49-
#[fragment_attrs(schemars(schema_with = "raw_object_schema"))]
49+
#[fragment_attrs(schemars(schema_with = "raw_optional_object_schema"))]
5050
pub node_affinity: Option<NodeAffinity>,
5151

5252
// This schema isn't big, so it can stay

crates/stackable-operator/src/utils/crds.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ pub fn raw_object_schema(_: &mut schemars::gen::SchemaGenerator) -> Schema {
88
.expect("Failed to parse JSON of custom raw object schema")
99
}
1010

11+
pub fn raw_optional_object_schema(_: &mut schemars::gen::SchemaGenerator) -> Schema {
12+
serde_json::from_value(serde_json::json!({
13+
"type": "object",
14+
"nullable": true,
15+
"x-kubernetes-preserve-unknown-fields": true,
16+
}))
17+
.expect("Failed to parse JSON of custom optional raw object schema")
18+
}
19+
1120
pub fn raw_object_list_schema(_: &mut schemars::gen::SchemaGenerator) -> Schema {
1221
serde_json::from_value(serde_json::json!({
1322
"type": "array",

0 commit comments

Comments
 (0)