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

Fix the NodeLost pod's status #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var workloop = function workloop() {
//Lets remove any pods that aren't running or haven't been assigned an IP address yet
for (var i = pods.length - 1; i >= 0; i--) {
var pod = pods[i];
if (pod.status.phase !== 'Running' || !pod.status.podIP) {
if (pod.status.phase !== 'Running' || !pod.status.podIP || pod.status.reason === 'NodeLost') {
pods.splice(i, 1);
}
}
Expand Down Expand Up @@ -111,7 +111,7 @@ var inReplicaSet = function(db, pods, status, done) {
for (var i in members) {
var member = members[i];

if (member.state === 1) {
if (member.state === 1 && podIsAlive(member, pods)) {
if (member.self) {
return primaryWork(db, pods, members, false, done);
}
Expand Down Expand Up @@ -232,9 +232,6 @@ var addrToAddLoop = function(pods, members) {
var addrToAdd = [];
for (var i in pods) {
var pod = pods[i];
if (pod.status.phase !== 'Running') {
continue;
}

var podIpAddr = getPodIpAddressAndPort(pod);
var podStableNetworkAddr = getPodStableNetworkAddressAndPort(pod);
Expand Down Expand Up @@ -275,6 +272,11 @@ var memberShouldBeRemoved = function(member) {
&& moment().subtract(unhealthySeconds, 'seconds').isAfter(member.lastHeartbeatRecv);
};

var podIsAlive = function(member, pods) {
return pods.some(p => getPodIpAddressAndPort(p) == member.name
|| getPodStableNetworkAddressAndPort(p) == member.name)
}

/**
* @param pod this is the Kubernetes pod, containing the info.
* @returns string - podIp the pod's IP address with the port from config attached at the end. Example
Expand Down