Skip to content

Commit

Permalink
chore: remove kube finalizer (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulobressan authored Jan 2, 2024
1 parent ba1ebc5 commit 6d441bd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 34 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -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
44 changes: 10 additions & 34 deletions operator/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,24 +59,6 @@ pub struct KupoPortStatus {
pub auth_token: Option<String>,
}

impl KupoPort {
async fn reconcile(&self, ctx: Arc<Context>) -> Result<Action> {
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<Context>) -> Result<Action> {
Ok(Action::await_change())
}
}

fn build_private_dns_service_name(network: &Network, prune_utxo: bool) -> String {
if prune_utxo {
return format!("kupo-{}-pruned", network);
Expand All @@ -90,17 +67,16 @@ fn build_private_dns_service_name(network: &Network, prune_utxo: bool) -> String
}

async fn reconcile(crd: Arc<KupoPort>, ctx: Arc<Context>) -> Result<Action> {
let ns = crd.namespace().unwrap();
let crds: Api<KupoPort> = 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<KupoPort>, err: &Error, ctx: Arc<Context>) -> Action {
Expand Down

0 comments on commit 6d441bd

Please sign in to comment.