8000 fix(chk): prevent tight reconcile loop on status updates by Tyagiquamar · Pull Request #2111 · Altinity/clickhouse-operator · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions cmd/operator/app/thread_keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/altinity/clickhouse-operator/pkg/chop"
controller "github.com/altinity/clickhouse-operator/pkg/controller/chk"
chkLabeler "github.com/altinity/clickhouse-operator/pkg/model/chk/tags/labeler"
"github.com/altinity/clickhouse-operator/pkg/util"
)

var (
Expand Down Expand Up @@ -246,6 +247,14 @@ func keeperPredicate() predicate.Funcs {
return false
}

if old, ok := e.ObjectOld.(*api.ClickHouseKeeperInstallation); ok && old != nil {
if old.GetGeneration() == new.GetGeneration() &&
util.SlicesEqualAsSet(old.GetFinalizers(), new.GetFinalizers()) &&
old.GetDeletionTimestamp().Equal(new.GetDeletionTimestamp()) {
return false
}
}

return true
},
GenericFunc: func(e event.GenericEvent) bool {
Expand Down
59 changes: 59 additions & 0 deletions cmd/operator/app/thread_keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"testing"

meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/event"

api "github.com/altinity/clickhouse-operator/pkg/apis/clickhouse-keeper.altinity.com/v1"
Expand Down Expand Up @@ -81,6 +82,64 @@ func Test_keeperPredicateUpdate(t *testing.T) {
},
},
},
{
name: "drops update when generation, finalizers, and deletionTimestamp are unchanged (pure status update)",
want: false,
evt: event.UpdateEvent{
ObjectOld: &api.ClickHouseKeeperInstallation{
ObjectMeta: meta.ObjectMeta{
Generation: 1,
Finalizers: []string{"clickhousekeeperinstallations.clickhouse-keeper.altinity.com"},
},
Spec: api.ChkSpec{
Suspend: types.NewStringBool(false),
},
},
ObjectNew: &api.ClickHouseKeeperInstallation{
ObjectMeta: meta.ObjectMeta{
Generation: 1,
Finalizers: []string{"clickhousekeeperinstallations.clickhouse-keeper.altinity.com"},
},
Spec: api.ChkSpec{
Suspend: types.NewStringBool(false),
},
},
},
},
{
name: "queues update when generation changes",
want: true,
evt: event.UpdateEvent{
ObjectOld: &api.ClickHouseKeeperInstallation{
ObjectMeta: meta.ObjectMeta{
Generation: 1,
},
},
ObjectNew: &api.ClickHouseKeeperInstallation{
ObjectMeta: meta.ObjectMeta{
Generation: 2,
},
},
},
},
{
name: "queues update when finalizers change",
want: true,
evt: event.UpdateEvent{
ObjectOld: &api.ClickHouseKeeperInstallation{
ObjectMeta: meta.ObjectMeta{
Generation: 1,
Finalizers: []string{},
},
},
ObjectNew: &api.ClickHouseKeeperInstallation{
ObjectMeta: meta.ObjectMeta{
Generation: 1,
Finalizers: []string{"clickhousekeeperinstallations.clickhouse-keeper.altinity.com"},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
8 changes: 6 additions & 2 deletions pkg/controller/chk/worker-reconciler-chk.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,14 @@ func (w *worker) reconcileCR(ctx context.Context, old, new *apiChk.ClickHouseKee
metrics.CRReconcilesCompleted(ctx, new)
}
return nil
case new.HasReconcileWork():
w.a.M(new).F().Info("CR has reconcile work - continue reconcile")
case w.isAfterFinalizerInstalled(new.GetAncestorT(), new):
w.a.M(new).F().Info("isAfterFinalizerInstalled - continue reconcile-2")
case w.isGenerationTheSame(new.GetAncestorT(), new):
w.a.M(new).F().Info("isGenerationTheSame() - nothing to do here, exit")
metrics.CRReconcilesCompleted(ctx, new)
return nil
case new.HasReconcileWork():
w.a.M(new).F().Info("CR has reconcile work - continue reconcile")
default:
w.a.M(new).F().Info("No reconcile work - abort reconcile")
metrics.CRReconcilesCompleted(ctx, new)
Expand Down
Loading
0