Read minio instance secret key

This commit is contained in:
2023-05-06 10:58:18 +02:00
parent 547cc02800
commit 36aaf5fb4d
10 changed files with 65 additions and 8 deletions

View File

@@ -1,7 +1,11 @@
use futures::TryStreamExt;
use k8s_openapi::api::core::v1::Secret;
use kube::{Api, Client};
use kube::runtime::{watcher, WatchStreamExt};
use minio_operator::crd::MinioBucket;
use minio_operator::constants::{SECRET_MINIO_INSTANCE_ACCESS_KEY, SECRET_MINIO_INSTANCE_SECRET_KEY};
use minio_operator::crd::{MinioBucket, MinioInstance};
use minio_operator::minio::MinioService;
use minio_operator::secrets::read_secret_str;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
@@ -27,7 +31,23 @@ async fn main() -> anyhow::Result<()> {
/// Make sure a bucket is compliant with a desired configuration
async fn apply_bucket(b: &MinioBucket, _client: &Client) -> anyhow::Result<()> {
async fn apply_bucket(b: &MinioBucket, client: &Client) -> anyhow::Result<()> {
log::info!("Apply configuration for bucket {}", b.spec.name);
// Get instance information
let instances: Api<MinioInstance> = Api::default_namespaced(client.clone());
let instance = instances.get(&b.spec.instance).await?;
// Get instance configuration
let secrets: Api<Secret> = Api::default_namespaced(client.clone());
let instance_secret = secrets.get(&instance.spec.credentials).await?;
let service = MinioService {
hostname: instance.spec.endpoint,
access_key: read_secret_str(&instance_secret, SECRET_MINIO_INSTANCE_ACCESS_KEY)?,
secret_key: read_secret_str(&instance_secret, SECRET_MINIO_INSTANCE_SECRET_KEY)?,
};
println!("{:?}", service);
Ok(())
}