Skip to content

Commit c1adeb0

Browse files
committed
feat: customize mapping annotation in kubernetes dependent resource
Signed-off-by: Attila Mészáros <csviri@gmail.com>
1 parent c225f71 commit c1adeb0

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ protected void addReferenceHandlingMetadata(R desired, P primary) {
239239
if (addOwnerReference()) {
240240
desired.addOwnerReference(primary);
241241
} else if (useDefaultAnnotationsToIdentifyPrimary()) {
242-
addDefaultSecondaryToPrimaryMapperAnnotations(desired, primary);
242+
addSecondaryToPrimaryMapperAnnotations(desired, primary);
243243
}
244244
}
245245

@@ -273,13 +273,18 @@ private boolean useDefaultAnnotationsToIdentifyPrimary() {
273273
return !(this instanceof SecondaryToPrimaryMapper) && !garbageCollected && isCreatable();
274274
}
275275

276-
private void addDefaultSecondaryToPrimaryMapperAnnotations(R desired, P primary) {
276+
protected void addSecondaryToPrimaryMapperAnnotations(R desired, P primary) {
277+
addSecondaryToPrimaryMapperAnnotations(desired, primary, Mappers.DEFAULT_ANNOTATION_FOR_NAME,
278+
Mappers.DEFAULT_ANNOTATION_FOR_NAMESPACE);
279+
}
280+
281+
protected void addSecondaryToPrimaryMapperAnnotations(R desired, P primary, String nameKey,
282+
String namespaceKey) {
277283
var annotations = desired.getMetadata().getAnnotations();
278-
annotations.put(Mappers.DEFAULT_ANNOTATION_FOR_NAME, primary.getMetadata().getName());
284+
annotations.put(nameKey, primary.getMetadata().getName());
279285
var primaryNamespaces = primary.getMetadata().getNamespace();
280286
if (primaryNamespaces != null) {
281-
annotations.put(
282-
Mappers.DEFAULT_ANNOTATION_FOR_NAMESPACE, primary.getMetadata().getNamespace());
287+
annotations.put(namespaceKey, primary.getMetadata().getNamespace());
283288
}
284289
}
285290

0 commit comments

Comments
 (0)