Skip to content

Commit

Permalink
refactor(stackable-versioned): Simplify crate overrides (#919)
Browse files Browse the repository at this point in the history
* refactor(stackable-versioned): Simplify crate overrides

* chore(stackable-versioned): Update changelog

* Apply suggestions from code review

---------

Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com>
  • Loading branch information
Techassi and NickLarsenNZ authored Nov 28, 2024
1 parent 3790332 commit 59cb9d5
Show file tree
Hide file tree
Showing 9 changed files with 444 additions and 160 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#[versioned(
version(name = "v1alpha1"),
version(name = "v1beta1"),
version(name = "v1"),
k8s(
group = "foo.example.org",
singular = "foo",
plural = "foos",
namespaced,
crates(
kube_core = ::kube::core
)
)
)]
// ---
#[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.

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.

28 changes: 0 additions & 28 deletions crates/stackable-versioned-macros/src/attrs/k8s.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use darling::{util::Flag, FromMeta};
use proc_macro2::TokenStream;
use quote::{quote, ToTokens};
use syn::Path;

/// This struct contains supported Kubernetes arguments.
Expand Down Expand Up @@ -65,29 +63,3 @@ pub(crate) struct KubernetesCrateArguments {
pub(crate) serde: Option<Path>,
pub(crate) serde_json: Option<Path>,
}

impl ToTokens for KubernetesCrateArguments {
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
let mut crate_overrides = TokenStream::new();

if let Some(path) = &self.k8s_openapi {
crate_overrides.extend(quote! { k8s_openapi = #path, });
}
if let Some(path) = &self.kube_core {
crate_overrides.extend(quote! { kube_core = #path, });
}
if let Some(path) = &self.schemars {
crate_overrides.extend(quote! { schemars = #path, });
}
if let Some(path) = &self.serde {
crate_overrides.extend(quote! { serde = #path, });
}
if let Some(path) = &self.serde_json {
crate_overrides.extend(quote! { serde_json = #path, });
}

if !crate_overrides.is_empty() {
tokens.extend(quote! { , crates(#crate_overrides) });
}
}
}
Loading

0 comments on commit 59cb9d5

Please sign in to comment.