Skip to content

Commit bfb924f

Browse files
committed
fix(operator/crd): Skip serializing traffic policy field if None
We skip serialization if this is None to ensure that forwarding the selection of the policy to Kubernetes works as expected. We stumbled over the following unexpected behaviour: - If ListenerClass manifests (which don't set this field) are applied by a client (like kubectl or helm), they are applied as expected - no errors. - If the same manifests are applied by Rust code, it fails. This field cannot be set to "null". Serde by default serializes None to "null". We expected there to be a null variant in the schema, which would allow setting this field to null, but the schema only lists the two available variants. Additionally, ad-hoc testing showed that manifests would still be rejected after manually adjusting the schema in the CRD. This is something which should be investigated further.
1 parent 73ed8c5 commit bfb924f

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

  • crates/stackable-operator/src/crd/listener/class

crates/stackable-operator/src/crd/listener/class/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ pub mod versioned {
6969
// (which currently defaults to `Cluster`). This should be the most sensible option in most cases.
7070
// There is the possibility Kubernetes will automatically choose `Local` if support for it on the
7171
// LoadBalancer has been detected.
72+
//
73+
// We skip serialization if this is None to ensure that forwarding the selection of the policy to
74+
// Kubernetes works as expected. We stumbled over the following unexpected behaviour:
75+
//
76+
// - If ListenerClass manifests (which don't set this field) are applied by a client (like kubectl or helm),
77+
// they are applied as expected - no errors.
78+
// - If the same manifests are applied by Rust code, it fails. This field cannot be set to "null". Serde by
79+
// default serializes None to "null".
80+
//
81+
// We expected there to be a null variant in the schema, which would allow setting this field to null, but
82+
// the schema only lists the two available variants. Additionally, ad-hoc testing showed that manifests would
83+
// still be rejected after manually adjusting the schema in the CRD. This is something which should be
84+
// investigated further.
85+
#[serde(skip_serializing_if = "Option::is_none")]
7286
pub service_external_traffic_policy: Option<core_v1alpha1::KubernetesTrafficPolicy>,
7387

7488
/// Whether addresses should prefer using the IP address (`IP`) or the hostname (`Hostname`).

0 commit comments

Comments
 (0)