Initial commit
commit
6f7160fc02
|
@ -0,0 +1,5 @@
|
|||
root = true
|
||||
|
||||
[*.sh]
|
||||
indent_style = space
|
||||
indent_size = 4
|
|
@ -0,0 +1 @@
|
|||
/target
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "k8s-reboot-controller"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
rocket = { version = "0.5.1", default-features = false }
|
||||
tracing = "0.1.41"
|
||||
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
|
|
@ -0,0 +1,2 @@
|
|||
match_block_trailing_comma = true
|
||||
max_width = 79
|
|
@ -0,0 +1,10 @@
|
|||
#!/bin/sh
|
||||
|
||||
SELF=$(realpath "$0")
|
||||
|
||||
if [ -z "${KUBECONFIG}" ]; then
|
||||
KUBECONFIG="$("${SELF%/*}"/start-k3d.sh)"
|
||||
export KUBECONFIG
|
||||
fi
|
||||
|
||||
cargo test "$@"
|
|
@ -0,0 +1,33 @@
|
|||
#!/bin/sh
|
||||
|
||||
: ${CLUSTER_NAME:=krc-tests}
|
||||
: ${XDG_RUNTIME_DIR:=/run/user/$(id -u)}
|
||||
|
||||
: "${DOCKER_HOST=unix://${XDG_RUNTIME_DIR}/podman/podman.sock}"
|
||||
: "${DOCKER_SOCK=${XDG_RUNTIME_DIR}/podman/podman.sock}"
|
||||
export DOCKER_HOST DOCKER_SOCK
|
||||
|
||||
cluster_exists() {
|
||||
k3d cluster get "${CLUSTER_NAME}" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
create_cluster() {
|
||||
k3d cluster create "${CLUSTER_NAME}" \
|
||||
--k3s-arg '--kubelet-arg=feature-gates=KubeletInUserNamespace=true@server:*' \
|
||||
--kubeconfig-update-default=false \
|
||||
--kubeconfig-switch-context=false \
|
||||
--no-lb \
|
||||
>&2
|
||||
}
|
||||
|
||||
start_cluster() {
|
||||
k3d cluster start "${CLUSTER_NAME}" >&2
|
||||
}
|
||||
|
||||
if ! cluster_exists; then
|
||||
create_cluster
|
||||
else
|
||||
start_cluster
|
||||
fi
|
||||
|
||||
k3d kubeconfig write "${CLUSTER_NAME}"
|
|
@ -0,0 +1,22 @@
|
|||
use rocket::Request;
|
||||
use rocket::http::Status;
|
||||
|
||||
#[rocket::catch(default)]
|
||||
fn not_found(status: Status, _req: &Request) -> String {
|
||||
match status.reason() {
|
||||
Some(s) => s.into(),
|
||||
None => format!("{}", status.code),
|
||||
}
|
||||
}
|
||||
|
||||
#[rocket::get("/healthz")]
|
||||
fn healthz() -> &'static str {
|
||||
"UP"
|
||||
}
|
||||
|
||||
#[rocket::launch]
|
||||
pub fn rocket() -> _ {
|
||||
rocket::build()
|
||||
.mount("/", rocket::routes![healthz])
|
||||
.register("/", rocket::catchers![not_found])
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#[rocket::launch]
|
||||
fn rocket() -> _ {
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
|
||||
.with_writer(std::io::stderr)
|
||||
.init();
|
||||
|
||||
k8s_reboot_controller::rocket()
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
use rocket::http::Status;
|
||||
|
||||
#[test]
|
||||
fn test_healthz() {
|
||||
super::setup();
|
||||
|
||||
let client = super::client();
|
||||
let response = client.get("/healthz").dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.into_string(), Some("UP".into()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_not_found() {
|
||||
super::setup();
|
||||
|
||||
let client = super::client();
|
||||
let response = client.get("/bogus").dispatch();
|
||||
assert_eq!(response.status(), Status::NotFound);
|
||||
assert_eq!(response.into_string(), Some("Not Found".into()));
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
mod basic;
|
||||
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use rocket::local::blocking::Client;
|
||||
|
||||
static SETUP: LazyLock<()> = LazyLock::new(|| {
|
||||
unsafe {
|
||||
std::env::set_var("ROCKET_CLI_COLORS", "false");
|
||||
}
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(tracing_subscriber::EnvFilter::new(concat!(
|
||||
env!("CARGO_PKG_NAME"),
|
||||
"=trace,",
|
||||
"k8s_reboot_controller=trace,",
|
||||
"info",
|
||||
)))
|
||||
.with_test_writer()
|
||||
.init();
|
||||
});
|
||||
|
||||
fn setup() {
|
||||
LazyLock::force(&SETUP);
|
||||
}
|
||||
|
||||
fn client() -> Client {
|
||||
Client::tracked(k8s_reboot_controller::rocket()).unwrap()
|
||||
}
|
Loading…
Reference in New Issue