|
40 | 40 | import io.javaoperatorsdk.operator.processing.event.ResourceID; |
41 | 41 | import io.javaoperatorsdk.operator.processing.event.source.informer.ManagedInformerEventSource; |
42 | 42 |
|
| 43 | +import static io.javaoperatorsdk.operator.ReconcilerUtilsInternal.compareResourceVersions; |
43 | 44 | import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getUID; |
44 | 45 | import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getVersion; |
45 | 46 |
|
@@ -604,56 +605,55 @@ public static <P extends HasMetadata> P addFinalizerWithSSA( |
604 | 605 | } |
605 | 606 | } |
606 | 607 |
|
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 | + } |
635 | 621 |
|
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 | + } |
649 | 636 |
|
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 | + } |
658 | 650 |
|
| 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 | + } |
659 | 659 | } |
0 commit comments