From 356fca6f1fe709a4c44cb4f8270d1e2c2de6f885 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 17 Dec 2024 21:16:03 +0100 Subject: [PATCH] Wait for Minio to be reachable before attempting to update bucket configuration --- src/main.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main.rs b/src/main.rs index f2279a3..409d751 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ use minio_operator::crd::{MinioBucket, MinioInstance}; use minio_operator::minio::{MinioService, MinioUser}; use minio_operator::secrets::{create_secret, read_secret_str}; use std::collections::BTreeMap; +use std::time::Duration; #[tokio::main] async fn main() -> anyhow::Result<()> { @@ -54,6 +55,17 @@ async fn apply_bucket(b: &MinioBucket, client: &Client) -> anyhow::Result<()> { secret_key: read_secret_str(&instance_secret, SECRET_MINIO_INSTANCE_SECRET_KEY)?, }; + // Check if Minio is responding + let mut ready_count = 0; + while !service.is_ready().await { + if ready_count > 5 { + panic!("Minio is unreachable!"); + } + ready_count += 1; + tokio::time::sleep(Duration::from_millis(200)).await; + log::warn!("Minio is not responding yet, will try again to connect soon..."); + } + // Get user key & password let user_secret = match secrets.get_opt(&b.spec.secret).await? { Some(s) => s,