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
2 changes: 1 addition & 1 deletion crates/stackable-operator/src/crd/git_sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub mod versioned {
// FIXME: The roundtrip looses data when private keys are used.
// See https://github.com/stackabletech/issues/issues/849 for details.
#[versioned(changed(
since = "v1alpha2",
in = "v1alpha2",
previous_name = "credentials_secret",
previous_type = "Option<String>",
upgrade_with = credentials_secret_to_basic_auth,
Expand Down
77 changes: 41 additions & 36 deletions crates/stackable-versioned-macros/src/attrs/item/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,27 @@ impl CommonItemAttributes {
let mut errors = Error::accumulator();

if let Some(added) = &self.added
&& !versions.iter().any(|v| v.inner == *added.since)
&& !versions.iter().any(|v| v.inner == *added.version)
{
errors.push(Error::custom(
"the `added` action uses a version which is not declared via `#[versioned(version)]`",
).with_span(&added.since.span()));
).with_span(&added.version.span()));
}

for change in &self.changes {
if !versions.iter().any(|v| v.inner == *change.since) {
if !versions.iter().any(|v| v.inner == *change.version) {
errors.push(Error::custom(
"the `changed` action uses a version which is not declared via `#[versioned(version)]`"
).with_span(&change.since.span()));
).with_span(&change.version.span()));
}
}

if let Some(deprecated) = &self.deprecated
&& !versions.iter().any(|v| v.inner == *deprecated.since)
&& !versions.iter().any(|v| v.inner == *deprecated.version)
{
errors.push(Error::custom(
"the `deprecated` action uses a version which is not declared via `#[versioned(version)]`",
).with_span(&deprecated.since.span()));
).with_span(&deprecated.version.span()));
}

errors.finish()
Expand All @@ -108,16 +108,18 @@ impl CommonItemAttributes {
/// rules from above apply here as well.
fn validate_action_combinations(&self, item_idents: &impl ItemIdents) -> Result<()> {
match (&self.added, &self.changes, &self.deprecated) {
(Some(added), _, Some(deprecated)) if *added.since == *deprecated.since => Err(
(Some(added), _, Some(deprecated)) if *added.version == *deprecated.version => Err(
Error::custom("cannot be marked as `added` and `deprecated` in the same version")
.with_span(item_idents.original()),
),
(Some(added), changed, _) if changed.iter().any(|r| *r.since == *added.since) => Err(
Error::custom("cannot be marked as `added` and `changed` in the same version")
.with_span(item_idents.original()),
),
(Some(added), changed, _) if changed.iter().any(|r| *r.version == *added.version) => {
Err(
Error::custom("cannot be marked as `added` and `changed` in the same version")
.with_span(item_idents.original()),
)
}
(_, changed, Some(deprecated))
if changed.iter().any(|r| *r.since == *deprecated.since) =>
if changed.iter().any(|r| *r.version == *deprecated.version) =>
{
Err(Error::custom(
"cannot be marked as `deprecated` and `changed` in the same version",
Expand All @@ -141,8 +143,8 @@ impl CommonItemAttributes {
/// - All `changed` actions must use a greater version than `added` but a
/// lesser version than `deprecated`.
fn validate_action_order(&self, item_idents: &impl ItemIdents) -> Result<()> {
let added_version = self.added.as_ref().map(|a| *a.since);
let deprecated_version = self.deprecated.as_ref().map(|d| *d.since);
let added_version = self.added.as_ref().map(|a| *a.version);
let deprecated_version = self.deprecated.as_ref().map(|d| *d.version);

// First, validate that the added version is less than the deprecated
// version.
Expand All @@ -158,8 +160,8 @@ impl CommonItemAttributes {
// Now, iterate over all changes and ensure that their versions are
// between the added and deprecated version.
if !self.changes.iter().all(|r| {
added_version.is_none_or(|a| a < *r.since)
&& deprecated_version.is_none_or(|d| d > *r.since)
added_version.is_none_or(|a| a < *r.version)
&& deprecated_version.is_none_or(|d| d > *r.version)
}) {
return Err(Error::custom(
"all changes must use versions higher than `added` and lower than `deprecated`",
Expand Down Expand Up @@ -229,7 +231,7 @@ impl CommonItemAttributes {
{
errors.push(Error::custom(
"`previous_name`, `previous_type` and `previous_docs` are unset. Is this `changed()` action needed?"
).with_span(&change.since.span()));
).with_span(&change.version.span()));
}

// This ensures that `previous_name` doesn't include the deprecation prefix.
Expand Down Expand Up @@ -306,7 +308,7 @@ impl CommonItemAttributes {
.iter()
.filter_map(|change| {
let docs = change.previous_docs.as_deref()?;
Some((*change.since, docs.into_doc_comments()))
Some((*change.version, docs.into_doc_comments()))
})
.collect()
}
Expand All @@ -330,7 +332,7 @@ impl CommonItemAttributes {
let mut actions = BTreeMap::new();

actions.insert(
*deprecated.since,
*deprecated.version,
ItemStatus::Deprecation {
previous_ident: ident.clone(),
ident: deprecated_ident.clone(),
Expand All @@ -353,7 +355,7 @@ impl CommonItemAttributes {
.map_or_else(|| ty.clone(), |sv| sv.deref().clone());

actions.insert(
*change.since,
*change.version,
ItemStatus::Change {
downgrade_with: change.downgrade_with.as_deref().cloned(),
upgrade_with: change.upgrade_with.as_deref().cloned(),
Expand All @@ -372,7 +374,7 @@ impl CommonItemAttributes {
// added action if there is any.
if let Some(added) = self.added {
actions.insert(
*added.since,
*added.version,
ItemStatus::Addition {
default_fn: added.default_fn.deref().clone(),
ident,
Expand Down Expand Up @@ -403,7 +405,7 @@ impl CommonItemAttributes {
.map_or_else(|| ty.clone(), |sv| sv.deref().clone());

actions.insert(
*change.since,
*change.version,
ItemStatus::Change {
downgrade_with: change.downgrade_with.as_deref().cloned(),
upgrade_with: change.upgrade_with.as_deref().cloned(),
Expand All @@ -422,7 +424,7 @@ impl CommonItemAttributes {
// added action if there is any.
if let Some(added) = self.added {
actions.insert(
*added.since,
*added.version,
ItemStatus::Addition {
default_fn: added.default_fn.deref().clone(),
ident,
Expand All @@ -437,7 +439,7 @@ impl CommonItemAttributes {
let mut actions = BTreeMap::new();

actions.insert(
*added.since,
*added.version,
ItemStatus::Addition {
default_fn: added.default_fn.deref().clone(),
ident: idents.original().clone(),
Expand All @@ -456,11 +458,12 @@ impl CommonItemAttributes {
/// For the added() action
///
/// Example usage:
/// - `added(since = "...")`
/// - `added(since = "...", default_fn = "custom_fn")`
/// - `added(in = "...")`
/// - `added(in = "...", default_fn = "custom_fn")`
#[derive(Clone, Debug, FromMeta)]
pub struct AddedAttributes {
pub since: SpannedValue<Version>,
#[darling(rename = "in")]
pub version: SpannedValue<Version>,

#[darling(rename = "default", default = "default_default_fn")]
pub default_fn: SpannedValue<Path>,
Expand All @@ -477,14 +480,15 @@ fn default_default_fn() -> SpannedValue<Path> {
/// For the changed() action
///
/// Example usage:
/// - `changed(since = "...", previous_name = "...")`
/// - `changed(since = "...", previous_name = "...", previous_type="...")`
/// - `changed(since = "...", previous_name = "...", previous_type="...", upgrade_with = "...")`
/// - `changed(since = "...", previous_name = "...", previous_type="...", downgrade_with = "...")`
/// - `changed(since = "...", previous_docs = "...")`
/// - `changed(in = "...", previous_name = "...")`
/// - `changed(in = "...", previous_name = "...", previous_type="...")`
/// - `changed(in = "...", previous_name = "...", previous_type="...", upgrade_with = "...")`
/// - `changed(in = "...", previous_name = "...", previous_type="...", downgrade_with = "...")`
/// - `changed(in = "...", previous_docs = "...")`
#[derive(Clone, Debug, FromMeta)]
pub struct ChangedAttributes {
pub since: SpannedValue<Version>,
#[darling(rename = "in")]
pub version: SpannedValue<Version>,
pub previous_name: Option<SpannedValue<String>>,
pub previous_type: Option<SpannedValue<Type>>,
pub previous_docs: Option<SpannedValue<String>>,
Expand All @@ -495,10 +499,11 @@ pub struct ChangedAttributes {
/// For the deprecated() action
///
/// Example usage:
/// - `deprecated(since = "...")`
/// - `deprecated(since = "...", note = "...")`
/// - `deprecated(in = "...")`
/// - `deprecated(in = "...", note = "...")`
#[derive(Clone, Debug, FromMeta)]
pub struct DeprecatedAttributes {
pub since: SpannedValue<Version>,
#[darling(rename = "in")]
pub version: SpannedValue<Version>,
pub note: Option<SpannedValue<String>>,
}
32 changes: 16 additions & 16 deletions crates/stackable-versioned-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ mod utils;
/// ))]
/// # #[derive(Clone, Debug, Deserialize, Serialize, CustomResource, JsonSchema)]
/// pub struct FooSpec {
/// #[versioned(deprecated(since = "v1beta1"))]
/// #[versioned(deprecated(in = "v1beta1"))]
/// deprecated_bar: usize,
/// baz: bool,
/// }
Expand Down Expand Up @@ -393,7 +393,7 @@ mod utils;
/// This action indicates that an item is added in a particular version.
/// Available arguments are:
///
/// - `since` to indicate since which version the item is present.
/// - `in` to indicate in which version the item was added.
/// - `default` to customize the default function used to populate the item
/// in auto-generated conversion implementations.
///
Expand All @@ -402,7 +402,7 @@ mod utils;
/// #[versioned(version(name = "v1alpha1"), version(name = "v1beta1"))]
/// mod versioned {
/// pub struct Foo {
/// #[versioned(added(since = "v1beta1"))]
/// #[versioned(added(in = "v1beta1"))]
/// bar: usize,
/// baz: bool,
/// }
Expand Down Expand Up @@ -457,7 +457,7 @@ mod utils;
/// #[versioned(version(name = "v1alpha1"), version(name = "v1beta1"))]
/// mod versioned {
/// pub struct Foo {
/// #[versioned(added(since = "v1beta1", default = "default_bar"))]
/// #[versioned(added(in = "v1beta1", default = "default_bar"))]
/// bar: usize,
/// baz: bool,
/// }
Expand Down Expand Up @@ -498,7 +498,7 @@ mod utils;
/// You can choose to change the name, change the type, change the doc comment
/// or combine multiple changes. Available arguments are:
///
/// - `since` to indicate since which version the item is changed.
/// - `in` to indicate in which version the item is changed.
/// - `previous_name` to declare the previous name of the field.
/// - `previous_type` to declare the previous type of the field.
/// - `previous_docs` to declare the previous doc comments of the item.
Expand All @@ -516,7 +516,7 @@ mod utils;
/// mod versioned {
/// pub struct Foo {
/// #[versioned(changed(
/// since = "v1beta1",
/// in = "v1beta1",
/// previous_name = "prev_bar",
/// previous_type = "u16",
/// downgrade_with = usize_to_u16
Expand Down Expand Up @@ -581,7 +581,7 @@ mod utils;
/// mod versioned {
/// pub struct Foo {
/// /// The number of bars.
/// #[versioned(changed(since = "v1beta1", previous_docs = "The bar."))]
/// #[versioned(changed(in = "v1beta1", previous_docs = "The bar."))]
/// bar: usize,
/// baz: bool,
/// }
Expand Down Expand Up @@ -621,18 +621,18 @@ mod utils;
///
/// ### Deprecated Action
///
/// This action indicates that an item is deprecated in a particular version.
/// This action indicates that an item was deprecated in a particular version.
/// Deprecated items are not removed. Available arguments are:
///
/// - `since` to indicate since which version the item is deprecated.
/// - `in` to indicate in which version the item was deprecated.
/// - `note` to specify an optional deprecation note.
///
/// ```
/// # use stackable_versioned_macros::versioned;
/// #[versioned(version(name = "v1alpha1"), version(name = "v1beta1"))]
/// mod versioned {
/// pub struct Foo {
/// #[versioned(deprecated(since = "v1beta1"))]
/// #[versioned(deprecated(in = "v1beta1"))]
/// deprecated_bar: usize,
/// baz: bool,
/// }
Expand Down Expand Up @@ -705,7 +705,7 @@ mod utils;
/// #[versioned(version(name = "v1alpha1"), version(name = "v1beta1"))]
/// mod versioned {
/// pub struct Foo {
/// #[versioned(changed(since = "v1beta1", previous_type = "Vec<usize>"), hint(vec))]
/// #[versioned(changed(in = "v1beta1", previous_type = "Vec<usize>"), hint(vec))]
/// bar: Vec<usize>,
/// baz: bool,
/// }
Expand Down Expand Up @@ -747,7 +747,7 @@ mod utils;
/// #[versioned(crd(group = "example.com", doc = "My custom resource."))]
/// #[derive(Clone, Debug, Deserialize, Serialize, CustomResource, JsonSchema)]
/// pub struct FooSpec {
/// #[versioned(added(since = "v1beta1"))]
/// #[versioned(added(in = "v1beta1"))]
/// bar: usize,
/// baz: bool,
/// }
Expand Down Expand Up @@ -818,10 +818,10 @@ mod utils;
/// #[versioned(crd(group = "example.com", doc = "My custom resource."))]
/// #[derive(Clone, Debug, Deserialize, Serialize, CustomResource, JsonSchema)]
/// pub struct FooSpec {
/// #[versioned(added(since = "v1beta1"))]
/// #[versioned(added(in = "v1beta1"))]
/// bar: usize,
///
/// #[versioned(added(since = "v1"))]
/// #[versioned(added(in = "v1"))]
/// baz: bool,
///
/// quox: String,
Expand Down Expand Up @@ -966,7 +966,7 @@ mod utils;
/// struct Baz {
/// quax: String,
///
/// #[versioned(added(since = "v1beta1"))]
/// #[versioned(added(in = "v1beta1"))]
/// quox: bool,
/// }
/// }
Expand Down Expand Up @@ -1009,7 +1009,7 @@ mod utils;
/// struct Baz {
/// quax: String,
///
/// #[versioned(added(since = "v1beta1"))]
/// #[versioned(added(in = "v1beta1"))]
/// quox: bool,
/// }
/// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use stackable_versioned_macros::versioned;
mod versioned {
struct Foo {
#[versioned(
changed(since = "v1beta1", previous_name = "deprecated_bar"),
changed(since = "v1", previous_name = "deprecated_baz"),
changed(since = "v2")
changed(in = "v1beta1", previous_name = "deprecated_bar"),
changed(in = "v1", previous_name = "deprecated_baz"),
changed(in = "v2")
)]
bar: usize,
}
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ mod versioned {
#[versioned(crd(group = "stackable.tech", doc = "Test"))]
pub struct Foo {
#[versioned(
added(since = "v1beta1"),
changed(since = "v1", previous_name = "bah", previous_type = "u16")
added(in = "v1beta1"),
changed(in = "v1", previous_name = "bah", previous_type = "u16")
)]
bar: usize,
baz: bool,
Expand Down
Loading
Loading