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
@@ -0,0 +1,24 @@
#[versioned(
version(name = "v1alpha1"),
version(name = "v1beta1"),
version(name = "v1"),
k8s(
group = "stackable.tech",
kind = "FooBar",
singular = "foo",
plural = "foos",
namespaced,
)
)]
// ---
#[derive(
Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema, kube::CustomResource,
)]
pub struct FooSpec {
#[versioned(
added(since = "v1beta1"),
changed(since = "v1", from_name = "bah", from_type = "u16")
)]
bar: usize,
baz: bool,
}

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 @@ -37,7 +37,7 @@ impl Container {
.map_or(false, |s| s.from.is_present()),
};

let idents: ContainerIdents = item_enum.ident.into();
let idents = ContainerIdents::from(item_enum.ident, None);

let common = CommonContainerData {
original_attributes: item_enum.attrs,
Expand Down Expand Up @@ -73,7 +73,7 @@ impl Container {
.map_or(false, |s| s.from.is_present()),
};

let idents: ContainerIdents = item_enum.ident.into();
let idents = ContainerIdents::from(item_enum.ident, None);

let common = CommonContainerData {
original_attributes: item_enum.attrs,
Expand Down
18 changes: 14 additions & 4 deletions crates/stackable-versioned-macros/src/codegen/container/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ops::Deref;

use darling::{util::IdentString, Result};
use proc_macro2::TokenStream;
use proc_macro2::{Span, TokenStream};
use quote::{quote, ToTokens};
use syn::{parse_quote, Attribute, Ident, ItemEnum, ItemStruct, Path, Visibility};

Expand Down Expand Up @@ -237,12 +237,22 @@ pub(crate) struct ContainerIdents {
pub(crate) from: IdentString,
}

impl From<Ident> for ContainerIdents {
fn from(ident: Ident) -> Self {
impl ContainerIdents {
pub(crate) fn from(ident: Ident, kubernetes_options: Option<&KubernetesOptions>) -> Self {
let kubernetes = kubernetes_options.map_or_else(
|| ident.as_cleaned_kubernetes_ident(),
|options| {
options.kind.as_ref().map_or_else(
|| ident.as_cleaned_kubernetes_ident(),
|kind| IdentString::from(Ident::new(kind, Span::call_site())),
)
},
);

Self {
kubernetes: ident.as_cleaned_kubernetes_ident(),
from: ident.as_from_impl_ident(),
original: ident.into(),
kubernetes,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Container {
}

let kubernetes_options = attributes.kubernetes_arguments.map(Into::into);
let idents: ContainerIdents = item_struct.ident.into();
let idents = ContainerIdents::from(item_struct.ident, kubernetes_options.as_ref());

// Validate K8s specific requirements
// Ensure that the struct name includes the 'Spec' suffix.
Expand Down Expand Up @@ -78,7 +78,7 @@ impl Container {
}

let kubernetes_options = attributes.kubernetes_arguments.map(Into::into);
let idents: ContainerIdents = item_struct.ident.into();
let idents = ContainerIdents::from(item_struct.ident, kubernetes_options.as_ref());

// Validate K8s specific requirements
// Ensure that the struct name includes the 'Spec' suffix.
Expand Down
2 changes: 2 additions & 0 deletions crates/stackable-versioned/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ All notable changes to this project will be documented in this file.

### Fixed

- Emit correct enum ident based on kube/k8s kind argument ([#920]).
- Generate Kubernetes code independent of container order ([#913]).
- Correctly emit Kubernetes code when macro is used on modules ([#912]).

Expand All @@ -31,6 +32,7 @@ All notable changes to this project will be documented in this file.
[#913]: https://github.com/stackabletech/operator-rs/pull/913
[#914]: https://github.com/stackabletech/operator-rs/pull/914
[#919]: https://github.com/stackabletech/operator-rs/pull/919
[#920]: https://github.com/stackabletech/operator-rs/pull/920

## [0.4.1] - 2024-10-23

Expand Down
Loading