diff --git a/src/executor.rs b/src/executor.rs index ab17d3c..0467f7a 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -317,7 +317,7 @@ impl Executor for DefaultExecutor { // just to check let object: SupportedResources = serde_yaml::from_str(manifest).expect("failed to deserialize manifest"); match object { - SupportedResources::Pod(_) | SupportedResources::Deployment(_) | SupportedResources::DaemonSet(_) => { + SupportedResources::Pod(_) | SupportedResources::Deployment(_) | SupportedResources::DaemonSet(_) | SupportedResources::Secret(_) => { self.apply_play(object) } SupportedResources::Ingress(ingress) => { @@ -348,6 +348,9 @@ impl Executor for DefaultExecutor { SupportedResources::CronJob(cron) => { self.remove_cron(cron) } + SupportedResources::Secret(secret) => { + todo!() + } } } } diff --git a/src/get.rs b/src/get.rs index 61ec85a..ce6a33e 100644 --- a/src/get.rs +++ b/src/get.rs @@ -63,6 +63,8 @@ pub enum GetCommands { Ingress(GetObjectArgs), #[command(alias("cronjobs"))] Cronjob(GetObjectArgs), + #[command(alias("secrets"))] + Secret(GetObjectArgs), } pub async fn get(args: GetArgs) -> Result<(), Box> { @@ -73,6 +75,7 @@ pub async fn get(args: GetArgs) -> Result<(), Box> { GetCommands::Node(args) => get_nodes(global_args, args).await, GetCommands::Ingress(args) => get_ingress(global_args, args).await, GetCommands::Cronjob(args) => get_cronjobs(global_args, args).await, + GetCommands::Secret(args) => todo!(), } } diff --git a/src/scheduler.rs b/src/scheduler.rs index 0a3be74..8b7d33b 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -469,6 +469,7 @@ impl DefaultScheduler { SupportedResources::DaemonSet(ds) => Self::plan_daemonset(state, ds), SupportedResources::Ingress(ingress) => Self::plan_ingress(state, ingress), SupportedResources::CronJob(cron) => Self::plan_cronjob(state, cron), + SupportedResources::Secret(secret) => todo!(), } } diff --git a/src/skate.rs b/src/skate.rs index 5c513a7..3174d01 100644 --- a/src/skate.rs +++ b/src/skate.rs @@ -104,7 +104,7 @@ pub enum SupportedResources { #[strum(serialize = "CronJob")] CronJob(CronJob), #[strum(serialize = "Secret")] - Secret(k8s_openapi::api::core::v1::Secret), + Secret(Secret), } @@ -306,64 +306,57 @@ pub fn read_manifests(filenames: Vec) -> Result, let mut result: Vec = Vec::new(); - for filename in filenames { - let str_file = fs::read_to_string(filename).expect("failed to read file"); - for document in serde_yaml::Deserializer::from_str(&str_file) { - let value = Value::deserialize(document).expect("failed to read document"); - if let Value::Mapping(mapping) = &value { - let api_version = mapping.get(&api_version_key).and_then(Value::as_str); - let kind = mapping.get(&kind_key).and_then(Value::as_str); - match (api_version, kind) { - (Some(api_version), Some(kind)) if - api_version == ::API_VERSION && - kind == ::KIND => - { - let pod: Pod = serde::Deserialize::deserialize(value)?; - result.push(SupportedResources::Pod(pod)) - } - - (Some(api_version), Some(kind)) if - api_version == ::API_VERSION && - kind == ::KIND => - { - let deployment: Deployment = serde::Deserialize::deserialize(value)?; - result.push(SupportedResources::Deployment(deployment)) - } - (Some(api_version), Some(kind)) if - api_version == ::API_VERSION && - kind == ::KIND => - { - let daemonset: DaemonSet = serde::Deserialize::deserialize(value)?; - result.push(SupportedResources::DaemonSet(daemonset)) - } - (Some(api_version), Some(kind)) if - api_version == ::API_VERSION && - kind == ::KIND => - { - let ingress: Ingress = serde::Deserialize::deserialize(value)?; - result.push(SupportedResources::Ingress(ingress)) - } - (Some(api_version), Some(kind)) if - api_version == ::API_VERSION && - kind == ::KIND => - { - let cronjob: CronJob = serde::Deserialize::deserialize(value)?; - result.push(SupportedResources::CronJob(cronjob)) + let supported_resources = + + for filename in filenames { + let str_file = fs::read_to_string(filename).expect("failed to read file"); + for document in serde_yaml::Deserializer::from_str(&str_file) { + let value = Value::deserialize(document).expect("failed to read document"); + if let Value::Mapping(mapping) = &value { + let api_version = mapping.get(&api_version_key).and_then(Value::as_str); + let kind = mapping.get(&kind_key).and_then(Value::as_str); + match (api_version, kind) { + (Some(api_version), Some(kind)) => { + if api_version == Pod::API_VERSION && + kind == Pod::KIND + { + let pod: Pod = serde::Deserialize::deserialize(value)?; + result.push(SupportedResources::Pod(pod)) + } else if api_version == Deployment::API_VERSION && + kind == Deployment::KIND + { + let deployment: Deployment = serde::Deserialize::deserialize(value)?; + result.push(SupportedResources::Deployment(deployment)) + } else if api_version == DaemonSet::API_VERSION && + kind == DaemonSet::KIND + { + let daemonset: DaemonSet = serde::Deserialize::deserialize(value)?; + result.push(SupportedResources::DaemonSet(daemonset)) + } else if api_version == Ingress::API_VERSION && kind == Ingress::KIND + { + let ingress: Ingress = serde::Deserialize::deserialize(value)?; + result.push(SupportedResources::Ingress(ingress)) + } else if + api_version == CronJob::API_VERSION && + kind == CronJob::KIND + { + let cronjob: CronJob = serde::Deserialize::deserialize(value)?; + result.push(SupportedResources::CronJob(cronjob)) + } else if + api_version == Secret::API_VERSION && + kind == Secret::KIND + { + let secret: Secret = serde::Deserialize::deserialize(value)?; + result.push(SupportedResources::Secret(secret)) + } } - (Some(api_version), Some(kind)) if - api_version == ::API_VERSION && - kind == ::KIND => - { - let secret: Secret = serde::Deserialize::deserialize(value)?; - result.push(SupportedResources::Secret(secret)) + _ => { + return Err(anyhow!(format!("kind {:?}", kind)).context("unsupported resource type").into()); } - _ => { - return Err(anyhow!(format!("kind {:?}", kind)).context("unsupported resource type").into()); - } + }; } } - } - } + }; Ok(result) }