Implement base operator #1

Merged
pierre merged 21 commits from operator into master 2023-05-08 16:20:17 +00:00
5 changed files with 36 additions and 2 deletions
Showing only changes of commit 547cc02800 - Show all commits

1
Cargo.lock generated
View File

@ -864,6 +864,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"env_logger", "env_logger",
"futures",
"k8s-openapi", "k8s-openapi",
"kube", "kube",
"log", "log",

View File

@ -15,3 +15,4 @@ schemars = "0.8.12"
tokio = { version = "1.28.0", features = ["full"] } tokio = { version = "1.28.0", features = ["full"] }
kube = { version = "0.82.2", features = ["runtime", "derive"] } kube = { version = "0.82.2", features = ["runtime", "derive"] }
k8s-openapi = { version = "0.18.0", features = ["v1_26"] } # TODO : switch to v1_27 k8s-openapi = { version = "0.18.0", features = ["v1_26"] } # TODO : switch to v1_27
futures = "0.3.28"

View File

@ -1,4 +1,7 @@
use kube::Client; use futures::TryStreamExt;
use kube::{Api, Client};
use kube::runtime::{watcher, WatchStreamExt};
use minio_operator::crd::MinioBucket;
#[tokio::main] #[tokio::main]
async fn main() -> anyhow::Result<()> { async fn main() -> anyhow::Result<()> {
@ -6,5 +9,25 @@ async fn main() -> anyhow::Result<()> {
let client = Client::try_default().await?; let client = Client::try_default().await?;
let buckets: Api<MinioBucket> = Api::default_namespaced(client.clone());
// Listen for events / buckets creation or update (deletion is not supported)
let wc = watcher::Config::default();
let bw = watcher(buckets, wc).applied_objects();
futures::pin_mut!(bw);
while let Some(b) = bw.try_next().await? {
if let Err(e) = apply_bucket(&b, &client).await {
log::error!("Failed to apply desired configuration for applied bucket {} : {}", b.spec.name, e)
}
}
Ok(())
}
/// Make sure a bucket is compliant with a desired configuration
async fn apply_bucket(b: &MinioBucket, _client: &Client) -> anyhow::Result<()> {
log::info!("Apply configuration for bucket {}", b.spec.name);
Ok(()) Ok(())
} }

View File

@ -22,4 +22,4 @@ metadata:
spec: spec:
instance: my-minio-instance instance: my-minio-instance
name: first-bucket name: first-bucket
secret: bucket-secret secret: first-bucket-secret

9
test/second-bucket.yaml Normal file
View File

@ -0,0 +1,9 @@
---
apiVersion: "communiquons.org/v1"
kind: MinioBucket
metadata:
name: second-bucket
spec:
instance: my-minio-instance
name: second-bucket
secret: second-bucket-secret