-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathmod.rs
More file actions
86 lines (71 loc) · 2.74 KB
/
Copy pathmod.rs
File metadata and controls
86 lines (71 loc) · 2.74 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
use std::path::PathBuf;
use paste::paste;
use snafu::{OptionExt, ResultExt, Snafu};
use stackable_operator::{
crd::{
authentication::core::{AuthenticationClass, AuthenticationClassVersion},
listener::{
Listener, ListenerClass, ListenerClassVersion, ListenerVersion, PodListeners,
PodListenersVersion,
},
s3::{S3Bucket, S3BucketVersion, S3Connection, S3ConnectionVersion},
scaler::{Scaler, ScalerVersion},
},
kube::core::crd::MergeError,
};
use crate::crd::dummy::{DummyCluster, DummyClusterVersion};
mod dummy;
#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("failed to get manifest directory"))]
GetManifestDirectory { source: std::env::VarError },
#[snafu(display("failed to get parent directory of {path}", path = path.display()))]
GetParentDirectory { path: PathBuf },
#[snafu(display("failed to merge {crd_name:?} CRD"))]
MergeCrd {
source: MergeError,
crd_name: String,
},
#[snafu(display("failed to write CRD to file at {path}", path = path.display()))]
WriteCrd {
source: stackable_operator::shared::yaml::Error,
path: PathBuf,
},
}
macro_rules! write_crd {
($base_path:expr, $crd_name:ident, $stored_crd_version:ident) => {
paste! {
let merged = $crd_name::merged_crd([<$crd_name Version>]::$stored_crd_version)
.context(MergeCrdSnafu { crd_name: stringify!($crd_name) })?;
let mut path = $base_path.join(stringify!($crd_name));
path.set_extension("yaml");
<stackable_operator::k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition
as stackable_operator::YamlSchema>
::write_yaml_schema(
&merged,
&path,
"0.0.0-dev",
stackable_operator::shared::yaml::SerializeOptions::default(),
)
.with_context(|_| WriteCrdSnafu { path: path.clone() })?;
}
};
}
pub fn generate_preview() -> Result<(), Error> {
let path = std::env::var("CARGO_MANIFEST_DIR")
.map(PathBuf::from)
.context(GetManifestDirectorySnafu)?;
let path = path
.parent()
.with_context(|| GetParentDirectorySnafu { path: path.clone() })?
.join("stackable-operator/crds");
write_crd!(path, AuthenticationClass, V1Alpha1);
write_crd!(path, Listener, V1Alpha1);
write_crd!(path, ListenerClass, V1Alpha1);
write_crd!(path, PodListeners, V1Alpha1);
write_crd!(path, S3Bucket, V1Alpha1);
write_crd!(path, S3Connection, V1Alpha1);
write_crd!(path, Scaler, V1Alpha1);
write_crd!(path, DummyCluster, V1Alpha1);
Ok(())
}