Skip to content

Instantly share code, notes, and snippets.

@chmouel
Last active May 5, 2022 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chmouel/cb398155eae141725a2e062f27542208 to your computer and use it in GitHub Desktop.
Save chmouel/cb398155eae141725a2e062f27542208 to your computer and use it in GitHub Desktop.
Querying tekton objects with Rust, dynamic clients and tokio
[package]
name = "tekton-rs"
version = "0.1.0"
authors = ["Chmouel Boudjnah <chmouel@chmouel.com>"]
edition = "2018"
[dependencies]
kube = { version = "0.71.0", features = ["runtime", "derive"] }
k8s-openapi = { version = "0.14.0", features = ["v1_23"] }
tokio = { version = "1.14.0", features = ["full"] }
anyhow = "1.0.44"
use anyhow::Ok;
use kube::{
api::ListParams,
core::{DynamicObject, GroupVersionKind},
discovery, Api, Client,
};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = Client::try_default().await?;
let namespace = std::env::var("NAMESPACE").unwrap_or_else(|_| "test".into());
let gvk = GroupVersionKind::gvk("tekton.dev", "v1beta1", "PipelineRun");
let (ar, _caps) = discovery::pinned_kind(&client, &gvk).await?;
let dynapi = Api::<DynamicObject>::namespaced_with(client, &namespace, &ar);
let prs = dynapi.list(&ListParams::default()).await?;
dbg!(prs.items);
let pr = dynapi.get("pr-test").await?;
let status = pr.data["status"].as_object().unwrap();
dbg!(status);
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment