Skip to content

Commit

Permalink
Merge pull request #315 from Kuadrant/gh-294-2
Browse files Browse the repository at this point in the history
probes unhealthy only if threshold exeeded
  • Loading branch information
maleck13 authored Nov 25, 2024
2 parents bf2d33b + 30ed77a commit bee684b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
16 changes: 7 additions & 9 deletions internal/controller/dnsrecord_healthchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,18 @@ func removeUnhealthyEndpoints(specEndpoints []*endpoint.Endpoint, dnsRecord *v1a

var haveHealthyProbes bool
for _, probe := range probes.Items {
// if the probe is healthy or unknown, continue to the next probe
// if the probe is healthy, continue to the next probe
if probe.Status.Healthy != nil && *probe.Status.Healthy {
haveHealthyProbes = true
continue
}

// if we exceeded a threshold or we haven't probed yet
if probe.Status.ConsecutiveFailures >= dnsRecord.Spec.HealthCheck.FailureThreshold || probe.Status.Healthy == nil {
//delete bad endpoint from all endpoints targets
tree.RemoveNode(&common.DNSTreeNode{
Name: probe.Spec.Address,
})
unhealthyAddresses = append(unhealthyAddresses, probe.Spec.Address)
}
// if unhealthy or we haven't probed yet
//delete bad endpoint from all endpoints targets
tree.RemoveNode(&common.DNSTreeNode{
Name: probe.Spec.Address,
})
unhealthyAddresses = append(unhealthyAddresses, probe.Spec.Address)

}

Expand Down
3 changes: 0 additions & 3 deletions internal/controller/dnsrecord_healthchecks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ var _ = Describe("DNSRecordReconciler_HealthChecks", func() {
if probe.Spec.Address == "172.32.200.1" {
probe.Status.Healthy = ptr.To(false)
probe.Status.LastCheckedAt = metav1.Now()
probe.Status.ConsecutiveFailures = dnsRecord.Spec.HealthCheck.FailureThreshold + 1
g.Expect(k8sClient.Status().Update(ctx, &probe)).To(Succeed())
updated = true
}
Expand Down Expand Up @@ -499,7 +498,6 @@ var _ = Describe("DNSRecordReconciler_HealthChecks", func() {
if probe.Spec.Address == "172.32.200.2" {
probe.Status.Healthy = ptr.To(false)
probe.Status.LastCheckedAt = metav1.Now()
probe.Status.ConsecutiveFailures = dnsRecord.Spec.HealthCheck.FailureThreshold + 1
g.Expect(k8sClient.Status().Update(ctx, &probe)).To(Succeed())
updated = true
}
Expand Down Expand Up @@ -585,7 +583,6 @@ var _ = Describe("DNSRecordReconciler_HealthChecks", func() {
if probe.Spec.Address == "172.32.200.1" {
probe.Status.Healthy = ptr.To(false)
probe.Status.LastCheckedAt = metav1.Now()
probe.Status.ConsecutiveFailures = dnsRecord.Spec.HealthCheck.FailureThreshold + 1
g.Expect(k8sClient.Status().Update(ctx, &probe)).To(Succeed())
updated = true
}
Expand Down
5 changes: 4 additions & 1 deletion internal/probes/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,14 @@ func (w *Probe) Start(clientctx context.Context, k8sClient client.Client, probe
freshProbe.Status.ObservedGeneration = freshProbe.Generation
if !probeResult.Healthy {
freshProbe.Status.ConsecutiveFailures++
if freshProbe.Status.ConsecutiveFailures > freshProbe.Spec.FailureThreshold {
freshProbe.Status.Healthy = &probeResult.Healthy
}
} else {
freshProbe.Status.ConsecutiveFailures = 0
freshProbe.Status.Healthy = &probeResult.Healthy
}
logger.V(1).Info("health: execution complete ", "result", probeResult, "checked at", probeResult.CheckedAt.String(), "previoud check at ", probeResult.PreviousCheck)
freshProbe.Status.Healthy = &probeResult.Healthy
freshProbe.Status.LastCheckedAt = probeResult.CheckedAt
freshProbe.Status.Reason = probeResult.Reason
freshProbe.Status.Status = probeResult.Status
Expand Down

0 comments on commit bee684b

Please sign in to comment.