Skip to content

Commit 2c5102a

Browse files
authored
refactor patch (#49)
Signed-off-by: csviri <[email protected]>
1 parent 55aabde commit 2c5102a

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

Diff for: src/main/java/io/csviri/operator/resourceglue/reconciler/glue/GlueReconciler.java

+12-13
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ private Condition toCondition(ConditionSpec condition) {
238238
throw new IllegalStateException("Unknown condition: " + condition);
239239
}
240240

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

@@ -249,12 +248,7 @@ private void addFinalizersToParentResource(Glue primary, Context<Glue> context)
249248
if (!p.getMetadata().getFinalizers().contains(finalizer)) {
250249
var res = getResourceForSSAFrom(p);
251250
res.getMetadata().getFinalizers().add(finalizer);
252-
context.getClient().resource(res)
253-
.patch(new PatchContext.Builder()
254-
.withFieldManager(context.getControllerConfiguration().fieldManager())
255-
.withForce(true)
256-
.withPatchType(PatchType.SERVER_SIDE_APPLY)
257-
.build());
251+
patchResource(res, context);
258252
}
259253
});
260254
}
@@ -267,18 +261,23 @@ private void removeFinalizerForParent(Glue primary, Context<Glue> context) {
267261
String finalizer = parentFinalizer(primary.getMetadata().getName());
268262
if (p.getMetadata().getFinalizers().contains(finalizer)) {
269263
var res = getResourceForSSAFrom(p);
270-
context.getClient().resource(res)
271-
.patch(new PatchContext.Builder()
272-
.withFieldManager(context.getControllerConfiguration().fieldManager())
273-
.withForce(true)
274-
.withPatchType(PatchType.SERVER_SIDE_APPLY)
275-
.build());
264+
patchResource(res, context);
276265
}
277266
}, () -> log.warn(
278267
"Parent resource expected to be present on cleanup. Glue name: {} namespace: {}",
279268
primary.getMetadata().getName(), primary.getMetadata().getNamespace()));
280269
}
281270

271+
private GenericKubernetesResource patchResource(GenericKubernetesResource res,
272+
Context<Glue> context) {
273+
return context.getClient().resource(res)
274+
.patch(new PatchContext.Builder()
275+
.withFieldManager(context.getControllerConfiguration().fieldManager())
276+
.withForce(true)
277+
.withPatchType(PatchType.SERVER_SIDE_APPLY)
278+
.build());
279+
}
280+
282281
private Optional<GenericKubernetesResource> getParentRelatedResource(Glue primary,
283282
Context<Glue> context) {
284283
var parentRelated = primary.getSpec().getRelatedResources().stream()

0 commit comments

Comments
 (0)