Skip to content

Commit

Permalink
refactor patch
Browse files Browse the repository at this point in the history
Signed-off-by: csviri <[email protected]>
  • Loading branch information
csviri committed Apr 1, 2024
1 parent 55aabde commit d0f51e5
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ private Condition toCondition(ConditionSpec condition) {
throw new IllegalStateException("Unknown condition: " + condition);
}

// todo docs
private void addFinalizersToParentResource(Glue primary, Context<Glue> context) {
var parent = getParentRelatedResource(primary, context);

Expand All @@ -249,12 +248,7 @@ private void addFinalizersToParentResource(Glue primary, Context<Glue> 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);
}
});
}
Expand All @@ -267,18 +261,23 @@ private void removeFinalizerForParent(Glue primary, Context<Glue> 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<Glue> context) {
return context.getClient().resource(res)
.patch(new PatchContext.Builder()
.withFieldManager(context.getControllerConfiguration().fieldManager())
.withForce(true)
.withPatchType(PatchType.SERVER_SIDE_APPLY)
.build());
}

private Optional<GenericKubernetesResource> getParentRelatedResource(Glue primary,
Context<Glue> context) {
var parentRelated = primary.getSpec().getRelatedResources().stream()
Expand Down

0 comments on commit d0f51e5

Please sign in to comment.