Skip to content

Commit c9c2e29

Browse files
committed
patch deployment resources too
1 parent 9056ae4 commit c9c2e29

2 files changed

Lines changed: 16 additions & 34 deletions

File tree

rust/olm-deployer/src/data.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,5 @@
11
use stackable_operator::kube::{ResourceExt, api::DynamicObject};
22

3-
pub fn container<'a>(
4-
target: &'a mut DynamicObject,
5-
container_name: &str,
6-
) -> anyhow::Result<&'a mut serde_json::Value> {
7-
let tname = target.name_any();
8-
let path = "template/spec/containers".split("/");
9-
match get_or_create(target.data.pointer_mut("/spec").unwrap(), path)? {
10-
serde_json::Value::Array(containers) => {
11-
for c in containers {
12-
if c.is_object() {
13-
if let Some(serde_json::Value::String(name)) = c.get("name") {
14-
if container_name == name {
15-
return Ok(c);
16-
}
17-
}
18-
} else {
19-
anyhow::bail!("container is not a object: {:?}", c);
20-
}
21-
}
22-
anyhow::bail!("container named {container_name} not found");
23-
}
24-
_ => anyhow::bail!("no containers found in object {tname}"),
25-
}
26-
}
27-
283
pub fn containers<'a>(
294
target: &'a mut DynamicObject,
305
) -> anyhow::Result<&'a mut Vec<serde_json::Value>> {

rust/olm-deployer/src/resources/mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,28 @@ use stackable_operator::{
66
},
77
};
88

9-
use crate::data::container;
9+
use crate::data::containers;
1010

1111
/// Copies the resources of the container named "secret-operator-deployer" from `source`
12-
/// to the container "secret-operator" in `target`.
13-
/// Does nothing if there are no resources or if the `target` is not a DaemonSet.
12+
/// to *all* containers in `target`.
13+
/// Does nothing if there are no resources or if the `target` is not a DaemonSet or a Deployment.
14+
/// This function allows OLM Subscription objects to configure the resources
15+
/// of operator containers.
1416
pub(super) fn maybe_copy_resources(
1517
source: &Deployment,
1618
target: &mut DynamicObject,
1719
target_gvk: &GroupVersionKind,
1820
) -> anyhow::Result<()> {
19-
if target_gvk.kind == "DaemonSet" {
21+
let target_kind_set = ["DaemonSet", "Deployment"];
22+
if target_kind_set.contains(&target_gvk.kind.as_str()) {
2023
if let Some(res) = deployment_resources(source) {
21-
match container(target, "secret-operator")? {
22-
serde_json::Value::Object(c) => {
23-
c.insert("resources".to_string(), serde_json::json!(res));
24+
for container in containers(target)? {
25+
match container {
26+
serde_json::Value::Object(c) => {
27+
c.insert("resources".to_string(), serde_json::json!(res));
28+
}
29+
_ => anyhow::bail!("no containers found in object {}", target.name_any()),
2430
}
25-
_ => anyhow::bail!("no containers found in object {}", target.name_any()),
2631
}
2732
}
2833
}
@@ -150,7 +155,9 @@ spec:
150155
..ResourceRequirements::default()
151156
});
152157
assert_eq!(
153-
container(&mut daemonset, "secret-operator")?
158+
containers(&mut daemonset)?
159+
.first()
160+
.expect("daemonset has no containers")
154161
.get("resources")
155162
.unwrap(),
156163
&expected

0 commit comments

Comments
 (0)