From 8fc0e2b96790e661b0cb2b2d5027a056a9edd451 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Fri, 9 Aug 2024 09:13:17 +0200 Subject: [PATCH 1/3] fix: Invalid CRD schema for StackableAffinity contents --- crates/stackable-operator/CHANGELOG.md | 4 ++++ crates/stackable-operator/src/commons/affinity.rs | 8 ++++---- crates/stackable-operator/src/utils/crds.rs | 9 +++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/crates/stackable-operator/CHANGELOG.md b/crates/stackable-operator/CHANGELOG.md index 51a010ad9..6d69bc820 100644 --- a/crates/stackable-operator/CHANGELOG.md +++ b/crates/stackable-operator/CHANGELOG.md @@ -8,6 +8,10 @@ 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 ([XXX]). + [#833]: https://github.com/stackabletech/operator-rs/pull/833 ## [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", From d66aae765b9324adca96c9a329821aed10acff37 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Fri, 9 Aug 2024 09:14:08 +0200 Subject: [PATCH 2/3] changelog --- crates/stackable-operator/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/stackable-operator/CHANGELOG.md b/crates/stackable-operator/CHANGELOG.md index 6d69bc820..9980571ba 100644 --- a/crates/stackable-operator/CHANGELOG.md +++ b/crates/stackable-operator/CHANGELOG.md @@ -10,9 +10,10 @@ All notable changes to this project will be documented in this file. ### 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 ([XXX]). +- 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 From bd6017a89c71a2b258548f5bcfdfb971e067d09a Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Fri, 9 Aug 2024 09:16:06 +0200 Subject: [PATCH 3/3] changelog --- crates/stackable-operator/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/stackable-operator/CHANGELOG.md b/crates/stackable-operator/CHANGELOG.md index 9980571ba..18d6768a3 100644 --- a/crates/stackable-operator/CHANGELOG.md +++ b/crates/stackable-operator/CHANGELOG.md @@ -10,7 +10,7 @@ All notable changes to this project will be documented in this file. ### 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]). +- 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