Skip to content

Commit

Permalink
fix: owner check redundant (#51)
Browse files Browse the repository at this point in the history
Signed-off-by: csviri <[email protected]>
  • Loading branch information
csviri authored Apr 1, 2024
1 parent 2c5102a commit 6873084
Showing 1 changed file with 0 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@
import io.fabric8.kubernetes.client.dsl.base.PatchContext;
import io.fabric8.kubernetes.client.dsl.base.PatchType;
import io.javaoperatorsdk.operator.api.reconciler.*;
import io.javaoperatorsdk.operator.processing.GroupVersionKind;
import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition;
import io.javaoperatorsdk.operator.processing.dependent.workflow.KubernetesResourceDeletedCondition;
import io.javaoperatorsdk.operator.processing.dependent.workflow.WorkflowBuilder;
import io.javaoperatorsdk.operator.processing.event.ResourceID;
import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource;

import static io.csviri.operator.resourceglue.Utils.getResourceForSSAFrom;
import static io.csviri.operator.resourceglue.reconciler.operator.GlueOperatorReconciler.PARENT_RELATED_RESOURCE_NAME;
Expand Down Expand Up @@ -65,9 +62,6 @@ public UpdateControl<Glue> reconcile(Glue primary,
return UpdateControl.noUpdate();
}
addFinalizersToParentResource(primary, context);
if (ownersBeingDeleted(primary, context)) {
return UpdateControl.noUpdate();
}
var actualWorkflow = buildWorkflowAndRegisterInformers(primary, context);
var result = actualWorkflow.reconcile(primary, context);
cleanupRemovedResourcesFromWorkflow(context, primary);
Expand All @@ -86,33 +80,6 @@ private boolean deletedGlueIfParentMarkedForDeletion(Context<Glue> context, Glue
}
}


/**
* If a parent gets deleted, the glue is reconciled still, but we don't want that in that case.
* Glue us deleted / marked for deleted eventually by the garbage collector but want to make the
* best effort to prevent that.
*/
private boolean ownersBeingDeleted(Glue primary, Context<Glue> context) {
if (primary.getMetadata().getOwnerReferences().isEmpty()) {
return false;
}

var res = !primary.getMetadata().getOwnerReferences().stream().anyMatch(or -> {
var gvk = new GroupVersionKind(or.getApiVersion(), or.getKind());
var es = (InformerEventSource<GenericKubernetesResource, Glue>) context.eventSourceRetriever()
.getResourceEventSourceFor(GenericKubernetesResource.class, gvk.toString());
var resource = es.get(new ResourceID(or.getName(), primary.getMetadata().getNamespace()));
return resource.map(r -> r.getMetadata().getDeletionTimestamp() == null).orElse(false);

});
if (res) {
log.debug("Skipping reconciliation since glue owners being deleted, name: {} namespace: {}",
primary.getMetadata().getName(),
primary.getMetadata().getNamespace());
}
return res;
}

@Override
public DeleteControl cleanup(Glue primary, Context<Glue> context) {

Expand Down

0 comments on commit 6873084

Please sign in to comment.