Skip to content

Commit cd1e4a7

Browse files
committed
chore(stackable-versioned): Allow overriding the k8s_openapi crate
1 parent bc13fb3 commit cd1e4a7

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

crates/stackable-versioned-macros/src/attrs/k8s.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ pub(crate) struct KubernetesSkipArguments {
5959
/// This struct contains crate overrides to be passed to `#[kube]`.
6060
#[derive(Clone, Debug, FromMeta)]
6161
pub(crate) struct KubernetesCrateArguments {
62-
kube_core: Option<Path>,
63-
k8s_openapi: Option<Path>,
64-
schemars: Option<Path>,
65-
serde: Option<Path>,
66-
serde_json: Option<Path>,
62+
pub(crate) kube_core: Option<Path>,
63+
pub(crate) k8s_openapi: Option<Path>,
64+
pub(crate) schemars: Option<Path>,
65+
pub(crate) serde: Option<Path>,
66+
pub(crate) serde_json: Option<Path>,
6767
}
6868

6969
impl ToTokens for KubernetesCrateArguments {

crates/stackable-versioned-macros/src/codegen/container/struct.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::ops::Not;
22

3-
use darling::{util::IdentString, Error, FromAttributes, Result};
3+
use darling::{util::IdentString, Error, FromAttributes, FromMeta, Result};
44
use proc_macro2::TokenStream;
55
use quote::{quote, ToTokens};
66
use syn::{parse_quote, ItemStruct, Path};
@@ -342,6 +342,19 @@ impl Struct {
342342
// module (in standalone mode).
343343
let automatically_derived = is_nested.not().then(|| quote! {#[automatically_derived]});
344344

345+
let k8s_openapi_crate_default = &Path::from_string("::k8s_openapi").expect("valid path");
346+
let k8s_openapi_crate = self.common.options.kubernetes_options.as_ref().map_or_else(
347+
|| quote! {#k8s_openapi_crate_default},
348+
|options| {
349+
if let Some(crates) = &options.crates {
350+
if let Some(k8s_openapi) = &crates.k8s_openapi {
351+
return quote! {#k8s_openapi};
352+
}
353+
}
354+
quote! {#k8s_openapi_crate_default}
355+
},
356+
);
357+
345358
// TODO (@Techassi): Use proper visibility instead of hard-coding 'pub'
346359
// TODO (@Techassi): Move the YAML printing code into 'stackable-versioned' so that we don't
347360
// have any cross-dependencies and the macro can be used on it's own (K8s features of course
@@ -366,7 +379,7 @@ impl Struct {
366379
/// Generates a merged CRD which contains all versions defined using the `#[versioned()]` macro.
367380
pub fn merged_crd(
368381
stored_apiversion: Self
369-
) -> ::std::result::Result<::k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition, ::kube::core::crd::MergeError> {
382+
) -> ::std::result::Result<#k8s_openapi_crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition, ::kube::core::crd::MergeError> {
370383
::kube::core::crd::merge_crds(vec![#(#fn_calls),*], &stored_apiversion.to_string())
371384
}
372385

0 commit comments

Comments
 (0)