Creating an example PipelineRun.
This commit is contained in:
parent
1612278bed
commit
1406a21785
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1905,6 +1905,7 @@ dependencies = [
|
||||
"http-body-util",
|
||||
"k8s-openapi",
|
||||
"kube",
|
||||
"schemars",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2",
|
||||
|
@ -26,6 +26,7 @@ http-body-util = "0.1.2"
|
||||
k8s-openapi = { version = "0.22.0", default-features = false, features = ["v1_30"] }
|
||||
# default client, config, rustls-tls
|
||||
kube = { version = "0.92.1", default-features = false, features = ["client", "config", "rustls-tls", "derive", "runtime"] }
|
||||
schemars = "0.8.21"
|
||||
serde = { version = "1.0.204", features = ["derive"] }
|
||||
# default std
|
||||
serde_json = { version = "1.0.120", default-features = false, features = ["std"] }
|
||||
|
70
example_pipeline_run.json
Normal file
70
example_pipeline_run.json
Normal file
@ -0,0 +1,70 @@
|
||||
{
|
||||
"apiVersion": "tekton.dev/v1beta1",
|
||||
"kind": "PipelineRun",
|
||||
"metadata": {
|
||||
"name": "minimal-test",
|
||||
"namespace": "lighthouse"
|
||||
},
|
||||
"spec": {
|
||||
"pipelineSpec": {
|
||||
"tasks": [
|
||||
{
|
||||
"name": "echo-variable",
|
||||
"taskSpec": {
|
||||
"metadata": {},
|
||||
"stepTemplate": {
|
||||
"image": "alpine:3.18",
|
||||
"name": "",
|
||||
"resources": {
|
||||
"requests": {
|
||||
"cpu": "10m",
|
||||
"memory": "600Mi"
|
||||
}
|
||||
}
|
||||
},
|
||||
"steps": [
|
||||
{
|
||||
"image": "alpine:3.18",
|
||||
"script": "#!/usr/bin/env sh\necho \"The variable: $(params.LOREM)\"\n"
|
||||
}
|
||||
]
|
||||
},
|
||||
"params": [
|
||||
{
|
||||
"name": "LOREM",
|
||||
"value": "$(tasks.set-variable.results.ipsum)"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "set-variable",
|
||||
"taskSpec": {
|
||||
"metadata": {},
|
||||
"stepTemplate": {
|
||||
"image": "alpine:3.18",
|
||||
"name": "",
|
||||
"resources": {
|
||||
"requests": {
|
||||
"cpu": "10m",
|
||||
"memory": "600Mi"
|
||||
}
|
||||
}
|
||||
},
|
||||
"results": [
|
||||
{
|
||||
"name": "ipsum"
|
||||
}
|
||||
],
|
||||
"steps": [
|
||||
{
|
||||
"image": "alpine:3.18",
|
||||
"script": "#!/usr/bin/env sh\necho -n \"dolar\" > \"$(results.ipsum.path)\"\n"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"timeout": "240h0m0s"
|
||||
}
|
||||
}
|
44
example_pipeline_run.yaml
Normal file
44
example_pipeline_run.yaml
Normal file
@ -0,0 +1,44 @@
|
||||
apiVersion: tekton.dev/v1beta1
|
||||
kind: PipelineRun
|
||||
metadata:
|
||||
name: minimal-test
|
||||
namespace: lighthouse
|
||||
spec:
|
||||
pipelineSpec:
|
||||
tasks:
|
||||
- name: echo-variable
|
||||
taskSpec:
|
||||
metadata: {}
|
||||
stepTemplate:
|
||||
image: alpine:3.18
|
||||
name: ""
|
||||
resources:
|
||||
requests:
|
||||
cpu: 10m
|
||||
memory: 600Mi
|
||||
steps:
|
||||
- image: alpine:3.18
|
||||
script: |
|
||||
#!/usr/bin/env sh
|
||||
echo "The variable: $(params.LOREM)"
|
||||
params:
|
||||
- name: LOREM
|
||||
value: $(tasks.set-variable.results.ipsum)
|
||||
- name: set-variable
|
||||
taskSpec:
|
||||
metadata: {}
|
||||
stepTemplate:
|
||||
image: alpine:3.18
|
||||
name: ""
|
||||
resources:
|
||||
requests:
|
||||
cpu: 10m
|
||||
memory: 600Mi
|
||||
results:
|
||||
- name: ipsum
|
||||
steps:
|
||||
- image: alpine:3.18
|
||||
script: |
|
||||
#!/usr/bin/env sh
|
||||
echo -n "dolar" > "$(results.ipsum.path)"
|
||||
timeout: 240h0m0s
|
24
src/crd_pipeline_run.rs
Normal file
24
src/crd_pipeline_run.rs
Normal file
@ -0,0 +1,24 @@
|
||||
use kube::CustomResource;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use serde_json::Value;
|
||||
|
||||
/// A single execution of a Pipeline.
|
||||
#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema)]
|
||||
#[kube(
|
||||
group = "tekton.dev",
|
||||
version = "v1beta1",
|
||||
kind = "PipelineRun",
|
||||
singular = "pipelinerun",
|
||||
plural = "pipelineruns"
|
||||
)]
|
||||
#[kube(namespaced)]
|
||||
pub struct PipelineRunSpec {
|
||||
/// Contents of the Pipeline
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub pipelineSpec: Option<Value>,
|
||||
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub timeout: Option<String>,
|
||||
}
|
16
src/main.rs
16
src/main.rs
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user