Skip to content

Commit 06b4be6

Browse files
committed
Fixing breaking unit test with proposed changes to IsConsideredHealthy and getWorkerPeersResponse for issue #251
1 parent 450e787 commit 06b4be6

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

pkg/apicheck/check.go

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ func (c *ApiConnectivityCheck) Start(ctx context.Context) error {
168168
}
169169

170170
// isConsideredHealthy keeps track of the number of errors reported, and when a certain amount of error occur within a certain
171-
// time, ask peers if this node is healthy. Returns if the node is considered to be healthy or not.
171+
// time, ask peers if this node is healthy. Returns if the node is considered to be healthy or not. It is usable
172+
// whether this is a control plane node or a worker node
172173
func (c *ApiConnectivityCheck) isConsideredHealthy() bool {
174+
173175
isControlPlaneManagerNil := c.controlPlaneManager == nil
174176

175177
isWorkerNode := isControlPlaneManagerNil || !c.controlPlaneManager.IsControlPlane()
@@ -178,31 +180,52 @@ func (c *ApiConnectivityCheck) isConsideredHealthy() bool {
178180
"isControlPlaneManagerNil", isControlPlaneManagerNil,
179181
"isWorkerNode", isWorkerNode)
180182

181-
workerPeersResponse := c.getWorkerPeersResponse()
183+
var peersResponse peers.Response
182184

183185
if isWorkerNode {
184-
c.config.Log.Info("isConsideredHealthy: returning result from getWorkerPeersResponse",
185-
"workerPeersResponse.IsHealthy", workerPeersResponse.IsHealthy)
186-
return workerPeersResponse.IsHealthy
186+
peersResponse = c.getPeersResponse(peers.Worker)
187+
187188
} else {
188-
canOtherControlPlanesBeReached := c.canOtherControlPlanesBeReached()
189-
isControlPlaneHealthy := c.controlPlaneManager.IsControlPlaneHealthy(workerPeersResponse, canOtherControlPlanesBeReached)
190-
c.config.Log.Info("isConsideredHealthy: returning result from IsControlPlaneHealthy",
191-
"c.canOtherControlPlanesBeReached()", canOtherControlPlanesBeReached,
192-
"c.controlPlaneManager.IsControlPlaneHealthy", isControlPlaneHealthy)
193-
return isControlPlaneHealthy
189+
// MES: On a control plane node, when it can reach the other nodes, and the control plane is healthy,
190+
// that's overriding any sort of peer response from them
191+
192+
//canOtherControlPlanesBeReached := c.canOtherControlPlanesBeReached()
193+
peersResponse = c.getPeersResponse(peers.ControlPlane)
194+
195+
// MES: This does not appear to have any actual relevance. To me, it appears that all the necessary
196+
// logic is contained in getPeersResponse(peers.ControlPlane)
197+
//isControlPlaneHealthy := c.controlPlaneManager.IsControlPlaneHealthy(controlPlanePeersResponse,
198+
// canOtherControlPlanesBeReached)
199+
200+
//c.config.Log.Info("isConsideredHealthy: returning result from IsControlPlaneHealthy",
201+
// "c.canOtherControlPlanesBeReached()", canOtherControlPlanesBeReached,
202+
// "c.controlPlaneManager.IsControlPlaneHealthy", isControlPlaneHealthy)
203+
//return isControlPlaneHealthy
204+
205+
//c.config.Log.Info("isConsideredHealthy: returning result from getPeersResponse",
206+
// "workerPeersResponse.IsHealthy", workerPeersResponse.IsHealthy)
207+
//return workerPeersResponse.IsHealthy
194208
}
195209

210+
c.config.Log.Info("isConsideredHealthy: returning result from getPeersResponse",
211+
"workerPeersResponse.IsHealthy", peersResponse.IsHealthy)
212+
213+
return peersResponse.IsHealthy
214+
196215
}
197216

198-
func (c *ApiConnectivityCheck) getWorkerPeersResponse() peers.Response {
217+
func (c *ApiConnectivityCheck) getPeersResponse(role peers.Role) peers.Response {
199218
c.errorCount++
200219
if c.errorCount < c.config.MaxErrorsThreshold {
201220
c.config.Log.Info("Ignoring api-server error, error count below threshold", "current count", c.errorCount, "threshold", c.config.MaxErrorsThreshold)
202221
return peers.Response{IsHealthy: true, Reason: peers.HealthyBecauseErrorsThresholdNotReached}
203222
}
223+
c.config.Log.Info("Error count was above threshold, we will continue and attempt to get the addressess" +
224+
" for our peers, I consider myself a WORKER at the moment")
204225

205-
peersToAsk := c.config.Peers.GetPeersAddresses(peers.Worker)
226+
// MES: This gets called even if the current node is a control plane node. Hopefully
227+
// in an actual environment it is returning actual worker peers
228+
peersToAsk := c.config.Peers.GetPeersAddresses(role)
206229

207230
c.config.Log.Info("Error count exceeds threshold, trying to ask other peer nodes if I'm healthy",
208231
"minPeersRequired", c.config.MinPeersForRemediation, "actualNumPeersFound", len(peersToAsk))

0 commit comments

Comments
 (0)