Skip to content

Commit

Permalink
Merge branch '1336-circular' of github.com:defenseunicorns/pepr into …
Browse files Browse the repository at this point in the history
…1336-circular
  • Loading branch information
schaeferka committed Oct 28, 2024
2 parents 60c303e + 4abe4bb commit 492e0ce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lib/capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export class Capability implements CapabilityExport {
event: Event.Update,
finalizeCallback: async (update: InstanceType<T>, logger = aliasLogger) => {
Log.info(`Executing finalize action with alias: ${binding.alias || "no alias provided"}`);
await finalizeCallback(update, logger);
return await finalizeCallback(update, logger);
},
};
bindings.push(watchBinding);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export type ValidateActionResponse = {
export type FinalizeAction<T extends GenericClass, K extends KubernetesObject = InstanceType<T>> = (
update: K,
logger?: Logger,
) => Promise<void> | void;
) => Promise<boolean | void> | boolean | void;

export type FinalizeActionChain<T extends GenericClass> = {
/**
Expand Down
16 changes: 13 additions & 3 deletions src/lib/watch-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,22 @@ async function runBinding(binding: Binding, capabilityNamespaces: string[], igno
if (!obj.metadata?.deletionTimestamp) {
return;
}

let shouldRemoveFinalizer: boolean | void | undefined = true;
try {
await binding.finalizeCallback?.(obj);
shouldRemoveFinalizer = await binding.finalizeCallback?.(obj);

// irrespective of callback success / failure, remove pepr finalizer
// if not opt'ed out of / if in error state, remove pepr finalizer
} finally {
await removeFinalizer(binding, obj);
const peprFinal = "pepr.dev/finalizer";
const meta = obj.metadata!;
const resource = `${meta.namespace || "ClusterScoped"}/${meta.name}`;

// [ true, void, undefined ] SHOULD remove finalizer
// [ false ] should NOT remove finalizer
shouldRemoveFinalizer === false
? Log.debug({ obj }, `Skipping removal of finalizer '${peprFinal}' from '${resource}'`)
: await removeFinalizer(binding, obj);
}
} else {
await binding.watchCallback?.(obj, phase);
Expand Down

0 comments on commit 492e0ce

Please sign in to comment.