Compare commits

..

1 Commits

Author SHA1 Message Date
c46a4992ae Update Rust crate reqwest to 0.11.25
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2024-03-09 00:12:25 +00:00
11 changed files with 707 additions and 1393 deletions

1823
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -6,17 +6,17 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
log = "0.4.27"
env_logger = "0.11.8"
anyhow = "1.0.98"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
schemars = "0.9.0"
tokio = { version = "1.45.1", features = ["full"] }
kube = { version = "1.1.0", features = ["runtime", "derive"] }
k8s-openapi = { version = "0.25.0", features = ["v1_31"] }
futures = "0.3.31"
thiserror = "2.0.12"
rand = "0.9.1"
log = "0.4.21"
env_logger = "0.11.3"
anyhow = "1.0.80"
serde = { version = "1.0.195", features = ["derive"] }
serde_json = "1.0.114"
schemars = "0.8.16"
tokio = { version = "1.35.1", features = ["full"] }
kube = { version = "0.87.2", features = ["runtime", "derive"] }
k8s-openapi = { version = "0.20.0", features = ["v1_27"] }
futures = "0.3.30"
thiserror = "1.0.57"
rand = "0.8.5"
mktemp = "0.5.1"
reqwest = "0.12.20"
reqwest = "0.11.25"

View File

@ -1,10 +1,6 @@
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
libssl3 \
&& rm -rf /var/lib/apt/lists/*
COPY minio-operator /usr/local/bin/minio-operator
COPY mc /usr/local/bin/mc
ENTRYPOINT ["/usr/local/bin/minio-operator"]
ENTRYPOINT /usr/local/bin/minio-operator

View File

@ -1,109 +0,0 @@
# Setup for development
This guide will present you how to prepare your computer to update features of MinioK8SBucket
## Install Rust
As this project has been written using Rust, you will need to install it prior working on MinioK8SBucket. Please follow the official instructions: [https://www.rust-lang.org/tools/install](https://www.rust-lang.org/tools/install)
## Install Minikube
First, you need to install Minikube on your computer to have a K8S environment. In order to do this, please follow the official instructions: [https://minikube.sigs.k8s.io/docs/start](https://minikube.sigs.k8s.io/docs/start)
## Start Minikube
You will then need to start Minikube using the following command:
```bash
minikube start
```
You can then make sure that Minikube is working properly:
```
minikube kubectl get nodes
```
You should get a response similar to this one:
```
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane 2m16s v1.32.0
```
## Clone repository
Clone this repository using:
```bash
https://gitea.communiquons.org/pierre/MinioK8sBuckets
```
!!! note "Gitea account request"
If you want to get a Gitea account to make pull request on this repository, you will need to contact me at: `pierre.git@communiquons.org`
## Deploy Minio
First, enable Minikube tunnel:
```bash
minikube tunnel --bind-address '127.0.0.1'
```
You will then need to deploy Minio in Minikube. Apply the Minio deployment located at the in MinioK8SBucket repository:
```bash
minikube kubectl -- apply -f yaml/minio-dev-deployment.yml
```
Wait for the pod to become ready:
```bash
minikube kubectl -- get pods -w
```
Check for the availability of the service that expose Minio to your host computer:
```bash
minikube kubectl -- get services
```
You should get a result similar to this one:
```
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 31m
minio LoadBalancer 10.103.82.87 127.0.0.1 9000:30656/TCP,9090:31369/TCP 6m40s
```
You should be able to access minio at the following address: [http://127.0.0.1:9090](http://127.0.0.1:9090/)
Minio API should be available at: [http://127.0.0.1:9000/](http://127.0.0.1:9000/)
## Deploy CRD
You will need then to deploy the Custom Resource Definitions of MinioK8SBucket using the following command:
```bash
minikube kubectl -- apply -f yaml/crd.yaml
```
## Run operator
You can then run the project using the following command:
```bash
cargo fmt && cargo clippy && RUST_LOG=debug cargo run --
```
## Create a first bucket
You should be able to create a first bucket using the following command:
```bash
minikube kubectl -- apply -f test/test-outside-cluster.yaml
```
The bucket should then appear in buckets list:
```bash
minikube kubectl -- get buckets
```
```
NAME AGE
first-bucket 8m43s
```
Have fun working for MinioK8SBucket!

View File

@ -1,3 +1,9 @@
{
"extends": ["local>renovate/presets"]
}
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"packageRules": [
{
"matchUpdateTypes": ["minor", "patch"],
"automerge": true
}
]
}

View File

@ -10,7 +10,6 @@ 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<()> {
@ -55,17 +54,6 @@ 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 > 10 {
panic!("Minio is unreachable!");
}
ready_count += 1;
tokio::time::sleep(Duration::from_millis(500)).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,
@ -77,7 +65,7 @@ async fn apply_bucket(b: &MinioBucket, client: &Client) -> anyhow::Result<()> {
);
// The secret needs to be created
let new_user = MinioUser::gen_random(&b.spec.name);
let new_user = MinioUser::gen_random();
create_secret(
&secrets,
&b.spec.secret,

View File

@ -44,9 +44,9 @@ pub struct MinioUser {
}
impl MinioUser {
pub fn gen_random(prefix: &str) -> Self {
pub fn gen_random() -> Self {
Self {
username: format!("{prefix}_{}", rand_str(SECRET_MINIO_BUCKET_ACCESS_LEN)),
username: rand_str(SECRET_MINIO_BUCKET_ACCESS_LEN),
password: rand_str(SECRET_MINIO_BUCKET_SECRET_LEN),
}
}
@ -1099,7 +1099,7 @@ mod test {
let srv = MinioTestServer::start().await.unwrap();
let service = srv.as_service();
let user = MinioUser::gen_random("policy_user");
let user = MinioUser::gen_random();
assert!(!service.user_list().await.unwrap().contains(&user.username));
service.user_apply(&user).await.unwrap();
@ -1113,7 +1113,7 @@ mod test {
let srv = MinioTestServer::start().await.unwrap();
let service = srv.as_service();
let user = MinioUser::gen_random("attach_policy_user");
let user = MinioUser::gen_random();
service.user_apply(&user).await.unwrap();
service

View File

@ -25,7 +25,7 @@ impl MinioTestServer {
let root_user = rand_str(30);
let root_password = rand_str(30);
let api_port = (2000 + rand::rng().next_u64() % 5000) as u16;
let api_port = (2000 + rand::thread_rng().next_u64() % 5000) as u16;
log::info!(
"Spwan a new Minio server on port {} with root credentials {}:{}",
api_port,

View File

@ -1,6 +1,11 @@
use rand::distr::{Alphanumeric, SampleString};
use rand::distributions::Alphanumeric;
use rand::Rng;
/// Generate a random string of a given size
pub fn rand_str(len: usize) -> String {
Alphanumeric.sample_string(&mut rand::rng(), len)
rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(len)
.map(char::from)
.collect()
}

View File

@ -12,7 +12,7 @@ kind: MinioInstance
metadata:
name: my-minio-instance
spec:
endpoint: http://localhost:9000
endpoint: http://localhost:9000/
credentials: minio-root
---
apiVersion: "communiquons.org/v1"
@ -22,4 +22,4 @@ metadata:
spec:
instance: my-minio-instance
name: first-bucket
secret: first-bucket-secret
secret: first-bucket-secret

View File

@ -1,89 +0,0 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: minio
labels:
app: minio
spec:
replicas: 1
selector:
matchLabels:
app: minio
template:
metadata:
labels:
app: minio
spec:
volumes:
- name: data
persistentVolumeClaim:
claimName: minio
containers:
- name: minio
image: minio/minio
imagePullPolicy: Always
ports:
- containerPort: 9000
protocol: TCP
name: api
- containerPort: 9090
protocol: TCP
name: console
args:
- server
- /data
- --console-address
- ":9090"
env:
- name: MINIO_ROOT_USER
value: minioadmin
- name: MINIO_ROOT_PASSWORD
value: minioadmin
volumeMounts:
- mountPath: "/data"
name: data
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: minio
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
capacity:
storage: 5Gi
hostPath:
path: /data/minio/
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: minio
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
---
apiVersion: v1
kind: Service
metadata:
name: minio
labels:
app: minio
spec:
type: LoadBalancer
selector:
app: minio
ports:
- name: api
port: 9000
targetPort: api
- name: console
port: 9090
targetPort: console
externalTrafficPolicy: Local