Skip to content

Commit 99b738c

Browse files
Use namespace list from namespaceWatcher.NamespaceStore instead of retrieving it (#132)
This fixes performance issues when many secrets need to be replicated to other namespaces via replicate-to. The performance issue would be acceptable, when it would fix itself after some time after the initial replication after startup. However, with the current solution, the liveness probe never gets green and keep causing replicator restarts in our clusters. Co-authored-by: Martin Helmich <m.helmich@mittwald.de>
1 parent a5f212a commit 99b738c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

replicate/common/generic-replicator.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,12 @@ func (r *GenericReplicator) ResourceAdded(obj interface{}) {
269269
if namespacePatterns, ok := annotations[ReplicateTo]; ok {
270270
r.ReplicateToList[sourceKey] = struct{}{}
271271

272-
if list, err := r.Client.CoreV1().Namespaces().List(ctx, metav1.ListOptions{}); err != nil {
273-
logger.WithError(err).Error("failed to list namespaces")
274-
} else if err := r.replicateResourceToMatchingNamespaces(obj, namespacePatterns, list.Items); err != nil {
272+
namespacesFromStore := namespaceWatcher.NamespaceStore.List()
273+
namespaces := make([]v1.Namespace, len(namespacesFromStore))
274+
for i, ns := range namespacesFromStore {
275+
namespaces[i] = *ns.(*v1.Namespace)
276+
}
277+
if err := r.replicateResourceToMatchingNamespaces(obj, namespacePatterns, namespaces); err != nil {
275278
logger.WithError(err).Errorf("could not replicate object to other namespaces")
276279
}
277280
} else {

0 commit comments

Comments
 (0)