From 91ff1f17ae834b6901fb684bb6b18672ab311a7a Mon Sep 17 00:00:00 2001 From: kjuulh Date: Wed, 31 Jan 2024 20:55:24 +0100 Subject: [PATCH] feat: add kubectl command Signed-off-by: kjuulh --- crates/cuddle-ci/src/rust_service.rs | 2 + crates/cuddle-ci/src/rust_service/kubectl.rs | 54 ++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 crates/cuddle-ci/src/rust_service/kubectl.rs diff --git a/crates/cuddle-ci/src/rust_service.rs b/crates/cuddle-ci/src/rust_service.rs index 457fd3d..8cd5e89 100644 --- a/crates/cuddle-ci/src/rust_service.rs +++ b/crates/cuddle-ci/src/rust_service.rs @@ -420,6 +420,7 @@ mod clap_sanity_test; mod cuddle_cli; mod docker_cache; mod docker_cli; +mod kubectl; mod mold; mod sqlx; mod ssh_agent; @@ -434,6 +435,7 @@ pub mod extensions { pub use super::cuddle_cli::*; pub use super::docker_cache::*; pub use super::docker_cli::*; + pub use super::kubectl::*; pub use super::mold::*; pub use super::sqlx::*; pub use super::ssh_agent::*; diff --git a/crates/cuddle-ci/src/rust_service/kubectl.rs b/crates/cuddle-ci/src/rust_service/kubectl.rs new file mode 100644 index 0000000..c61b8aa --- /dev/null +++ b/crates/cuddle-ci/src/rust_service/kubectl.rs @@ -0,0 +1,54 @@ +use std::sync::Arc; + +use async_trait::async_trait; +use dagger_sdk::{Container, ImageMediaTypes}; + +use crate::dagger_middleware::DaggerMiddleware; + +use super::RustService; + +pub struct Kubectl { + client: dagger_sdk::Query, +} + +impl Kubectl { + pub fn new(client: dagger_sdk::Query) -> Self { + Self { client } + } +} + +#[async_trait] +impl DaggerMiddleware for Kubectl { + async fn handle(&self, container: Container) -> eyre::Result { + let kubectl = self + .client + .container() + .from("line/kubectl-kustomize:1.29.1-5.3.0"); + + Ok(container + .with_file( + "/usr/local/bin/kubectl", + kubectl.file("/usr/local/bin/kubectl"), + ) + .with_file( + "/usr/local/bin/kustomize", + kubectl.file("/usr/local/bin/kustomize"), + )) + } +} + +pub trait KubectlExt { + fn with_kubectl(&mut self) -> &mut Self { + self + } +} + +impl KubectlExt for RustService { + fn with_kubectl(&mut self) -> &mut Self { + self.with_stage(super::RustServiceStage::BeforePackage(Arc::new( + Kubectl::new(self.client.clone()), + ))); + + self + } +}