-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added olm-deployer crate. * Update changelog. * pass in deployer name * replace unwrap() calls with context() * regenerate-nix
- Loading branch information
Showing
12 changed files
with
1,122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "olm-deployer" | ||
description = "OLM deployment helper." | ||
version.workspace = true | ||
authors.workspace = true | ||
license.workspace = true | ||
edition.workspace = true | ||
repository.workspace = true | ||
publish = false | ||
|
||
[dependencies] | ||
anyhow.workspace = true | ||
clap.workspace = true | ||
tokio.workspace = true | ||
tracing.workspace = true | ||
stackable-operator.workspace = true | ||
serde.workspace = true | ||
serde_json.workspace = true | ||
serde_yaml.workspace = true | ||
walkdir.workspace = true | ||
|
||
[build-dependencies] | ||
built.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
built::write_built_file().unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use anyhow::{anyhow, Context}; | ||
use stackable_operator::kube::{api::DynamicObject, ResourceExt}; | ||
|
||
pub fn container<'a>( | ||
target: &'a mut DynamicObject, | ||
container_name: &str, | ||
) -> anyhow::Result<&'a mut serde_json::Value> { | ||
let tname = target.name_any(); | ||
let path = "template/spec/containers".split("/"); | ||
match get_or_create( | ||
target | ||
.data | ||
.pointer_mut("/spec") | ||
.context(anyhow!("object [{tname}] has no .spec property"))?, | ||
path, | ||
)? { | ||
serde_json::Value::Array(containers) => { | ||
for c in containers { | ||
if c.is_object() { | ||
if let Some(serde_json::Value::String(name)) = c.get("name") { | ||
if container_name == name { | ||
return Ok(c); | ||
} | ||
} | ||
} else { | ||
anyhow::bail!("container is not a object: {:?}", c); | ||
} | ||
} | ||
anyhow::bail!("container named {container_name} not found"); | ||
} | ||
_ => anyhow::bail!("no containers found in object {tname}"), | ||
} | ||
} | ||
|
||
/// Returns the object nested in `root` by traversing the `path` of nested keys. | ||
/// Creates any missing objects in path. | ||
/// In case of success, the returned value is either the existing object or | ||
/// serde_json::Value::Null. | ||
/// Returns an error if any of the nested objects has a type other than map. | ||
pub fn get_or_create<'a, 'b, I>( | ||
root: &'a mut serde_json::Value, | ||
path: I, | ||
) -> anyhow::Result<&'a mut serde_json::Value> | ||
where | ||
I: IntoIterator<Item = &'b str>, | ||
{ | ||
let mut iter = path.into_iter(); | ||
match iter.next() { | ||
None => Ok(root), | ||
Some(first) => { | ||
let new_root = get_or_insert_default_object(root, first)?; | ||
get_or_create(new_root, iter) | ||
} | ||
} | ||
} | ||
|
||
/// Given a map object create or return the object corresponding to the given `key`. | ||
fn get_or_insert_default_object<'a>( | ||
value: &'a mut serde_json::Value, | ||
key: &str, | ||
) -> anyhow::Result<&'a mut serde_json::Value> { | ||
let map = match value { | ||
serde_json::Value::Object(map) => map, | ||
x @ serde_json::Value::Null => { | ||
*x = serde_json::json!({}); | ||
x.as_object_mut() | ||
.context(anyhow!("expected an empty map for [{key}] but found null"))? | ||
} | ||
x => anyhow::bail!("invalid type {x:?}, expected map"), | ||
}; | ||
Ok(map.entry(key).or_insert_with(|| serde_json::Value::Null)) | ||
} |
Oops, something went wrong.