From 6d441bd57efd482f81817f00d9473bbf9f1b3d07 Mon Sep 17 00:00:00 2001 From: Paulo Bressan Date: Tue, 2 Jan 2024 07:37:25 -0300 Subject: [PATCH] chore: remove kube finalizer (#6) --- .github/workflows/clippy.yml | 22 ++++++++++++++++++ operator/src/controller.rs | 44 ++++++++---------------------------- 2 files changed, 32 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/clippy.yml diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml new file mode 100644 index 0000000..a2d5d57 --- /dev/null +++ b/.github/workflows/clippy.yml @@ -0,0 +1,22 @@ +name: Clippy + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + lint: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./operator + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Clippy check lints + run: cargo clippy -- -D warnings diff --git a/operator/src/controller.rs b/operator/src/controller.rs index 7eba8bc..ed090c1 100644 --- a/operator/src/controller.rs +++ b/operator/src/controller.rs @@ -5,12 +5,7 @@ use crate::{ }; use futures::StreamExt; use kube::{ - runtime::{ - controller::Action, - finalizer::{finalizer, Event}, - watcher::Config as WatcherConfig, - Controller, - }, + runtime::{controller::Action, watcher::Config as WatcherConfig, Controller}, Api, Client, CustomResource, ResourceExt, }; use schemars::JsonSchema; @@ -64,24 +59,6 @@ pub struct KupoPortStatus { pub auth_token: Option, } -impl KupoPort { - async fn reconcile(&self, ctx: Arc) -> Result { - let client = ctx.client.clone(); - let namespace = self.namespace().unwrap(); - - let private_dns_service_name = - build_private_dns_service_name(&self.spec.network, self.spec.prune_utxo); - handle_reference_grant(client.clone(), &namespace, self, &private_dns_service_name).await?; - handle_http_route(client.clone(), &namespace, self, &private_dns_service_name).await?; - handle_auth(client.clone(), &namespace, self).await?; - Ok(Action::requeue(Duration::from_secs(5 * 60))) - } - - async fn cleanup(&self, _: Arc) -> Result { - Ok(Action::await_change()) - } -} - fn build_private_dns_service_name(network: &Network, prune_utxo: bool) -> String { if prune_utxo { return format!("kupo-{}-pruned", network); @@ -90,17 +67,16 @@ fn build_private_dns_service_name(network: &Network, prune_utxo: bool) -> String } async fn reconcile(crd: Arc, ctx: Arc) -> Result { - let ns = crd.namespace().unwrap(); - let crds: Api = Api::namespaced(ctx.client.clone(), &ns); + let client = ctx.client.clone(); + let namespace = crd.namespace().unwrap(); + + let private_dns_service_name = + build_private_dns_service_name(&crd.spec.network, crd.spec.prune_utxo); + handle_reference_grant(client.clone(), &namespace, &crd, &private_dns_service_name).await?; + handle_http_route(client.clone(), &namespace, &crd, &private_dns_service_name).await?; + handle_auth(client.clone(), &namespace, &crd).await?; - finalizer(&crds, KUPO_PORT_FINALIZER, crd, |event| async { - match event { - Event::Apply(crd) => crd.reconcile(ctx.clone()).await, - Event::Cleanup(crd) => crd.cleanup(ctx.clone()).await, - } - }) - .await - .map_err(|e| Error::FinalizerError(Box::new(e))) + Ok(Action::await_change()) } fn error_policy(crd: Arc, err: &Error, ctx: Arc) -> Action {