Skip to content

Commit

Permalink
feature: add from first reference to ResourceID too (#846)
Browse files Browse the repository at this point in the history
  • Loading branch information
csviri authored Jan 19, 2022
1 parent c43965e commit e5c3c71
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ public static ResourceID fromResource(HasMetadata resource) {
resource.getMetadata().getNamespace());
}

public static Optional<ResourceID> fromFirstOwnerReference(HasMetadata resource) {
var ownerReferences = resource.getMetadata().getOwnerReferences();
if (!ownerReferences.isEmpty()) {
return Optional.of(new ResourceID(ownerReferences.get(0).getName(),
resource.getMetadata().getNamespace()));
} else {
return Optional.empty();
}
}

private final String name;
private final String namespace;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,8 @@ public static <T extends HasMetadata> PrimaryResourcesRetriever<T> fromLabel(
}

public static <T extends HasMetadata> PrimaryResourcesRetriever<T> fromOwnerReference() {
return resource -> {
var ownerReferences = resource.getMetadata().getOwnerReferences();
if (!ownerReferences.isEmpty()) {
return Set.of(new ResourceID(ownerReferences.get(0).getName(),
resource.getMetadata().getNamespace()));
} else {
return Collections.emptySet();
}
};
return resource -> ResourceID.fromFirstOwnerReference(resource).map(Set::of)
.orElse(Collections.emptySet());
}

private static <T extends HasMetadata> PrimaryResourcesRetriever<T> fromMetadata(
Expand Down

0 comments on commit e5c3c71

Please sign in to comment.