Skip to content

Commit 487cf2a

Browse files
csvirimetacosm
authored andcommitted
Using Annotations to Identify primary for a secondary object if no owner reference can be added (#1197)
1 parent edde94d commit 487cf2a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ private SecondaryToPrimaryMapper<R> getSecondaryToPrimaryMapper() {
9191
}
9292
}
9393

94+
@SuppressWarnings("unchecked")
95+
private SecondaryToPrimaryMapper<R> getSecondaryToPrimaryMapper() {
96+
if (this instanceof SecondaryToPrimaryMapper) {
97+
return (SecondaryToPrimaryMapper<R>) this;
98+
} else if (garbageCollected) {
99+
return Mappers.fromOwnerReference();
100+
} else if (useDefaultAnnotationsToIdentifyPrimary()) {
101+
return Mappers.fromDefaultAnnotations();
102+
} else {
103+
throw new OperatorException("Provide a SecondaryToPrimaryMapper to associate " +
104+
"this resource with the primary resource. DependentResource: " + getClass().getName());
105+
}
106+
}
107+
94108
/**
95109
* Use to share informers between event more resources.
96110
*

0 commit comments

Comments
 (0)