Creating an example PipelineRun.

This commit is contained in:
Tom Alexander
2024-07-21 15:54:12 -04:00
parent 1612278bed
commit 1406a21785
6 changed files with 156 additions and 0 deletions

View File

@@ -7,6 +7,8 @@ use axum::routing::get;
use axum::routing::post;
use axum::Json;
use axum::Router;
use kube::api::PostParams;
use kube::Api;
use kube::Client;
use serde::Serialize;
use tokio::signal;
@@ -15,12 +17,17 @@ use tower_http::trace::TraceLayer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use self::crd_pipeline_run::PipelineRun;
use self::webhook::hook;
use self::webhook::verify_signature;
use kube::CustomResourceExt;
mod crd_pipeline_run;
mod hook_push;
mod webhook;
const EXAMPLE_PIPELINE_RUN: &'static str = include_str!("../example_pipeline_run.json");
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::registry()
@@ -36,6 +43,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.await
.expect("Set KUBECONFIG to a valid kubernetes config.");
let jobs: Api<PipelineRun> = Api::namespaced(kubernetes_client, "lighthouse");
// let jobs: Api<PipelineRun> = Api::default_namespaced(kubernetes_client);
tracing::info!("Using crd: {}", serde_json::to_string(&PipelineRun::crd())?);
let test_run: PipelineRun = serde_json::from_str(EXAMPLE_PIPELINE_RUN)?;
let pp = PostParams::default();
let created_run = jobs.create(&pp, &test_run).await?;
let app = Router::new()
.route("/hook", post(hook))
.layer(middleware::from_fn(verify_signature))