diff --git a/src/main/java/io/csviri/operator/resourceglue/reconciler/glue/GlueReconciler.java b/src/main/java/io/csviri/operator/resourceglue/reconciler/glue/GlueReconciler.java index 010abe1..96c2ae0 100644 --- a/src/main/java/io/csviri/operator/resourceglue/reconciler/glue/GlueReconciler.java +++ b/src/main/java/io/csviri/operator/resourceglue/reconciler/glue/GlueReconciler.java @@ -238,7 +238,6 @@ private Condition toCondition(ConditionSpec condition) { throw new IllegalStateException("Unknown condition: " + condition); } - // todo docs private void addFinalizersToParentResource(Glue primary, Context context) { var parent = getParentRelatedResource(primary, context); @@ -249,12 +248,7 @@ private void addFinalizersToParentResource(Glue primary, Context context) if (!p.getMetadata().getFinalizers().contains(finalizer)) { var res = getResourceForSSAFrom(p); res.getMetadata().getFinalizers().add(finalizer); - context.getClient().resource(res) - .patch(new PatchContext.Builder() - .withFieldManager(context.getControllerConfiguration().fieldManager()) - .withForce(true) - .withPatchType(PatchType.SERVER_SIDE_APPLY) - .build()); + patchResource(res, context); } }); } @@ -267,18 +261,23 @@ private void removeFinalizerForParent(Glue primary, Context context) { String finalizer = parentFinalizer(primary.getMetadata().getName()); if (p.getMetadata().getFinalizers().contains(finalizer)) { var res = getResourceForSSAFrom(p); - context.getClient().resource(res) - .patch(new PatchContext.Builder() - .withFieldManager(context.getControllerConfiguration().fieldManager()) - .withForce(true) - .withPatchType(PatchType.SERVER_SIDE_APPLY) - .build()); + patchResource(res, context); } }, () -> log.warn( "Parent resource expected to be present on cleanup. Glue name: {} namespace: {}", primary.getMetadata().getName(), primary.getMetadata().getNamespace())); } + private GenericKubernetesResource patchResource(GenericKubernetesResource res, + Context context) { + return context.getClient().resource(res) + .patch(new PatchContext.Builder() + .withFieldManager(context.getControllerConfiguration().fieldManager()) + .withForce(true) + .withPatchType(PatchType.SERVER_SIDE_APPLY) + .build()); + } + private Optional getParentRelatedResource(Glue primary, Context context) { var parentRelated = primary.getSpec().getRelatedResources().stream()