From d70f7345f3d7cf2d77825656f154272b1d28e77b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 28 Feb 2025 14:36:17 +0100 Subject: [PATCH] feat: dependent resource set controller flag on owner reference MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../dependent/AbstractDependentResource.java | 4 ++++ .../kubernetes/KubernetesDependentResource.java | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java index db69d8134b..0f56958c61 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java @@ -238,4 +238,8 @@ protected boolean creatable() { protected boolean updatable() { return updatable; } + + protected Boolean readonly() { + return !isCreatable() && !isUpdatable() && !isDeletable(); + } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java index a3373e2d6c..9f57242468 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java @@ -5,6 +5,8 @@ import java.util.Optional; import java.util.Set; +import io.fabric8.kubernetes.api.model.OwnerReference; +import io.fabric8.kubernetes.api.model.OwnerReferenceBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -171,7 +173,15 @@ protected Resource prepare(Context

context, R desired, P primary, String a protected void addReferenceHandlingMetadata(R desired, P primary) { if (addOwnerReference()) { ReconcilerUtils.checkIfCanAddOwnerReference(primary, desired); - desired.addOwnerReference(primary); + + OwnerReferenceBuilder ownerRef = new OwnerReferenceBuilder() + .withApiVersion(primary.getApiVersion()) + .withKind(primary.getKind()) + .withName(primary.getMetadata().getName()) + .withUid(primary.getMetadata().getUid()) + .withController(!readonly()); + + desired.addOwnerReference(ownerRef.build()); } else if (useNonOwnerRefBasedSecondaryToPrimaryMapping()) { addSecondaryToPrimaryMapperAnnotations(desired, primary); }