diff --git a/Cargo.lock b/Cargo.lock index 1f65ec3..ce6bfeb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -864,6 +864,7 @@ version = "0.1.0" dependencies = [ "anyhow", "env_logger", + "futures", "k8s-openapi", "kube", "log", diff --git a/Cargo.toml b/Cargo.toml index cbbf30e..926dc9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,4 @@ schemars = "0.8.12" tokio = { version = "1.28.0", features = ["full"] } kube = { version = "0.82.2", features = ["runtime", "derive"] } k8s-openapi = { version = "0.18.0", features = ["v1_26"] } # TODO : switch to v1_27 +futures = "0.3.28" diff --git a/src/main.rs b/src/main.rs index baa238c..df7d984 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 = 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(()) +} \ No newline at end of file diff --git a/test/first-test.yaml b/test/first-test.yaml index da2f0ba..46f19ed 100644 --- a/test/first-test.yaml +++ b/test/first-test.yaml @@ -22,4 +22,4 @@ metadata: spec: instance: my-minio-instance name: first-bucket - secret: bucket-secret \ No newline at end of file + secret: first-bucket-secret \ No newline at end of file diff --git a/test/second-bucket.yaml b/test/second-bucket.yaml new file mode 100644 index 0000000..e14d20f --- /dev/null +++ b/test/second-bucket.yaml @@ -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 \ No newline at end of file