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

controller: fix reclaimspace based on ns annotation #396

Merged
merged 1 commit into from
Jun 28, 2023

Conversation

Rakshith-R
Copy link
Member

Logic used for determining reclaimspace annotation based on ns annotation and driver support had a bug which caused all the PVCs regardless of driversupport being annotated.
This commit makes sure only pvc with driver which
support reclaimspace is annotated/ requeued.

@mergify mergify bot requested a review from yati1998 June 27, 2023 11:57
@Rakshith-R Rakshith-R added this to the release-v0.6.0 milestone Jun 27, 2023
@@ -134,13 +134,22 @@ func (r *PersistentVolumeClaimReconciler) Reconcile(ctx context.Context, req ctr
logger.Error(err, "Failed to get Namespace", "Namespace", pvc.Namespace)
return ctrl.Result{}, err
}
schedule, scheduleFound = getScheduleFromAnnotation(&logger, ns.Annotations)
// If the schedule is not found, check whether driver supports the
nsSchedule, nsScheduleFound := getScheduleFromAnnotation(&logger, ns.Annotations)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need new variables? Can we assign this to exist schedule,schduleFound?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we need new variables? Can we assign this to exist schedule,schduleFound?

This current form simplifies the code and makes it easier to understand,
Otherwise it was very difficult to follow the flow.
please read the comments inside the statements.

Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm, this change does not improve the function for me. I have read the comments and change a few times now (that was really needed to understand it), so I think it is not clear enough. If you want to improve the behaviour, split things out in helper functions instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

We are evaluating a lot of conditions in these statements,

I don't believe adding helper function which take in a lot of arguments and also return a lot of arguments will make the code flow any cleaner.

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved the statements into a helper function with lots of io args.
Hopefully it is simpler to follow now 🤞

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks! I am not a big fan of many return values or arguments to a function either, but this is definitely easier to understand than what there was before.

One thing that could make it even cleaner, is returning an error if requeuing shoud not be needed. This, and maybe the schedule-not-found could be pre-defined errors. You can then check with errors.Is(...) what early return from the reconcile should be done. Can you consider doing that, and see if it makes it even cleaner?

Copy link
Member Author

Choose a reason for hiding this comment

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

made the suggested changes, ptal.

Copy link
Member Author

Choose a reason for hiding this comment

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

Both the args are now Err types and will be detected using errors.Is().

Madhu-1
Madhu-1 previously approved these changes Jun 27, 2023
@Rakshith-R Rakshith-R requested review from nixpanic and removed request for nixpanic June 27, 2023 13:08
@Rakshith-R
Copy link
Member Author

@Mergifyio rebase

@mergify
Copy link

mergify bot commented Jun 27, 2023

rebase

✅ Branch has been successfully rebased

@Rakshith-R Rakshith-R force-pushed the ns-annotate-fix branch 2 times, most recently from d51a9dc to f344e4d Compare June 28, 2023 07:40
@mergify mergify bot dismissed Madhu-1’s stale review June 28, 2023 07:41

Pull request has been modified.

Logic used for determining reclaimspace annotation
based on ns annotation and driver support had a bug
which caused all the PVCs regardless of driversupport
being annotated.
This commit makes sure only pvc with driver which
support reclaimspace is annotated/ requeued.

Signed-off-by: Rakshith R <rar@redhat.com>
@mergify mergify bot merged commit bed9c6e into csi-addons:main Jun 28, 2023
14 checks passed
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.

None yet

3 participants