feat: add kubectl command
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-01-31 20:55:24 +01:00
parent c16396db8c
commit 91ff1f17ae
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
2 changed files with 56 additions and 0 deletions

View File

@ -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::*;

View File

@ -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<Container> {
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
}
}