Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
byrnedo committed Jul 30, 2024
1 parent eca4894 commit e1f4cf2
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/skate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use async_trait::async_trait;
use clap::{Args, Command, Parser, Subcommand};
use k8s_openapi::{List, Metadata, NamespaceResourceScope, Resource, ResourceScope};
use k8s_openapi::api::apps::v1::{DaemonSet, Deployment, DeploymentSpec};
use k8s_openapi::api::core::v1::Pod;
use k8s_openapi::api::core::v1::{Pod, Secret};
use serde_yaml;
use serde::{Deserialize, Serialize};
use tokio;
Expand Down Expand Up @@ -103,6 +103,8 @@ pub enum SupportedResources {
Ingress(Ingress),
#[strum(serialize = "CronJob")]
CronJob(CronJob),
#[strum(serialize = "Secret")]
Secret(k8s_openapi::api::core::v1::Secret),
}


Expand All @@ -114,6 +116,7 @@ impl SupportedResources {
SupportedResources::DaemonSet(r) => metadata_name(r),
SupportedResources::Ingress(r) => metadata_name(r),
SupportedResources::CronJob(r) => metadata_name(r),
SupportedResources::Secret(s) => metadata_name(s),
}
}

Expand All @@ -125,6 +128,7 @@ impl SupportedResources {
SupportedResources::DaemonSet(d) => d.clone().spec.unwrap_or_default().template.spec.unwrap_or_default().host_network.unwrap_or_default(),
SupportedResources::Ingress(_) => false,
SupportedResources::CronJob(c) => c.clone().spec.unwrap_or_default().job_template.spec.unwrap_or_default().template.spec.unwrap_or_default().host_network.unwrap_or_default(),
SupportedResources::Secret(_) => false,
}
}
fn fixup_metadata(meta: ObjectMeta, extra_labels: Option<HashMap<String, String>>) -> Result<ObjectMeta, Box<dyn Error>> {
Expand All @@ -148,6 +152,10 @@ impl SupportedResources {
pub fn fixup(self) -> Result<Self, Box<dyn Error>> {
let mut resource = self.clone();
let resource = match resource {
SupportedResources::Secret(ref mut s) => {
// TODO
resource
}
SupportedResources::CronJob(ref mut c) => {
let original_name = c.metadata.name.clone().unwrap_or("".to_string());
if original_name.is_empty() {
Expand Down Expand Up @@ -342,6 +350,13 @@ pub fn read_manifests(filenames: Vec<String>) -> Result<Vec<SupportedResources>,
let cronjob: CronJob = serde::Deserialize::deserialize(value)?;
result.push(SupportedResources::CronJob(cronjob))
}
(Some(api_version), Some(kind)) if
api_version == <Secret as Resource>::API_VERSION &&
kind == <Secret as Resource>::KIND =>
{
let secret: Secret = serde::Deserialize::deserialize(value)?;
result.push(SupportedResources::Secret(secret))
}
_ => {
return Err(anyhow!(format!("kind {:?}", kind)).context("unsupported resource type").into());
}
Expand Down

0 comments on commit e1f4cf2

Please sign in to comment.