From 496626fdf84916e56ad7ccc16c8a27eacbbf46af Mon Sep 17 00:00:00 2001 From: Eguo Wang Date: Wed, 24 Jan 2024 18:49:12 +0800 Subject: [PATCH] refactor: remove event recorder from actor controllers --- Cargo.lock | 14 ++++++------ Cargo.toml | 2 +- controllers/src/actor_controller.rs | 17 ++++++--------- controllers/src/context.rs | 6 ------ resources/src/event.rs | 33 ----------------------------- resources/src/lib.rs | 1 - 6 files changed, 15 insertions(+), 58 deletions(-) delete mode 100644 resources/src/event.rs diff --git a/Cargo.lock b/Cargo.lock index 00f4633..17c802d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,7 +62,7 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" [[package]] name = "amp-apiserver" -version = "0.8.2" +version = "0.8.3" dependencies = [ "amp-common", "amp-resources", @@ -122,7 +122,7 @@ dependencies = [ [[package]] name = "amp-controllers" -version = "0.8.2" +version = "0.8.3" dependencies = [ "amp-common", "amp-resolver", @@ -148,7 +148,7 @@ dependencies = [ [[package]] name = "amp-crdgen" -version = "0.8.2" +version = "0.8.3" dependencies = [ "amp-common", "clap", @@ -160,7 +160,7 @@ dependencies = [ [[package]] name = "amp-resolver" -version = "0.8.2" +version = "0.8.3" dependencies = [ "amp-common", "amp-resources", @@ -174,7 +174,7 @@ dependencies = [ [[package]] name = "amp-resources" -version = "0.8.2" +version = "0.8.3" dependencies = [ "amp-common", "anyhow", @@ -194,7 +194,7 @@ dependencies = [ [[package]] name = "amp-syncer" -version = "0.8.2" +version = "0.8.3" dependencies = [ "amp-common", "async-nats", @@ -211,7 +211,7 @@ dependencies = [ [[package]] name = "amp-workflow" -version = "0.8.2" +version = "0.8.3" dependencies = [ "amp-common", "amp-resolver", diff --git a/Cargo.toml b/Cargo.toml index cd98f7b..eb5580a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/controllers/src/actor_controller.rs b/controllers/src/actor_controller.rs index 4129ed9..dcd0501 100644 --- a/controllers/src/actor_controller.rs +++ b/controllers/src/actor_controller.rs @@ -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; @@ -53,14 +51,13 @@ pub async fn reconcile(actor: Arc, ctx: Arc) -> Result { let ns = actor.namespace().unwrap(); // actor is namespace scoped let api: Api = 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 @@ -73,8 +70,8 @@ pub fn error_policy(_actor: Arc, error: &Error, _ctx: Arc) -> Ac Action::requeue(Duration::from_secs(60)) } -async fn apply(actor: &Actor, ctx: &Arc, recorder: &Recorder) -> Result { - trace(recorder, format!("Try to deploying the resources for Actor {}", actor.name_any())).await; +async fn apply(actor: &Actor, ctx: &Arc) -> Result { + 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); @@ -83,7 +80,7 @@ async fn apply(actor: &Actor, ctx: &Arc, recorder: &Recorder) -> Result Ok(Action::await_change()) } -pub async fn cleanup(actor: &Actor, ctx: &Arc, recorder: &Recorder) -> Result { +pub async fn cleanup(actor: &Actor, ctx: &Arc) -> Result { let namespace = actor.namespace().unwrap(); let api: Api = Api::all(ctx.k8s.clone()); @@ -94,7 +91,7 @@ pub async fn cleanup(actor: &Actor, ctx: &Arc, recorder: &Recorder) -> } } - trace(recorder, format!("Delete Actor `{}`", actor.name_any())).await; + info!("Delete Actor `{}`", actor.name_any()); Ok(Action::await_change()) } diff --git a/controllers/src/context.rs b/controllers/src/context.rs index 85c62af..3b6247f 100644 --- a/controllers/src/context.rs +++ b/controllers/src/context.rs @@ -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; @@ -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) - } } diff --git a/resources/src/event.rs b/resources/src/event.rs deleted file mode 100644 index 27e8cc6..0000000 --- a/resources/src/event.rs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) The Amphitheatre Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use kube::runtime::events::{Event, EventType, Recorder}; -use tracing::{error, info}; - -pub async fn trace(recorder: &Recorder, message: impl Into) { - let message: String = message.into(); - info!("{}", message); - - let event = Event { - type_: EventType::Normal, - reason: "Tracing".into(), - note: Some(message), - action: "Reconciling".into(), - secondary: None, - }; - - if let Err(err) = recorder.publish(event).await { - error!("Failed to publish event: {}", err); - } -} diff --git a/resources/src/lib.rs b/resources/src/lib.rs index 683fd47..b0b7c41 100644 --- a/resources/src/lib.rs +++ b/resources/src/lib.rs @@ -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;