-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: olm deployment helper #546
base: main
Are you sure you want to change the base?
Changes from 31 commits
b0b0c79
fa11668
5b75e2a
bbe0762
31b0372
3a69789
0893d20
e92acd3
7729878
e7a156c
5a3302b
46996ab
acee691
a827fab
4693dfa
87cfab2
df3b6ab
5ea0b36
5736913
4d3b7e7
28a7f00
1f880c9
75d21e2
0e77dfd
1299ffd
790cf2c
c2778b7
850a0d0
99ec5fd
274f0a2
2c577ca
1519519
57b431e
70160ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: secret-operator-deployer | ||
labels: | ||
app: nginx | ||
spec: | ||
replicas: 3 | ||
selector: | ||
matchLabels: | ||
app: nginx | ||
template: | ||
metadata: | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx:1.14.2 | ||
ports: | ||
- containerPort: 80 | ||
tolerations: | ||
- key: keep-out | ||
value: "yes" | ||
operator: Equal | ||
effect: NoSchedule |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# How to test | ||
|
||
Requirements: | ||
|
||
1. An OpenShift cluster. | ||
2. Checkout the branch `secret-olm-deployer` from the [operators](https://github.com/stackabletech/openshift-certified-operators/tree/secret-olm-deployer) repo. | ||
3. Clone the `stackable-utils` [repo](https://github.com/stackabletech/stackable-utils) | ||
|
||
Install the secret operator using OLM and the `olm-deployer`. From the `stackable-utils` repo, run: | ||
|
||
```bash | ||
$ ./olm/build-bundles.sh -c $HOME/repo/stackable/openshift-certified-operators -r 24.11.0 -o secret -d | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as we are now pushing to OCI, it is necessary to login first with: |
||
... | ||
``` | ||
|
||
The secret op and all it's dependencies should be installed and running in the `stackable-operators` namespace. | ||
|
||
Run the integration tests: | ||
|
||
```bash | ||
$ ./scripts/run-tests --skip-operator secret --test-suite openshift | ||
... | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
built::write_built_file().unwrap(); | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,75 @@ | ||||||||||||||||||
use anyhow::{bail, Result}; | ||||||||||||||||||
use stackable_operator::kube::{api::DynamicObject, ResourceExt}; | ||||||||||||||||||
|
||||||||||||||||||
pub fn data_field_as_mut<'a>( | ||||||||||||||||||
value: &'a mut serde_json::Value, | ||||||||||||||||||
pointer: &str, | ||||||||||||||||||
) -> Result<&'a mut serde_json::Value> { | ||||||||||||||||||
match value.pointer_mut(pointer) { | ||||||||||||||||||
Some(field) => Ok(field), | ||||||||||||||||||
x => bail!("invalid pointer {pointer} for object {x:?}"), | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
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").unwrap(), 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().unwrap() | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+68
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use
Suggested change
|
||||||||||||||||||
x => anyhow::bail!("invalid type {x:?}, expected map"), | ||||||||||||||||||
}; | ||||||||||||||||||
Ok(map.entry(key).or_insert_with(|| serde_json::Value::Null)) | ||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this an accidental left-over?