Skip to content

Commit

Permalink
feat(stackable-versioned): Support visibility for CRD enum (#923)
Browse files Browse the repository at this point in the history
* feat(stackable-versioned): Support visibility for CRD enum

* chore(stackable-versioned): Update changelog
  • Loading branch information
Techassi authored Nov 29, 2024
1 parent 2512a17 commit 5dcb07b
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#[derive(
Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema, kube::CustomResource,
)]
pub struct FooSpec {
pub(crate) struct FooSpec {
#[versioned(
added(since = "v1beta1"),
changed(since = "v1", from_name = "bah", from_type = "u16")
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.

Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ impl Container {
enum_variant_idents: &[IdentString],
enum_variant_strings: &[String],
fn_calls: &[TokenStream],
vis: &Visibility,
is_nested: bool,
) -> Option<TokenStream> {
match self {
Container::Struct(s) => s.generate_kubernetes_merge_crds(
enum_variant_idents,
enum_variant_strings,
fn_calls,
vis,
is_nested,
),
Container::Enum(_) => None,
Expand Down Expand Up @@ -216,6 +218,7 @@ impl StandaloneContainer {
&kubernetes_enum_variant_idents,
&kubernetes_enum_variant_strings,
&kubernetes_merge_crds_fn_calls,
vis,
false,
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ops::Not;
use darling::{util::IdentString, Error, FromAttributes, Result};
use proc_macro2::TokenStream;
use quote::{quote, ToTokens};
use syn::{parse_quote, ItemStruct, Path};
use syn::{parse_quote, ItemStruct, Path, Visibility};

use crate::{
attrs::container::NestedContainerAttributes,
Expand Down Expand Up @@ -332,6 +332,7 @@ impl Struct {
enum_variant_idents: &[IdentString],
enum_variant_strings: &[String],
fn_calls: &[TokenStream],
vis: &Visibility,
is_nested: bool,
) -> Option<TokenStream> {
match &self.common.options.kubernetes_options {
Expand All @@ -347,13 +348,12 @@ impl Struct {
let k8s_openapi_path = &*kubernetes_options.crates.k8s_openapi;
let kube_core_path = &*kubernetes_options.crates.kube_core;

// TODO (@Techassi): Use proper visibility instead of hard-coding 'pub'
// TODO (@Techassi): Move the YAML printing code into 'stackable-versioned' so that we don't
// have any cross-dependencies and the macro can be used on it's own (K8s features of course
// still need kube and friends).
Some(quote! {
#automatically_derived
pub enum #enum_ident {
#vis enum #enum_ident {
#(#enum_variant_idents),*
}

Expand All @@ -368,7 +368,7 @@ impl Struct {

#automatically_derived
impl #enum_ident {
/// Generates a merged CRD which contains all versions defined using the `#[versioned()]` macro.
/// Generates a merged CRD containing all versions and marking `stored_apiversion` as stored.
pub fn merged_crd(
stored_apiversion: Self
) -> ::std::result::Result<#k8s_openapi_path::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition, #kube_core_path::crd::MergeError> {
Expand Down
1 change: 1 addition & 0 deletions crates/stackable-versioned-macros/src/codegen/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ impl Module {
kubernetes_enum_variant_idents,
kubernetes_enum_variant_strings,
kubernetes_merge_crds_fn_calls,
version_module_vis,
self.preserve_module,
));
}
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 @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.

### Added

- Use visibility of container definition or module for generated CRD enum ([#923]).
- Add support to apply the `#[versioned()]` macro to modules to version all contained items at
once ([#891]).
- Add support for passing a `status`, `crates`, and `shortname` arguments through to the `#[kube]`
Expand Down Expand Up @@ -35,6 +36,7 @@ All notable changes to this project will be documented in this file.
[#919]: https://github.com/stackabletech/operator-rs/pull/919
[#920]: https://github.com/stackabletech/operator-rs/pull/920
[#922]: https://github.com/stackabletech/operator-rs/pull/922
[#923]: https://github.com/stackabletech/operator-rs/pull/923

## [0.4.1] - 2024-10-23

Expand Down

0 comments on commit 5dcb07b

Please sign in to comment.