Skip to content

Commit 5a5027a

Browse files
committed
wip
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent d145562 commit 5a5027a

File tree

2 files changed

+53
-50
lines changed

2 files changed

+53
-50
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ReconcileUtils.java

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import io.javaoperatorsdk.operator.processing.event.ResourceID;
4141
import io.javaoperatorsdk.operator.processing.event.source.informer.ManagedInformerEventSource;
4242

43+
import static io.javaoperatorsdk.operator.ReconcilerUtilsInternal.compareResourceVersions;
4344
import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getUID;
4445
import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getVersion;
4546

@@ -604,56 +605,55 @@ public static <P extends HasMetadata> P addFinalizerWithSSA(
604605
}
605606
}
606607

607-
/**
608-
* Returns a collector that deduplicates Kubernetes objects by keeping only the one with the
609-
* latest metadata.resourceVersion for each unique name and namespace combination. The intended
610-
* use case is for the rather rare setup when there are overlapping {@link
611-
* io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource}s for a
612-
* resource type.
613-
*
614-
* @param <T> the type of HasMetadata objects
615-
* @return a collector that produces a collection of deduplicated Kubernetes objects
616-
*/
617-
public static <T extends HasMetadata> Collector<T, ?, Collection<T>> latestDistinct() {
618-
return Collectors.collectingAndThen(latestDistinctToMap(), Map::values);
619-
}
620-
621-
/**
622-
* Returns a collector that deduplicates Kubernetes objects by keeping only the one with the
623-
* latest metadata.resourceVersion for each unique name and namespace combination. The intended
624-
* use case is for the rather rare setup when there are overlapping {@link
625-
* io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource}s for a
626-
* resource type.
627-
*
628-
* @param <T> the type of HasMetadata objects
629-
* @return a collector that produces a List of deduplicated Kubernetes objects
630-
*/
631-
public static <T extends HasMetadata> Collector<T, ?, List<T>> latestDistinctList() {
632-
return Collectors.collectingAndThen(
633-
latestDistinctToMap(), map -> new ArrayList<>(map.values()));
634-
}
608+
/**
609+
* Returns a collector that deduplicates Kubernetes objects by keeping only the one with the
610+
* latest metadata.resourceVersion for each unique name and namespace combination. The intended
611+
* use case is for the rather rare setup when there are overlapping {@link
612+
* io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource}s for a
613+
* resource type.
614+
*
615+
* @param <T> the type of HasMetadata objects
616+
* @return a collector that produces a collection of deduplicated Kubernetes objects
617+
*/
618+
public static <T extends HasMetadata> Collector<T, ?, Collection<T>> latestDistinct() {
619+
return Collectors.collectingAndThen(latestDistinctToMap(), Map::values);
620+
}
635621

636-
/**
637-
* Returns a collector that deduplicates Kubernetes objects by keeping only the one with the
638-
* latest metadata.resourceVersion for each unique name and namespace combination. The intended
639-
* use case is for the rather rare setup when there are overlapping {@link
640-
* io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource}s for a
641-
* resource type.
642-
*
643-
* @param <T> the type of HasMetadata objects
644-
* @return a collector that produces a Set of deduplicated Kubernetes objects
645-
*/
646-
public static <T extends HasMetadata> Collector<T, ?, Set<T>> latestDistinctSet() {
647-
return Collectors.collectingAndThen(latestDistinctToMap(), map -> new HashSet<>(map.values()));
648-
}
622+
/**
623+
* Returns a collector that deduplicates Kubernetes objects by keeping only the one with the
624+
* latest metadata.resourceVersion for each unique name and namespace combination. The intended
625+
* use case is for the rather rare setup when there are overlapping {@link
626+
* io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource}s for a
627+
* resource type.
628+
*
629+
* @param <T> the type of HasMetadata objects
630+
* @return a collector that produces a List of deduplicated Kubernetes objects
631+
*/
632+
public static <T extends HasMetadata> Collector<T, ?, List<T>> latestDistinctList() {
633+
return Collectors.collectingAndThen(
634+
latestDistinctToMap(), map -> new ArrayList<>(map.values()));
635+
}
649636

650-
private static <T extends HasMetadata> Collector<T, ?, Map<ResourceID, T>> latestDistinctToMap() {
651-
return Collectors.toMap(
652-
resource ->
653-
new ResourceID(resource.getMetadata().getName(), resource.getMetadata().getNamespace()),
654-
resource -> resource,
655-
(existing, replacement) ->
656-
compareResourceVersions(existing, replacement) >= 0 ? existing : replacement);
657-
}
637+
/**
638+
* Returns a collector that deduplicates Kubernetes objects by keeping only the one with the
639+
* latest metadata.resourceVersion for each unique name and namespace combination. The intended
640+
* use case is for the rather rare setup when there are overlapping {@link
641+
* io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource}s for a
642+
* resource type.
643+
*
644+
* @param <T> the type of HasMetadata objects
645+
* @return a collector that produces a Set of deduplicated Kubernetes objects
646+
*/
647+
public static <T extends HasMetadata> Collector<T, ?, Set<T>> latestDistinctSet() {
648+
return Collectors.collectingAndThen(latestDistinctToMap(), map -> new HashSet<>(map.values()));
649+
}
658650

651+
private static <T extends HasMetadata> Collector<T, ?, Map<ResourceID, T>> latestDistinctToMap() {
652+
return Collectors.toMap(
653+
resource ->
654+
new ResourceID(resource.getMetadata().getName(), resource.getMetadata().getNamespace()),
655+
resource -> resource,
656+
(existing, replacement) ->
657+
compareResourceVersions(existing, replacement) >= 0 ? existing : replacement);
658+
}
659659
}

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/ReconcileUtilsTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
import org.junit.jupiter.api.BeforeEach;
2626
import org.junit.jupiter.api.Test;
2727

28+
import io.fabric8.kubernetes.api.model.HasMetadata;
29+
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
30+
import io.fabric8.kubernetes.api.model.Pod;
31+
import io.fabric8.kubernetes.api.model.PodBuilder;
2832
import io.fabric8.kubernetes.client.KubernetesClient;
2933
import io.fabric8.kubernetes.client.KubernetesClientException;
3034
import io.fabric8.kubernetes.client.dsl.MixedOperation;
@@ -588,5 +592,4 @@ void latestDistinctSetHandlesEmptyStream() {
588592

589593
assertThat(result).isEmpty();
590594
}
591-
592595
}

0 commit comments

Comments
 (0)