Skip to content

Commit

Permalink
run Tainter (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
LasseHels authored Oct 20, 2024
1 parent 895c67b commit bc4e132
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 43 deletions.
133 changes: 132 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tracing-subscriber = { version = "0.3.18", features = ["json"] }
kube = { version = "0.90.0", features = ["runtime", "derive"] }
k8s-openapi = { version = "0.21.1", features = ["latest"] }
futures = "0.3.30"
tokio = { version = "1.37.0", features = ["macros"] }
tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread", "rt"] }
tower-test = "0.4.0"
tower = "0.4.13"
http = "1.1.0"
Expand All @@ -25,6 +25,12 @@ strum_macros = "0.26.4"
strum = "0.26.3"
validator = { version = "0.18.1", features = ["derive"] }
thiserror = "1.0.64"
clap = { version = "4.5.20", features = ["derive"] }

[dev-dependencies]
test-case = "3.3.1"

[[bin]]
edition = "2021"
name = "tainter"
path = "src/main.rs"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: run
run:
cargo run
cargo run -- --config-file "./settings/tainter.toml"

.PHONY: test
test:
Expand Down
20 changes: 20 additions & 0 deletions settings/tainter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[server]
host = "0.0.0.0"
port = "8080"

[log]
max_level = "info"

[[reconciler.matchers]]
[reconciler.matchers.taint]
effect = "NoExecute"
key = "pressure"
value = "memory"

[[reconciler.matchers.conditions]]
type = "NetworkInterfaceCard"
status = "Kaput|Ruined"

[[reconciler.matchers.conditions]]
type = "PrivateLink"
status = "severed"
42 changes: 32 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
use k8s_openapi::serde::Deserialize;
use clap::Parser;
use kube::Client;
use std::error::Error;

use crate::settings::Settings;

mod reconciler;
mod settings;
mod tainter;

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
/// Path to TOML file from which configuration is read.
#[arg(short, long)]
config_file: String,
}

// Adding the actix_web::main attribute also implicitly adds tokio::main.
// See https://stackoverflow.com/a/66419283.
#[actix_web::main]
async fn main() {
// TODO read settings file and initialize.
// let settings = Config::builder().add_source(config::File::with_name("example_config")).build().unwrap();
//
// println!("{:?}", settings);
async fn main() -> Result<(), Box<dyn Error>> {
let args = Args::parse();
println!(
"Reading configuration from file at path {}",
args.config_file
);
let settings = Settings::new(args.config_file.as_str())?;

tracing_subscriber::fmt()
.json()
// TODO ability to configure log level.
.with_max_level(tracing::Level::INFO)
.with_max_level(settings.log.max_level)
.with_current_span(false)
.init();

// let tainter = tainter::Tainter::new("localhost".to_string(), 8000);
// tainter.start().await.unwrap();
tracing::info!("Initializing Kubernetes client");

let client = Client::try_default().await?;

let tainter = tainter::Tainter::new(settings, client);

tainter.start().await?;

Ok(())
}
8 changes: 4 additions & 4 deletions src/reconciler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ use regex::Regex;

#[derive(Debug)]
pub struct Condition {
type_: Regex,
status: Regex,
pub type_: Regex,
pub status: Regex,
}

pub struct Configuration {
conditions: Vec<Condition>,
taint: Taint,
pub conditions: Vec<Condition>,
pub taint: Taint,
}

pub struct Reconciler {
Expand Down
Loading

0 comments on commit bc4e132

Please sign in to comment.