Skip to content

Commit

Permalink
fix endpoint reconciliation
Browse files Browse the repository at this point in the history
The idea was to still trigger reconciliation cycles if resources changes by checking if there was a `generation` update.
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata
> generation: a sequence number representing a specific generation of the desired state. Set by the system and monotonically increasing, per-resource. May be compared, such as for RAW and WAW consistency.

However, the change caused a degradation in `Endpoints` resources. These resources don't have generation because they don't have a status. As a result, a reconciliation was only triggered on creation and deletion, but not on subset update.
This degradated also the behavior of the k8gb controller. The controller became too slow monitoring the health of applications since `Endpoints` updates no longer triggered a reconcile of the GSLB resource. This lead to slow failovers and failing e2e tests.

The solution proposed in this PR is to always trigger the `endpointMapHandler` function when an `Endpoint` resource changes. This is the same behavior as before #1652.

Signed-off-by: Andre Baptista Aguas <andre.aguas@protonmail.com>
  • Loading branch information
abaguas committed Jul 30, 2024
1 parent dca347d commit e871ea8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 61 deletions.
1 change: 0 additions & 1 deletion controllers/gslb_controller_reconciliation.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ func (r *GslbReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
return result.RequeueError(fmt.Errorf("getting GSLB servers (%s)", err))
}
gslb.Status.Servers = servers
fmt.Printf("got servers: %v\n", servers)

loadBalancerExposedIPs, err := refResolver.GetGslbExposedIPs(r.Client, r.Config.EdgeDNSServers)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions controllers/gslb_controller_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
Expand Down Expand Up @@ -98,6 +99,15 @@ func (r *GslbReconciler) SetupWithManager(mgr ctrl.Manager) error {
if e.ObjectOld.GetGeneration() != e.ObjectNew.GetGeneration() {
return true
}

// endpoints don't have state, therefore they don't have a generation
// but when their subsets change they must be be reconciled
gvk, err := apiutil.GVKForObject(e.ObjectOld, r.Scheme)
if err == nil && gvk.Kind == "Endpoints" {
return true
}
log.Warn().Msg("could not fetch GroupVersionKind for object")

// Ignore reconciliation in case nothing has changed in k8gb annotations
oldAnnotations := e.ObjectOld.GetAnnotations()
newAnnotations := e.ObjectNew.GetAnnotations()
Expand Down
Loading

0 comments on commit e871ea8

Please sign in to comment.