diff --git a/crates/stackable-operator/CHANGELOG.md b/crates/stackable-operator/CHANGELOG.md index 51a010ad9..18d6768a3 100644 --- a/crates/stackable-operator/CHANGELOG.md +++ b/crates/stackable-operator/CHANGELOG.md @@ -8,7 +8,12 @@ All notable changes to this project will be documented in this file. - Rollout tracker for `StatefulSet` ([#833]). +### Fixed + +- 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]). + [#833]: https://github.com/stackabletech/operator-rs/pull/833 +[#836]: https://github.com/stackabletech/operator-rs/pull/836 ## [0.72.0] - 2024-08-05 diff --git a/crates/stackable-operator/src/commons/affinity.rs b/crates/stackable-operator/src/commons/affinity.rs index 1ecfcc059..21df0cbbc 100644 --- a/crates/stackable-operator/src/commons/affinity.rs +++ b/crates/stackable-operator/src/commons/affinity.rs @@ -13,7 +13,7 @@ use stackable_operator_derive::Fragment; use crate::{ config::merge::{Atomic, Merge}, kvp::consts::{K8S_APP_COMPONENT_KEY, K8S_APP_INSTANCE_KEY, K8S_APP_NAME_KEY}, - utils::crds::raw_object_schema, + utils::crds::raw_optional_object_schema, }; pub const TOPOLOGY_KEY_HOSTNAME: &str = "kubernetes.io/hostname"; @@ -38,15 +38,15 @@ pub const TOPOLOGY_KEY_HOSTNAME: &str = "kubernetes.io/hostname"; )] pub struct StackableAffinity { /// Same as the `spec.affinity.podAffinity` field on the Pod, see the [Kubernetes docs](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node) - #[fragment_attrs(schemars(schema_with = "raw_object_schema"))] + #[fragment_attrs(schemars(schema_with = "raw_optional_object_schema"))] pub pod_affinity: Option, /// Same as the `spec.affinity.podAntiAffinity` field on the Pod, see the [Kubernetes docs](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node) - #[fragment_attrs(schemars(schema_with = "raw_object_schema"))] + #[fragment_attrs(schemars(schema_with = "raw_optional_object_schema"))] pub pod_anti_affinity: Option, /// Same as the `spec.affinity.nodeAffinity` field on the Pod, see the [Kubernetes docs](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node) - #[fragment_attrs(schemars(schema_with = "raw_object_schema"))] + #[fragment_attrs(schemars(schema_with = "raw_optional_object_schema"))] pub node_affinity: Option, // This schema isn't big, so it can stay diff --git a/crates/stackable-operator/src/utils/crds.rs b/crates/stackable-operator/src/utils/crds.rs index 8d74e2786..6994bc607 100644 --- a/crates/stackable-operator/src/utils/crds.rs +++ b/crates/stackable-operator/src/utils/crds.rs @@ -8,6 +8,15 @@ pub fn raw_object_schema(_: &mut schemars::gen::SchemaGenerator) -> Schema { .expect("Failed to parse JSON of custom raw object schema") } +pub fn raw_optional_object_schema(_: &mut schemars::gen::SchemaGenerator) -> Schema { + serde_json::from_value(serde_json::json!({ + "type": "object", + "nullable": true, + "x-kubernetes-preserve-unknown-fields": true, + })) + .expect("Failed to parse JSON of custom optional raw object schema") +} + pub fn raw_object_list_schema(_: &mut schemars::gen::SchemaGenerator) -> Schema { serde_json::from_value(serde_json::json!({ "type": "array",