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 e1f4cf2 commit c078a74
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 56 deletions.
5 changes: 4 additions & 1 deletion src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -348,6 +348,9 @@ impl Executor for DefaultExecutor {
SupportedResources::CronJob(cron) => {
self.remove_cron(cron)
}
SupportedResources::Secret(secret) => {
todo!()
}
}
}
}
3 changes: 3 additions & 0 deletions src/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Error>> {
Expand All @@ -73,6 +75,7 @@ pub async fn get(args: GetArgs) -> Result<(), Box<dyn Error>> {
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!(),
}
}

Expand Down
1 change: 1 addition & 0 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(),
}
}

Expand Down
103 changes: 48 additions & 55 deletions src/skate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub enum SupportedResources {
#[strum(serialize = "CronJob")]
CronJob(CronJob),
#[strum(serialize = "Secret")]
Secret(k8s_openapi::api::core::v1::Secret),
Secret(Secret),
}


Expand Down Expand Up @@ -306,64 +306,57 @@ pub fn read_manifests(filenames: Vec<String>) -> Result<Vec<SupportedResources>,

let mut result: Vec<SupportedResources> = 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 == <Pod as Resource>::API_VERSION &&
kind == <Pod as Resource>::KIND =>
{
let pod: Pod = serde::Deserialize::deserialize(value)?;
result.push(SupportedResources::Pod(pod))
}

(Some(api_version), Some(kind)) if
api_version == <Deployment as Resource>::API_VERSION &&
kind == <Deployment as Resource>::KIND =>
{
let deployment: Deployment = serde::Deserialize::deserialize(value)?;
result.push(SupportedResources::Deployment(deployment))
}
(Some(api_version), Some(kind)) if
api_version == <DaemonSet as Resource>::API_VERSION &&
kind == <DaemonSet as Resource>::KIND =>
{
let daemonset: DaemonSet = serde::Deserialize::deserialize(value)?;
result.push(SupportedResources::DaemonSet(daemonset))
}
(Some(api_version), Some(kind)) if
api_version == <Ingress as Resource>::API_VERSION &&
kind == <Ingress as Resource>::KIND =>
{
let ingress: Ingress = serde::Deserialize::deserialize(value)?;
result.push(SupportedResources::Ingress(ingress))
}
(Some(api_version), Some(kind)) if
api_version == <CronJob as Resource>::API_VERSION &&
kind == <CronJob as Resource>::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 == <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());
}
_ => {
return Err(anyhow!(format!("kind {:?}", kind)).context("unsupported resource type").into());
}
};
}
}
}
}
};
Ok(result)
}

Expand Down

0 comments on commit c078a74

Please sign in to comment.