Skip to content

Commit

Permalink
compute health of applications only once (#1777)
Browse files Browse the repository at this point in the history
While investigating how we can add metric based health checks (for #1745) I noticed that we compute health checks twice.
This PR reduces it to a single call.

Signed-off-by: Andre Aguas <andre.aguas@protonmail.com>
  • Loading branch information
abaguas authored Dec 9, 2024
1 parent 76ecfcb commit 275c4f3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
9 changes: 2 additions & 7 deletions controllers/dnsupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,9 @@ func (r *GslbReconciler) gslbDNSEndpoint(gslb *k8gbv1beta1.Gslb) (*externaldns.D
var gslbHosts []*externaldns.Endpoint
var ttl = externaldns.TTL(gslb.Spec.Strategy.DNSTtlSeconds)

serviceHealth, err := r.getServiceHealthStatus(gslb)
if err != nil {
return nil, err
}

localTargets := gslb.Status.LoadBalancer.ExposedIPs

for host, health := range serviceHealth {
for host, health := range gslb.Status.ServiceHealth {
var finalTargets = assistant.NewTargets()

if !strings.Contains(host, r.Config.EdgeDNSZone) {
Expand Down Expand Up @@ -149,7 +144,7 @@ func (r *GslbReconciler) gslbDNSEndpoint(gslb *k8gbv1beta1.Gslb) (*externaldns.D
Spec: dnsEndpointSpec,
}

err = controllerutil.SetControllerReference(gslb, dnsEndpoint, r.Scheme)
err := controllerutil.SetControllerReference(gslb, dnsEndpoint, r.Scheme)
if err != nil {
return nil, err
}
Expand Down
8 changes: 8 additions & 0 deletions controllers/gslb_controller_reconciliation.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ func (r *GslbReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
Str("gslb", gslb.Name).
Msg("Resolved LoadBalancer and Server configuration referenced by Ingress")

// == health status of applications ==
serviceHealth, err := r.getServiceHealthStatus(gslb)
if err != nil {
m.IncrementError(gslb)
return result.RequeueError(err)
}
gslb.Status.ServiceHealth = serviceHealth

// == external-dns dnsendpoints CRs ==
dnsEndpoint, err := r.gslbDNSEndpoint(gslb)
if err != nil {
Expand Down
7 changes: 1 addition & 6 deletions controllers/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,10 @@ import (
)

func (r *GslbReconciler) updateGslbStatus(gslb *k8gbv1beta1.Gslb, ep *externaldns.DNSEndpoint) error {
var err error

gslb.Status.ServiceHealth, err = r.getServiceHealthStatus(gslb)
if err != nil {
return err
}

m.UpdateIngressHostsPerStatusMetric(gslb, gslb.Status.ServiceHealth)

var err error
gslb.Status.HealthyRecords, err = r.getHealthyRecords(gslb)
if err != nil {
return err
Expand Down

0 comments on commit 275c4f3

Please sign in to comment.