Skip to content

Commit

Permalink
refactor: remove event recorder from actor controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
wangeguo committed Jan 24, 2024
1 parent 43bbad1 commit 496626f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 58 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "0.8.2"
version = "0.8.3"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/amphitheatre-app/amphitheatre"
Expand Down
17 changes: 7 additions & 10 deletions controllers/src/actor_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ use std::time::Duration;

use amp_common::resource::Actor;
use amp_resources::deployer::Deployer;
use amp_resources::event::trace;
use futures::{future, StreamExt};
use k8s_openapi::api::core::v1::Namespace;
use kube::api::ListParams;
use kube::runtime::controller::Action;
use kube::runtime::events::Recorder;
use kube::runtime::finalizer::{finalizer, Event as FinalizerEvent};
use kube::runtime::{watcher, Controller};
use kube::{Api, Resource, ResourceExt};
use kube::{Api, ResourceExt};
use tracing::{error, info};

use crate::context::Context;
Expand Down Expand Up @@ -53,14 +51,13 @@ pub async fn reconcile(actor: Arc<Actor>, ctx: Arc<Context>) -> Result<Action> {

let ns = actor.namespace().unwrap(); // actor is namespace scoped
let api: Api<Actor> = Api::namespaced(ctx.k8s.clone(), &ns);
let recorder = ctx.recorder(actor.object_ref(&()));

// Reconcile the actor custom resource.
let finalizer_name = "actors.amphitheatre.app/finalizer";
finalizer(&api, finalizer_name, actor, |event| async {
match event {
FinalizerEvent::Apply(actor) => apply(&actor, &ctx, &recorder).await,
FinalizerEvent::Cleanup(actor) => cleanup(&actor, &ctx, &recorder).await,
FinalizerEvent::Apply(actor) => apply(&actor, &ctx).await,
FinalizerEvent::Cleanup(actor) => cleanup(&actor, &ctx).await,
}
})
.await
Expand All @@ -73,8 +70,8 @@ pub fn error_policy(_actor: Arc<Actor>, error: &Error, _ctx: Arc<Context>) -> Ac
Action::requeue(Duration::from_secs(60))
}

async fn apply(actor: &Actor, ctx: &Arc<Context>, recorder: &Recorder) -> Result<Action> {
trace(recorder, format!("Try to deploying the resources for Actor {}", actor.name_any())).await;
async fn apply(actor: &Actor, ctx: &Arc<Context>) -> Result<Action> {
info!("Try to deploying the resources for Actor {}", actor.name_any());

let credentials = ctx.credentials.read().await;
let mut deployer = Deployer::new(ctx.k8s.clone(), &credentials, actor);
Expand All @@ -83,7 +80,7 @@ async fn apply(actor: &Actor, ctx: &Arc<Context>, recorder: &Recorder) -> Result
Ok(Action::await_change())
}

pub async fn cleanup(actor: &Actor, ctx: &Arc<Context>, recorder: &Recorder) -> Result<Action> {
pub async fn cleanup(actor: &Actor, ctx: &Arc<Context>) -> Result<Action> {
let namespace = actor.namespace().unwrap();
let api: Api<Namespace> = Api::all(ctx.k8s.clone());

Expand All @@ -94,7 +91,7 @@ pub async fn cleanup(actor: &Actor, ctx: &Arc<Context>, recorder: &Recorder) ->
}
}

trace(recorder, format!("Delete Actor `{}`", actor.name_any())).await;
info!("Delete Actor `{}`", actor.name_any());

Ok(Action::await_change())
}
6 changes: 0 additions & 6 deletions controllers/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ use std::sync::Arc;
use amp_common::config::Credentials;
use amp_resources::credential;
use async_nats::jetstream;
use k8s_openapi::api::core::v1::ObjectReference;
use kube::runtime::events::Recorder;
use tokio::sync::RwLock;

use crate::config::Config;
Expand Down Expand Up @@ -57,8 +55,4 @@ impl Context {
jetstream: Arc::new(jetstream),
})
}

pub fn recorder(&self, reference: ObjectReference) -> Recorder {
Recorder::new(self.k8s.clone(), "amp-controllers".into(), reference)
}
}
33 changes: 0 additions & 33 deletions resources/src/event.rs

This file was deleted.

1 change: 0 additions & 1 deletion resources/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub mod credential;
pub mod deployer;
pub mod deployment;
pub mod error;
pub mod event;
pub mod namespace;
pub mod playbook;
pub mod secret;
Expand Down

0 comments on commit 496626f

Please sign in to comment.