Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add watching on Secrets in drcluster_controller #1167

Merged
merged 1 commit into from
Jan 12, 2024

Conversation

ELENAGER
Copy link
Member

Upon Hub recovery, it takes time till secrets are copied. While secrets are still not copied, drcluster_controller fails to find them several times and goes to exponential backoff. When secrets are finally copied, drcluster_controller is not notified, because it was not registered for it.
Watching on Secrets added

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2248666

Watches(&source.Kind{Type: &corev1.Secret{}},
handler.EnqueueRequestsFromMapFunc(r.drClusterSecretMapFunc),
builder.WithPredicates(util.CreateOrDeleteOrResourceVersionUpdatePredicate{}),
).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is little bit inconsistent with other code - in other watches we have a function (e.g. mcvMapFun) and predicate (e.g. mcvPred). Here we have harder to follow structure.

Copy link
Member Author

@ELENAGER ELENAGER Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly, here is the same structure
I moved the other watch with the same structure, hope it looks more clear now

@@ -141,6 +145,24 @@ func (r *DRClusterReconciler) drClusterConfigMapMapFunc(configMap client.Object)
return requests
}

func (r *DRClusterReconciler) drClusterSecretMapFunc(secret client.Object) []reconcile.Request {
if secret.GetNamespace() != NamespaceName() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear what is this namespace. Not an issue in your change but maybe it is time to make this more clear.

@@ -141,6 +145,24 @@ func (r *DRClusterReconciler) drClusterConfigMapMapFunc(configMap client.Object)
return requests
}

func (r *DRClusterReconciler) drClusterSecretMapFunc(secret client.Object) []reconcile.Request {
if secret.GetNamespace() != NamespaceName() {
return []reconcile.Request{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not return nil? (empty slices is nil)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am returning it for the consistency with the other code. The same return can be found in 5 more places in this file.

return []reconcile.Request{}
}

drcusters := &ramen.DRClusterList{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to create the DRClusterList on the heap - we can do:

drclusters := ramen.DRClusterList{}
r.Client.List(context.TODO(), &drcusters)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are probably right, but it's also for consistency. We are always creating lists on heap (I've looked through all our code).


requests := make([]reconcile.Request, len(drcusters.Items))
for i, drcluster := range drcusters.Items {
requests[i].Name = drcluster.GetName()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this loop copy all drclusters from drcusters.Items? We can avoid the copy if we do:

for i := range drcusters.Items {
    requests[i].Name = drclusters.Items[i].GetName()
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@ShyamsundarR ShyamsundarR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of a envtest and looked for parallels in DRPolicy, which also does not have a test for a secret event (though it is covered in other ways as per the coverage report).

Otherwise this looks good. In case we still want to address the optimizations that nir suggested we can amend it accordingly.

return []reconcile.Request{}
}

requests := make([]reconcile.Request, len(drcusters.Items))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of reconciling all DRClusters we may want to filter out only those that reference the secret via their S3Profile name. The same non-optimized version exists here as well, so let's add a TODO/issue at least to keep this tracked.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShyamsundarR ShyamsundarR merged commit bfe93e7 into RamenDR:main Jan 12, 2024
14 checks passed
@ELENAGER ELENAGER deleted the bug_2248666_watch_secrets branch January 14, 2024 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants