From cb61356b33e8e0c956ff67a5e6abdd87d1c0d930 Mon Sep 17 00:00:00 2001 From: Eguo Wang Date: Wed, 24 Jan 2024 19:14:03 +0800 Subject: [PATCH] chore: Rename playbook task and status names --- Cargo.lock | 14 +++++------ Cargo.toml | 2 +- controllers/src/playbook_controller.rs | 2 +- workflow/src/playbook/{end.rs => cleanup.rs} | 14 +++++------ workflow/src/playbook/init.rs | 4 ++-- workflow/src/playbook/mod.rs | 18 +++++++------- .../src/playbook/{schedule.rs => resolve.rs} | 24 +++++++++---------- workflow/src/playbook/{perform.rs => run.rs} | 20 ++++++++-------- 8 files changed, 49 insertions(+), 49 deletions(-) rename workflow/src/playbook/{end.rs => cleanup.rs} (90%) rename workflow/src/playbook/{schedule.rs => resolve.rs} (87%) rename workflow/src/playbook/{perform.rs => run.rs} (87%) diff --git a/Cargo.lock b/Cargo.lock index 17c802d..47f3d27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,7 +62,7 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" [[package]] name = "amp-apiserver" -version = "0.8.3" +version = "0.8.4" dependencies = [ "amp-common", "amp-resources", @@ -122,7 +122,7 @@ dependencies = [ [[package]] name = "amp-controllers" -version = "0.8.3" +version = "0.8.4" dependencies = [ "amp-common", "amp-resolver", @@ -148,7 +148,7 @@ dependencies = [ [[package]] name = "amp-crdgen" -version = "0.8.3" +version = "0.8.4" dependencies = [ "amp-common", "clap", @@ -160,7 +160,7 @@ dependencies = [ [[package]] name = "amp-resolver" -version = "0.8.3" +version = "0.8.4" dependencies = [ "amp-common", "amp-resources", @@ -174,7 +174,7 @@ dependencies = [ [[package]] name = "amp-resources" -version = "0.8.3" +version = "0.8.4" dependencies = [ "amp-common", "anyhow", @@ -194,7 +194,7 @@ dependencies = [ [[package]] name = "amp-syncer" -version = "0.8.3" +version = "0.8.4" dependencies = [ "amp-common", "async-nats", @@ -211,7 +211,7 @@ dependencies = [ [[package]] name = "amp-workflow" -version = "0.8.3" +version = "0.8.4" dependencies = [ "amp-common", "amp-resolver", diff --git a/Cargo.toml b/Cargo.toml index eb5580a..c916536 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace.package] -version = "0.8.3" +version = "0.8.4" edition = "2021" license = "Apache-2.0" repository = "https://github.com/amphitheatre-app/amphitheatre" diff --git a/controllers/src/playbook_controller.rs b/controllers/src/playbook_controller.rs index 567d26b..1c12735 100644 --- a/controllers/src/playbook_controller.rs +++ b/controllers/src/playbook_controller.rs @@ -71,7 +71,7 @@ pub async fn reconcile(playbook: Arc, ctx: Arc) -> Result { info!("Cleanup playbook {}", playbook.name_any()); workflow.set_context(playbook.clone()); - workflow.transition(Box::new(amp_workflow::playbook::EndingState)); + workflow.transition(Box::new(amp_workflow::playbook::CleanupState)); } }; diff --git a/workflow/src/playbook/end.rs b/workflow/src/playbook/cleanup.rs similarity index 90% rename from workflow/src/playbook/end.rs rename to workflow/src/playbook/cleanup.rs index 032ee99..9fc2b64 100644 --- a/workflow/src/playbook/end.rs +++ b/workflow/src/playbook/cleanup.rs @@ -19,14 +19,14 @@ use async_trait::async_trait; use kube::ResourceExt; use tracing::info; -pub struct EndingState; +pub struct CleanupState; #[async_trait] -impl State for EndingState { +impl State for CleanupState { /// Execute the logic for the ending state async fn handle(&self, ctx: &Context) -> Option>> { // Check if EndTask should be executed - let task = EndTask::new(); + let task = CleanupTask::new(); if task.matches(ctx) { if let Err(err) = task.execute(ctx).await { // Handle error, maybe log it @@ -38,12 +38,12 @@ impl State for EndingState { } } -pub struct EndTask; +pub struct CleanupTask; #[async_trait] -impl Task for EndTask { +impl Task for CleanupTask { fn new() -> Self { - EndTask + CleanupTask } fn matches(&self, _: &Context) -> bool { @@ -57,7 +57,7 @@ impl Task for EndTask { } } -impl EndTask { +impl CleanupTask { async fn cleanup(&self, ctx: &Context, playbook: &Playbook) -> Result<()> { // Try to delete the NATS stream for this playbook if it exists. if ctx.jetstream.delete_stream(playbook.name_any()).await.is_ok() { diff --git a/workflow/src/playbook/init.rs b/workflow/src/playbook/init.rs index f46af2e..3f1036f 100644 --- a/workflow/src/playbook/init.rs +++ b/workflow/src/playbook/init.rs @@ -24,7 +24,7 @@ use async_trait::async_trait; use kube::ResourceExt; use tracing::{debug, error, info}; -use super::SchedulingState; +use super::ResolvingState; pub struct InitialState; @@ -41,7 +41,7 @@ impl State for InitialState { } // Transition to the next state if needed - Some(Box::new(SchedulingState)) + Some(Box::new(ResolvingState)) } } diff --git a/workflow/src/playbook/mod.rs b/workflow/src/playbook/mod.rs index 6c278c1..1bd379b 100644 --- a/workflow/src/playbook/mod.rs +++ b/workflow/src/playbook/mod.rs @@ -16,14 +16,14 @@ mod init; pub use init::InitTask; pub use init::InitialState; -mod schedule; -pub use schedule::ScheduleTask; -pub use schedule::SchedulingState; +mod resolve; +pub use resolve::ResolveTask; +pub use resolve::ResolvingState; -mod perform; -pub use perform::PerformTask; -pub use perform::PerformingState; +mod run; +pub use run::RunTask; +pub use run::RunningState; -mod end; -pub use end::EndTask; -pub use end::EndingState; +mod cleanup; +pub use cleanup::CleanupState; +pub use cleanup::CleanupTask; diff --git a/workflow/src/playbook/schedule.rs b/workflow/src/playbook/resolve.rs similarity index 87% rename from workflow/src/playbook/schedule.rs rename to workflow/src/playbook/resolve.rs index 931303d..c05e6c8 100644 --- a/workflow/src/playbook/schedule.rs +++ b/workflow/src/playbook/resolve.rs @@ -23,47 +23,47 @@ use async_trait::async_trait; use std::collections::HashSet; use tracing::{debug, info}; -use super::PerformingState; +use super::RunningState; -pub struct SchedulingState; +pub struct ResolvingState; #[async_trait] -impl State for SchedulingState { +impl State for ResolvingState { /// Execute the logic for the scheduling state async fn handle(&self, ctx: &Context) -> Option>> { - // Check if ScheduleTask should be executed - let task = ScheduleTask::new(); + // Check if ResolveTask should be executed + let task = ResolveTask::new(); if task.matches(ctx) { if let Err(err) = task.execute(ctx).await { // Handle error, maybe log it - println!("Error during ScheduleTask execution: {}", err); + println!("Error during ResolveTask execution: {}", err); } } // Transition to the next state if needed - Some(Box::new(PerformingState)) + Some(Box::new(RunningState)) } } -pub struct ScheduleTask; +pub struct ResolveTask; #[async_trait] -impl Task for ScheduleTask { +impl Task for ResolveTask { fn new() -> Self { - ScheduleTask + ResolveTask } fn matches(&self, ctx: &Context) -> bool { ctx.object.status.as_ref().is_some_and(|status| status.resolving()) } - // Execute the task logic for InitTask using shared data + // Execute the task logic for ResolveTask using shared data async fn execute(&self, ctx: &Context) -> Result<()> { self.resolve(ctx, &ctx.object).await } } -impl ScheduleTask { +impl ResolveTask { async fn resolve(&self, ctx: &Context, playbook: &Playbook) -> Result<()> { // Check if there are any repositories to fetch // diff --git a/workflow/src/playbook/perform.rs b/workflow/src/playbook/run.rs similarity index 87% rename from workflow/src/playbook/perform.rs rename to workflow/src/playbook/run.rs index 8efbdfd..5ba4606 100644 --- a/workflow/src/playbook/perform.rs +++ b/workflow/src/playbook/run.rs @@ -20,18 +20,18 @@ use amp_resources::actor; use async_trait::async_trait; use tracing::{error, info}; -pub struct PerformingState; +pub struct RunningState; #[async_trait] -impl State for PerformingState { - /// Execute the logic for the performing state +impl State for RunningState { + /// Execute the logic for the Running state async fn handle(&self, ctx: &Context) -> Option>> { - // Check if PerformTask should be executed - let task = PerformTask::new(); + // Check if RunTask should be executed + let task = RunTask::new(); if task.matches(ctx) { if let Err(err) = task.execute(ctx).await { // Handle error, maybe log it - println!("Error during PerformTask execution: {}", err); + println!("Error during RunTask execution: {}", err); } } @@ -39,12 +39,12 @@ impl State for PerformingState { } } -pub struct PerformTask; +pub struct RunTask; #[async_trait] -impl Task for PerformTask { +impl Task for RunTask { fn new() -> Self { - PerformTask + RunTask } fn matches(&self, ctx: &Context) -> bool { @@ -56,7 +56,7 @@ impl Task for PerformTask { } } -impl PerformTask { +impl RunTask { async fn run(&self, ctx: &Context, playbook: &Playbook) -> Result<()> { let credentials = ctx.credentials.read().await;