-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: reconcile redis sentinel only on master changed (#1122)
* feat: redissentinel reconcile only on master changed Signed-off-by: drivebyer <[email protected]> * fix Lint Signed-off-by: drivebyer <[email protected]> * e2e cleanup Signed-off-by: drivebyer <[email protected]> --------- Signed-off-by: drivebyer <[email protected]>
- Loading branch information
Showing
35 changed files
with
161 additions
and
683 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package controllerutil | ||
|
||
import ( | ||
"context" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/client-go/util/workqueue" | ||
"sigs.k8s.io/controller-runtime/pkg/event" | ||
"sigs.k8s.io/controller-runtime/pkg/handler" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
) | ||
|
||
// ResourceWatcher implements handler.EventHandler and is used to trigger reconciliation when | ||
// a watched object changes. It's designed to only be used for a single type of object. | ||
// If multiple types should be watched, one ResourceWatcher for each type should be used. | ||
type ResourceWatcher struct { | ||
watched map[types.NamespacedName][]types.NamespacedName | ||
} | ||
|
||
var _ handler.EventHandler = &ResourceWatcher{} | ||
|
||
// NewResourceWatcher will create a new ResourceWatcher with no watched objects. | ||
func NewResourceWatcher() *ResourceWatcher { | ||
return &ResourceWatcher{ | ||
watched: make(map[types.NamespacedName][]types.NamespacedName), | ||
} | ||
} | ||
|
||
// Watch will add a new object to watch. | ||
func (w ResourceWatcher) Watch(ctx context.Context, watchedName, dependentName types.NamespacedName) { | ||
existing, hasExisting := w.watched[watchedName] | ||
if !hasExisting { | ||
existing = []types.NamespacedName{} | ||
} | ||
|
||
for _, dependent := range existing { | ||
if dependent == dependentName { | ||
return | ||
} | ||
} | ||
w.watched[watchedName] = append(existing, dependentName) | ||
} | ||
|
||
func (w ResourceWatcher) Create(ctx context.Context, event event.CreateEvent, queue workqueue.RateLimitingInterface) { | ||
w.handleEvent(event.Object, queue) | ||
} | ||
|
||
func (w ResourceWatcher) Update(ctx context.Context, event event.UpdateEvent, queue workqueue.RateLimitingInterface) { | ||
w.handleEvent(event.ObjectOld, queue) | ||
} | ||
|
||
func (w ResourceWatcher) Delete(ctx context.Context, event event.DeleteEvent, queue workqueue.RateLimitingInterface) { | ||
w.handleEvent(event.Object, queue) | ||
} | ||
|
||
func (w ResourceWatcher) Generic(ctx context.Context, event event.GenericEvent, queue workqueue.RateLimitingInterface) { | ||
w.handleEvent(event.Object, queue) | ||
} | ||
|
||
// handleEvent is called when an event is received for an object. | ||
// It will check if the object is being watched and trigger a reconciliation for | ||
// the dependent object. | ||
func (w ResourceWatcher) handleEvent(meta metav1.Object, queue workqueue.RateLimitingInterface) { | ||
changedObjectName := types.NamespacedName{ | ||
Name: meta.GetName(), | ||
Namespace: meta.GetNamespace(), | ||
} | ||
|
||
// Enqueue reconciliation for each dependent object. | ||
for _, dep := range w.watched[changedObjectName] { | ||
queue.Add(reconcile.Request{ | ||
NamespacedName: dep, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
53 changes: 0 additions & 53 deletions
53
tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/chainsaw-test.yaml
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/password.yaml
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/ready-secret.yaml
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/replication.yaml
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/sentinel.yaml
This file was deleted.
Oops, something went wrong.
File renamed without changes.
59 changes: 0 additions & 59 deletions
59
tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/chainsaw-test.yaml
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.