Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track kubernetes record status based on available pods #159

Closed
wants to merge 3 commits into from
Closed

Track kubernetes record status based on available pods #159

wants to merge 3 commits into from

Conversation

rgmz
Copy link

@rgmz rgmz commented Oct 24, 2021

This fixes #148.

@tsegismont The scope of this PR is admittedly larger than I would like; I found myself re-organizing the existing code to get a better understanding of its function.

This is a first attempt at implementing #148, missing tests coverage, and could no doubt be improved. Let me know your thoughts on the general approach.


Using 3 maps to track service selectors, service's active pods, and the sevices per pod feels sub-optimal, but the intention was to avoid calculating everything on the fly:

private final Map<RecordKey, ServiceSelector> selectorsByService = new HashMap<>();
private final Map<RecordKey, List<String>> runningPodsByService = new HashMap<>();
private final Map<String, List<RecordKey>> servicesByPod = new HashMap<>();

The way that service status is updated also feels like it could be better (more reactive). For busier k8s instances, simply checking the size of the lists after modification may not work (concurrent modification). Ideally, we'd hook into the changes in the lists and update the services based on that.

List<String> runningPods = runningPodsByService.computeIfAbsent(key, k -> new ArrayList<>());
runningPods.add(podId);
servicesByPod.computeIfAbsent(podId, k -> new ArrayList<>())
.add(key);
if (runningPods.size() == 1) {
return updateRecordStatus(key, Status.UP);
} else {

List<RecordKey> keys = servicesByPod.remove(podId);
keys.forEach(key -> {
List<String> runningPods = runningPodsByService.get(key);
runningPods.remove(podId);
if (runningPods.isEmpty()) {
updates.add(updateRecordStatus(key, Status.OUT_OF_SERVICE));
}

To-do:

  • Handle events for pod watch (BOOKMARK, etc.)
  • Add/fix tests
  • Remove unnecessary classes
  • Fix up Java Doc

@tsegismont tsegismont self-assigned this Oct 25, 2021
@tsegismont tsegismont added this to the 4.3.0 milestone Oct 25, 2021
@tsegismont tsegismont removed this from the 4.3.4 milestone Sep 30, 2022
@tsegismont
Copy link
Contributor

Hi @rgmz , sorry this went out my radar... Are you able to resume your work on this?

@rgmz rgmz closed this by deleting the head repository Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

[Kubernetes] Track status of service based on pod events Inbox
2 participants