Try a nightly toolchain in the build
Some checks failed
ci/woodpecker/push/build-container Pipeline failed
Some checks failed
ci/woodpecker/push/build-container Pipeline failed
Signed-off-by: Nikolai Rodionov <iam@allanger.xyz>
This commit is contained in:
@@ -5,7 +5,8 @@ RUN cp $(which rc) .
|
||||
FROM rust AS builder
|
||||
WORKDIR /src
|
||||
COPY . .
|
||||
RUN cargo build --release
|
||||
RUN rustup toolchain install nightly
|
||||
RUN cargo +nightly build --release -Z sparse-registry
|
||||
|
||||
FROM alpine
|
||||
COPY --from=rc /output/rc /usr/bin/rc
|
||||
|
||||
36
operator/src/config.rs
Normal file
36
operator/src/config.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs::File;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct OperatorConfig {
|
||||
pub set_owner_reference: bool,
|
||||
}
|
||||
|
||||
pub(crate) fn read_config_from_file(path: String) -> Result<OperatorConfig, anyhow::Error> {
|
||||
let file = File::open(path)?;
|
||||
let config: OperatorConfig = serde_json::from_reader(file)?;
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::io::Write;
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
use crate::config::read_config_from_file;
|
||||
|
||||
#[test]
|
||||
fn test_read_config() {
|
||||
let config_json = r#"{
|
||||
"setOwnerReference": true
|
||||
}
|
||||
"#;
|
||||
let mut file = NamedTempFile::new().expect("Can't create a file");
|
||||
let path = file.path().to_path_buf();
|
||||
writeln!(file, "{}", config_json).expect("Can't write a config file");
|
||||
let config = read_config_from_file(path.to_str().expect("Can't get the path").to_string())
|
||||
.expect("Can't read the config file");
|
||||
assert!(config.set_owner_reference);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ mod conditions;
|
||||
mod controllers;
|
||||
mod rc;
|
||||
mod cli;
|
||||
mod config;
|
||||
|
||||
use crate::controllers::{rustfs_instance};
|
||||
|
||||
@@ -10,6 +11,7 @@ use clap::Parser;
|
||||
use kube::Client;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
use self::config::read_config_from_file;
|
||||
use self::controllers::{rustfs_bucket, rustfs_user};
|
||||
|
||||
/// Simple program to greet a person
|
||||
@@ -29,6 +31,9 @@ struct Args {
|
||||
/// If enabled, DB Operator will run full reconciliation only
|
||||
/// when changes are detected
|
||||
is_change_check_nabled: bool,
|
||||
#[arg(long, default_value = "/src/config/config.json")]
|
||||
/// A path to a config file
|
||||
config: String,
|
||||
}
|
||||
|
||||
#[get("/health")]
|
||||
@@ -45,8 +50,9 @@ async fn main() -> anyhow::Result<()> {
|
||||
let client = Client::try_default()
|
||||
.await
|
||||
.expect("failed to create kube Client");
|
||||
let config = read_config_from_file("test".to_string())?;
|
||||
let rustfs_instance_ctrl = rustfs_instance::run(client.clone());
|
||||
let rustfs_bucket_ctrl = rustfs_bucket::run(client.clone());
|
||||
let rustfs_bucket_ctrl = rustfs_bucket::run(client.clone(), config.clone());
|
||||
let rustfs_user_ctrl = rustfs_user::run(client.clone());
|
||||
// Start web server
|
||||
let server = HttpServer::new(move || {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::conditions::{is_condition_true, set_condition};
|
||||
use crate::config::OperatorConfig;
|
||||
use crate::rc::{create_bucket, list_buckets};
|
||||
use api::api::v1beta1_rustfs_instance::RustFSInstance;
|
||||
use futures::StreamExt;
|
||||
@@ -383,14 +384,14 @@ pub(crate) fn error_policy(_: Arc<RustFSBucket>, err: &RustFSBucketError, _: Arc
|
||||
}
|
||||
|
||||
#[instrument(skip(client), fields(trace_id))]
|
||||
pub async fn run(client: Client) {
|
||||
pub async fn run(client: Client, config: OperatorConfig) {
|
||||
let buckets = Api::<RustFSBucket>::all(client.clone());
|
||||
if let Err(err) = buckets.list(&ListParams::default().limit(1)).await {
|
||||
error!("{}", err);
|
||||
std::process::exit(1);
|
||||
}
|
||||
let recorder = Recorder::new(client.clone(), "bucket-controller".into());
|
||||
let context = Context { client, recorder };
|
||||
let context = Context { client, recorder, config };
|
||||
Controller::new(buckets, Config::default().any_semantic())
|
||||
.shutdown_on_signal()
|
||||
.run(reconcile, error_policy, Arc::new(context))
|
||||
@@ -405,6 +406,7 @@ pub(crate) struct Context {
|
||||
pub client: Client,
|
||||
/// Event recorder
|
||||
pub recorder: Recorder,
|
||||
pub(crate) config: OperatorConfig,
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
|
||||
Reference in New Issue
Block a user