-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcontainer.rs
More file actions
95 lines (87 loc) · 3.11 KB
/
container.rs
File metadata and controls
95 lines (87 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use darling::{Error, FromAttributes, FromMeta, Result, util::Flag};
use syn::Path;
#[derive(Debug, FromAttributes)]
#[darling(attributes(versioned), and_then = ContainerAttributes::validate)]
pub struct ContainerAttributes {
#[darling(rename = "crd")]
pub crd_arguments: Option<StructCrdArguments>,
#[darling(default)]
pub skip: ContainerSkipArguments,
}
impl ContainerAttributes {
fn validate(self) -> Result<Self> {
if self.crd_arguments.is_none()
&& (self.skip.object_from.is_present()
|| self.skip.merged_crd.is_present()
|| self.skip.try_convert.is_present())
{
return Err(Error::custom("spec sub structs can only use skip(from)"));
}
Ok(self)
}
}
#[derive(Debug, Default, FromMeta)]
pub struct ContainerSkipArguments {
pub from: Flag,
pub object_from: Flag,
pub merged_crd: Flag,
pub try_convert: Flag,
}
/// This struct contains supported CRD arguments.
///
/// The arguments are passed through to the `#[kube]` attribute. More details can be found in the
/// official docs: <https://docs.rs/kube/latest/kube/derive.CustomResource.html>.
///
/// Supported arguments are:
///
/// - `group`: Set the group of the CR object, usually the domain of the company.
/// This argument is Required.
/// - `kind`: Override the kind field of the CR object. This defaults to the struct
/// name (without the 'Spec' suffix).
/// - `singular`: Set the singular name of the CR object.
/// - `plural`: Set the plural name of the CR object.
/// - `namespaced`: Indicate that this is a namespaced scoped resource rather than a
/// cluster scoped resource.
/// - `crates`: Override specific crates.
/// - `status`: Set the specified struct as the status subresource.
/// - `scale`: Configure the scale subresource for horizontal pod autoscaling integration.
/// - `shortname`: Set a shortname for the CR object. This can be specified multiple
/// times.
/// - `skip`: Controls skipping parts of the generation.
#[derive(Clone, Debug, FromMeta)]
pub struct StructCrdArguments {
pub group: String,
pub kind: Option<String>,
pub singular: Option<String>,
pub plural: Option<String>,
pub namespaced: Flag,
// root
pub status: Option<Path>,
// derive
// schema
pub scale: Option<Scale>,
// printcolumn
#[darling(multiple, rename = "shortname")]
pub shortnames: Vec<String>,
// category
// selectable
// doc
// annotation
// label
}
/// Scale subresource configuration for a CRD.
///
/// Mirrors the fields of [`k8s_openapi::CustomResourceSubresourceScale`][1] and what is present in
/// `kube_derive`.
///
/// [1]: k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceSubresourceScale
//
// TODO (@Techassi): This should eventually get replaced by directly using what `kube_derive` offers,
// but that requires an upstream restructure I'm planning to do soon(ish).
#[derive(Clone, Debug, FromMeta)]
pub struct Scale {
pub spec_replicas_path: String,
pub status_replicas_path: String,
#[darling(default)]
pub label_selector_path: Option<String>,
}