Skip to content
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

Merged
merged 35 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b0b0c79
wip: added olm-deployer
razvan Jan 8, 2025
fa11668
wip
razvan Jan 9, 2025
5b75e2a
wip: checkpoint
razvan Jan 9, 2025
bbe0762
wip
razvan Jan 9, 2025
31b0372
wip: working version
razvan Jan 9, 2025
3a69789
reorg test manifests
razvan Jan 10, 2025
0893d20
impl owner ref
razvan Jan 10, 2025
e92acd3
Added readme, update manifests, successful run
razvan Jan 10, 2025
7729878
reorg modules
razvan Jan 10, 2025
e7a156c
wip
razvan Jan 13, 2025
5a3302b
test env
razvan Jan 14, 2025
46996ab
copy resources
razvan Jan 14, 2025
acee691
add secret op lib crate
razvan Jan 14, 2025
a827fab
patch namespace
razvan Jan 14, 2025
4693dfa
Revert "add secret op lib crate"
razvan Jan 14, 2025
87cfab2
added test for namespace patch
razvan Jan 14, 2025
df3b6ab
cargo fmt
razvan Jan 14, 2025
5ea0b36
Merge branch 'main' into feat/olm-deployer
razvan Jan 20, 2025
5736913
main merge
razvan Jan 20, 2025
4d3b7e7
added owner name cli param
razvan Jan 20, 2025
28a7f00
obtain clusterrole by label selector
razvan Jan 20, 2025
1f880c9
olm creates multiple clusterroles per subscription
razvan Jan 20, 2025
75d21e2
Merge branch 'main' into feat/olm-deployer
razvan Jan 21, 2025
0e77dfd
delete tests in favor of olm manifests
razvan Jan 21, 2025
1299ffd
modify DynamicObjects in place and reduce cloning
razvan Jan 21, 2025
790cf2c
added keep_alive cli option
razvan Jan 22, 2025
c2778b7
Merge branch 'main' into feat/olm-deployer
razvan Jan 22, 2025
850a0d0
sleep forever
razvan Jan 22, 2025
99ec5fd
fix lint
razvan Jan 22, 2025
274f0a2
main merge
razvan Feb 4, 2025
2c577ca
Update inline docs.
razvan Feb 4, 2025
1519519
Drop the op_version arg in favor of the csv name.
razvan Feb 6, 2025
57b431e
Update changelog.
razvan Feb 6, 2025
70160ae
fix typos
razvan Feb 6, 2025
00520b4
update readme to mention oci.stackable.tech
razvan Feb 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file.

- Made RSA key length configurable for certificates issued by cert-manager ([#528]).
- Kerberos principal backends now also provision principals for IP address, not just DNS hostnames ([#552]).
- OLM deployment helper ([#546]).

### Changed

Expand All @@ -22,6 +23,7 @@ All notable changes to this project will be documented in this file.
[#548]: https://github.com/stackabletech/secret-operator/pull/548
[#552]: https://github.com/stackabletech/secret-operator/pull/552
[#544]: https://github.com/stackabletech/secret-operator/pull/544
[#546]: https://github.com/stackabletech/secret-operator/pull/546

## [24.11.1] - 2025-01-10

Expand Down
64 changes: 54 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ clap = "4.5"
futures = { version = "0.3", features = ["compat"] }
h2 = "0.4"
ldap3 = { version = "0.11", default-features = false, features = [
"gssapi",
"tls",
"gssapi",
"tls",
] }
libc = "0.2"
native-tls = "0.2"
Expand Down Expand Up @@ -49,6 +49,7 @@ tonic-build = "0.12"
tonic-reflection = "0.12"
tracing = "0.1"
tracing-subscriber = "0.3"
walkdir = "2.5.0"
uuid = { version = "1.10.0", features = ["v4"] }
yasna = "0.5"

Expand Down
27 changes: 27 additions & 0 deletions nginx-deployment.yaml
Copy link
Member

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?

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
23 changes: 23 additions & 0 deletions rust/olm-deployer/Cargo.toml
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
23 changes: 23 additions & 0 deletions rust/olm-deployer/README.md
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
adwk67 marked this conversation as resolved.
Show resolved Hide resolved
...
```

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
...
```
3 changes: 3 additions & 0 deletions rust/olm-deployer/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
built::write_built_file().unwrap();
}
75 changes: 75 additions & 0 deletions rust/olm-deployer/src/data.rs
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()
}
razvan marked this conversation as resolved.
Show resolved Hide resolved
x => anyhow::bail!("invalid type {x:?}, expected map"),
};
Ok(map.entry(key).or_insert_with(|| serde_json::Value::Null))
}
Loading