-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathcrd.rs
More file actions
39 lines (36 loc) · 1.37 KB
/
Copy pathcrd.rs
File metadata and controls
39 lines (36 loc) · 1.37 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
use k8s_openapi::DeepMerge;
use kube::api::DynamicObject;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize, de::DeserializeOwned};
use super::apply_deep_merge;
use crate::utils::crds::raw_object_list_schema;
#[derive(Clone, Debug, Deserialize, Default, JsonSchema, Serialize, PartialEq)]
pub struct ObjectOverrides(
/// A list of generic Kubernetes objects, which are merged on the objects that the operator
/// creates.
///
/// List entries are arbitrary YAML objects, which need to be valid Kubernetes objects.
///
/// Read the [Object overrides documentation](DOCS_BASE_URL_PLACEHOLDER/concepts/overrides#object-overrides)
/// for more information.
//
// Remember to use `#[serde(default)]` when including this into a CRD!
#[schemars(schema_with = "raw_object_list_schema")]
Vec<DynamicObject>,
);
impl ObjectOverrides {
/// Takes an arbitrary Kubernetes object (`base`) and applies the configured list of deep merges
/// to it.
///
/// Merges are only applied to objects that have the same apiVersion, kind, name
/// and namespace.
pub fn apply_to<R>(&self, base: &mut R) -> Result<(), super::Error>
where
R: kube::Resource<DynamicType = ()> + DeepMerge + DeserializeOwned,
{
for object_override in &self.0 {
apply_deep_merge(base, object_override)?;
}
Ok(())
}
}