Skip to content

Commit a86bf17

Browse files
committed
refactor(stackable-versioned): Remove standalone and non-K8s specific code
1 parent 0f1e0a5 commit a86bf17

File tree

18 files changed

+802
-1807
lines changed

18 files changed

+802
-1807
lines changed

crates/stackable-operator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ versioned = []
1616

1717
[dependencies]
1818
stackable-telemetry = { path = "../stackable-telemetry", features = ["clap"] }
19-
stackable-versioned = { path = "../stackable-versioned", features = ["k8s"] }
2019
stackable-operator-derive = { path = "../stackable-operator-derive" }
20+
stackable-versioned = { path = "../stackable-versioned" }
2121
stackable-shared = { path = "../stackable-shared" }
2222

2323
chrono.workspace = true

crates/stackable-versioned-macros/Cargo.toml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,22 @@ normal = ["k8s-openapi", "kube"]
2424
[lib]
2525
proc-macro = true
2626

27-
[features]
28-
full = ["k8s"]
29-
k8s = ["dep:kube", "dep:k8s-openapi"]
30-
3127
[dependencies]
3228
k8s-version = { path = "../k8s-version", features = ["darling"] }
3329

3430
convert_case.workspace = true
3531
darling.workspace = true
3632
indoc.workspace = true
3733
itertools.workspace = true
38-
k8s-openapi = { workspace = true, optional = true }
39-
kube = { workspace = true, optional = true }
34+
k8s-openapi.workspace = true
35+
kube.workspace = true
4036
proc-macro2.workspace = true
4137
syn.workspace = true
4238
quote.workspace = true
4339

4440
[dev-dependencies]
4541
# Only needed for doc tests / examples
46-
stackable-versioned = { path = "../stackable-versioned", features = ["k8s"] }
42+
stackable-versioned = { path = "../stackable-versioned" }
4743

4844
insta.workspace = true
4945
prettyplease.workspace = true

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

Lines changed: 0 additions & 127 deletions
This file was deleted.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
use darling::{Error, FromAttributes, FromMeta, Result, util::Flag};
2+
use syn::Path;
3+
4+
#[derive(Debug, FromAttributes)]
5+
#[darling(attributes(versioned), and_then = ContainerAttributes::validate)]
6+
pub struct ContainerAttributes {
7+
#[darling(rename = "crd")]
8+
pub crd_arguments: Option<StructCrdArguments>,
9+
10+
#[darling(default)]
11+
pub skip: ContainerSkipArguments,
12+
}
13+
14+
impl ContainerAttributes {
15+
fn validate(self) -> Result<Self> {
16+
if self.crd_arguments.is_some()
17+
&& (self.skip.object_from.is_present()
18+
|| self.skip.merged_crd.is_present()
19+
|| self.skip.try_convert.is_present())
20+
{
21+
return Err(Error::custom("spec sub structs can only use skip(from)"));
22+
}
23+
24+
Ok(self)
25+
}
26+
}
27+
28+
#[derive(Debug, Default, FromMeta)]
29+
pub struct ContainerSkipArguments {
30+
pub from: Flag,
31+
pub object_from: Flag,
32+
pub merged_crd: Flag,
33+
pub try_convert: Flag,
34+
}
35+
36+
/// This struct contains supported CRD arguments.
37+
///
38+
/// The arguments are passed through to the `#[kube]` attribute. More details can be found in the
39+
/// official docs: <https://docs.rs/kube/latest/kube/derive.CustomResource.html>.
40+
///
41+
/// Supported arguments are:
42+
///
43+
/// - `group`: Set the group of the CR object, usually the domain of the company.
44+
/// This argument is Required.
45+
/// - `kind`: Override the kind field of the CR object. This defaults to the struct
46+
/// name (without the 'Spec' suffix).
47+
/// - `singular`: Set the singular name of the CR object.
48+
/// - `plural`: Set the plural name of the CR object.
49+
/// - `namespaced`: Indicate that this is a namespaced scoped resource rather than a
50+
/// cluster scoped resource.
51+
/// - `crates`: Override specific crates.
52+
/// - `status`: Set the specified struct as the status subresource.
53+
/// - `shortname`: Set a shortname for the CR object. This can be specified multiple
54+
/// times.
55+
/// - `skip`: Controls skipping parts of the generation.
56+
#[derive(Clone, Debug, FromMeta)]
57+
pub struct StructCrdArguments {
58+
pub group: String,
59+
pub kind: Option<String>,
60+
pub singular: Option<String>,
61+
pub plural: Option<String>,
62+
pub namespaced: Flag,
63+
// root
64+
pub status: Option<Path>,
65+
// derive
66+
// schema
67+
// scale
68+
// printcolumn
69+
#[darling(multiple, rename = "shortname")]
70+
pub shortnames: Vec<String>,
71+
// category
72+
// selectable
73+
// doc
74+
// annotation
75+
// label
76+
}

0 commit comments

Comments
 (0)