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
6 changes: 6 additions & 0 deletions crates/stackable-operator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Added

- Add `utils::crds::raw_any_nullable_value_schema`, which accepts any JSON value (not only objects) ([#1326]).

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

## [0.122.0] - 2026-11-03

### Added
Expand Down
62 changes: 62 additions & 0 deletions crates/stackable-operator/crds/DummyCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2685,6 +2685,68 @@ spec:
status:
nullable: true
properties:
changedValues:
description: Contains changed values during upgrades and downgrades of CRDs.
properties:
downgrades:
additionalProperties:
items:
description: Contains a changed value for a single field of the CRD.
properties:
downgradedValue:
description: |-
The value the field was converted to during the downgrade. Only set for fields which
changed their type.

When upgrading again, the tracked `value` is only applied if the field still contains this
value. Otherwise, the field was changed by a user in the older version and that change is
kept instead.
nullable: true
x-kubernetes-preserve-unknown-fields: true
jsonPath:
description: The name of the field of the custom resource this value is for.
type: string
value:
description: The value to be used when upgrading or downgrading the custom resource.
nullable: true
x-kubernetes-preserve-unknown-fields: true
required:
- jsonPath
- value
type: object
type: array
description: List of values needed when downgrading to a particular version.
type: object
upgrades:
additionalProperties:
items:
description: Contains a changed value for a single field of the CRD.
properties:
downgradedValue:
description: |-
The value the field was converted to during the downgrade. Only set for fields which
changed their type.

When upgrading again, the tracked `value` is only applied if the field still contains this
value. Otherwise, the field was changed by a user in the older version and that change is
kept instead.
nullable: true
x-kubernetes-preserve-unknown-fields: true
jsonPath:
description: The name of the field of the custom resource this value is for.
type: string
value:
description: The value to be used when upgrading or downgrading the custom resource.
nullable: true
x-kubernetes-preserve-unknown-fields: true
required:
- jsonPath
- value
type: object
type: array
description: List of values needed when upgrading to a particular version.
type: object
type: object
conditions:
items:
properties:
Expand Down
10 changes: 10 additions & 0 deletions crates/stackable-operator/src/utils/crds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ pub fn raw_optional_object_schema(_: &mut schemars::generate::SchemaGenerator) -
})
}

/// Accepts any JSON value (object, array, string, number, bool or null).
///
/// Kubernetes allows omitting the `type` for nodes with `x-kubernetes-preserve-unknown-fields`.
pub fn raw_any_nullable_value_schema(_: &mut schemars::generate::SchemaGenerator) -> Schema {
json_schema!({
"nullable": true,
"x-kubernetes-preserve-unknown-fields": true,
})
}

pub fn raw_object_list_schema(_: &mut schemars::generate::SchemaGenerator) -> Schema {
json_schema!({
"type": "array",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,11 @@ impl Struct {
versioned_path = path_to_string(versioned_path)
);

// The derive macros default to the `schemars` and `serde` crates, which are not necessarily
// direct dependencies of the user, so we have to tell them about crate overrides.
let schemars_path_string = path_to_string(schemars_path);
let serde_path_string = path_to_string(serde_path);

// TODO (@Techassi): Validate that users don't specify the status we generate
let status = spec_gen_ctx
.kubernetes_arguments
Expand All @@ -595,7 +600,8 @@ impl Struct {
#serde_path::Serialize,
#schemars_path::JsonSchema
)]
#[serde(rename_all = "camelCase")]
#[schemars(crate = #schemars_path_string)]
#[serde(crate = #serde_path_string, 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
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.

6 changes: 6 additions & 0 deletions crates/stackable-versioned/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ All notable changes to this project will be documented in this file.
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.
- The CRD schema of tracked values (`value` and `downgradedValue`) now accepts any JSON value instead
of only objects. Previously, patching the status failed for tracked non-object values, such as
strings ([#1326]).
- The generated tracking status now respects the `schemars` and `serde` crate overrides. Previously,
it failed to compile if these crates were not direct dependencies ([#1326]).

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

## [0.14.0] - 2026-11-03

Expand Down
8 changes: 4 additions & 4 deletions crates/stackable-versioned/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub struct ChangedValue {
// NOTE: This needs to be a JSON value, because the status is stored as JSON. YAML values
// represent enum variants as tags, which can't be deserialized again after a roundtrip
// through JSON.
#[schemars(schema_with = "raw_object_schema")]
#[schemars(schema_with = "raw_any_nullable_value_schema")]
pub value: serde_json::Value,

/// The value the field was converted to during the downgrade. Only set for fields which
Expand All @@ -133,16 +133,16 @@ pub struct ChangedValue {
/// value. Otherwise, the field was changed by a user in the older version and that change is
/// kept instead.
#[serde(default, skip_serializing_if = "Option::is_none")]
#[schemars(schema_with = "raw_object_schema")]
#[schemars(schema_with = "raw_any_nullable_value_schema")]
pub downgraded_value: Option<serde_json::Value>,
}

// TODO (@Techassi): Think about where this should live. Basically this already exists in
// stackable-operator, but we cannot use it without depending on it which I would like to
// avoid.
fn raw_object_schema(_: &mut schemars::generate::SchemaGenerator) -> Schema {
fn raw_any_nullable_value_schema(_: &mut schemars::generate::SchemaGenerator) -> Schema {
json_schema!({
"type": "object",
"nullable": true,
"x-kubernetes-preserve-unknown-fields": true,
})
}
Expand Down
3 changes: 2 additions & 1 deletion crates/xtask/src/crd/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ impl KeyValueOverridesProvider for DummyConfigOverrides {
k8s_openapi = "stackable_operator::k8s_openapi",
schemars = "stackable_operator::schemars",
versioned = "stackable_operator::versioned"
)
),
options(k8s(experimental_conversion_tracking))
)]
pub mod versioned {
#[versioned(crd(
Expand Down
Loading