Can listen to Minio buckets creation / update

This commit is contained in:
2023-05-06 09:35:18 +02:00
parent 4b7748bfbf
commit 547cc02800
5 changed files with 36 additions and 2 deletions

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]
async fn main() -> anyhow::Result<()> {
@ -6,5 +9,25 @@ async fn main() -> anyhow::Result<()> {
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(())
}