Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,11 @@ impl Struct {

let automatically_derived = mod_gen_ctx.automatically_derived_attr();

let changed_values_is_empty = format!(
"{versioned_path}::ChangedValues::is_empty",
versioned_path = path_to_string(versioned_path)
);

// TODO (@Techassi): Validate that users don't specify the status we generate
let status = spec_gen_ctx
.kubernetes_arguments
Expand All @@ -592,6 +597,10 @@ impl Struct {
)]
#[serde(rename_all = "camelCase")]
pub struct #status_ident {
// Objects created directly in the storage version never pass through the conversion
// webhook, so their status doesn't contain any changed values. The field must therefore
// not be required, otherwise operators fail to patch the status of such objects.
#[serde(default, skip_serializing_if = #changed_values_is_empty)]
pub changed_values: #versioned_path::ChangedValues,

#status
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions crates/stackable-versioned/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ All notable changes to this project will be documented in this file.
Removed fields are not tracked when `experimental_conversion_tracking` is enabled yet.
It doesn't support enum variants either for now ([#1324]).

### Fixed

- The `changedValues` field of the generated tracking status is no longer required and isn't
Comment thread
Techassi marked this conversation as resolved.
Resolved
serialized when empty. Previously, patching the status of objects created directly in the storage
version failed, as they never pass through the conversion webhook ([#1325]).
We also reduced "clutter" in the CR's status by only serializing tracking information into the status
in case something was actually tracked.

[#1324]: https://github.com/stackabletech/operator-rs/pull/1324
[#1325]: https://github.com/stackabletech/operator-rs/pull/1325

## [0.14.0] - 2026-11-03

Expand Down
13 changes: 10 additions & 3 deletions crates/stackable-versioned/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,28 @@ pub trait TrackingStatus {

// NOTE (@Techassi): This struct represents a rough first draft of how tracking values across
// CRD versions can be achieved. It might change down the line.
// FIXME (@Techassi): Ideally we don't serialize empty maps. Further, we shouldn't serialize the
// changedValues field in the status, if there it is empty. This currently "pollutes" the status
// with empty JSON objects.
//
/// Contains changed values during upgrades and downgrades of CRDs.
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
pub struct ChangedValues {
/// List of values needed when downgrading to a particular version.
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub downgrades: BTreeMap<String, Vec<ChangedValue>>,

/// List of values needed when upgrading to a particular version.
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub upgrades: BTreeMap<String, Vec<ChangedValue>>,
// TODO (@Techassi): Add a version indicator here if we ever decide to change the tracking
// mechanism.
}

impl ChangedValues {
/// Returns `true` if neither downgrades nor upgrades contain tracked, changed values.
pub fn is_empty(&self) -> bool {
self.downgrades.is_empty() && self.upgrades.is_empty()
}
}

/// Contains a changed value for a single field of the CRD.
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
#[serde(rename_all = "camelCase")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@
}
},
"status": {
"alive": true,
"changedValues": {
"downgrades": {},
"upgrades": {}
}
"alive": true
}
}
]
Expand Down
4 changes: 0 additions & 4 deletions crates/stackable-versioned/tests/roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ mod person;
fn person_v3_v1alpha1_v3() {
glob!("./inputs/roundtrip", "*.json", |path| {
// Convert from v3 to v1alpha1
// NOTE (@Techassi): It should be noted that the input conversion review
// contains a status with empty changedValues to be able to assert_eq
// the objects at the end. As mentioned in the actual macro code, we
// should avoid "polluting" the status if it is empty.
let (request_v1alpha1, response_v1alpha1) = person::convert_via_file(path);
let response = response_v1alpha1
.response
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions crates/stackable-versioned/tests/status.rs
Comment thread
Techassi marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use serde_json::json;

use crate::person::{Person, PersonStatusWithChangedValues, PersonVersion};

mod person;

// Objects created directly in the storage version never pass through the conversion webhook, so
// their status doesn't contain any changed values. Operators must still be able to patch and read
// the status of such objects.
#[test]
fn status_does_not_require_changed_values() {
let merged_crd = Person::merged_crd(PersonVersion::V2).expect("the CRDs must be mergeable");

for version in merged_crd.spec.versions {
let status_schema = version
.schema
.and_then(|schema| schema.open_api_v3_schema)
.and_then(|schema| schema.properties)
.and_then(|mut properties| properties.remove("status"))
.expect("the CRD must contain a status schema");

assert!(
!status_schema
.required
.unwrap_or_default()
.contains(&"changedValues".to_owned()),
"changedValues must not be required in the status of version {version}",
version = version.name
);
}

let status: PersonStatusWithChangedValues = serde_json::from_value(json!({ "alive": false }))
.expect("the status must deserialize without changedValues");
assert!(status.changed_values.is_empty());

// Empty changed values are not serialized
assert_eq!(
serde_json::to_value(&status).expect("the status must serialize"),
json!({ "alive": false })
);
}
Loading