-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Convert DownloadRequest resource/controller to kubebuilder #3004
Conversation
@carlisia I did a quick pass over the code, but is there anything in particular preventing it from moving out of draft right now? |
Yes, I need to fix this test: https://github.com/vmware-tanzu/velero/pull/3004/files#diff-6d5dc1afa6af05350b9f38368bde033f93c478b86304922796d2e6eedcbf1336 |
70f0620
to
7aa7aa1
Compare
Note: @nrb agreed that the test pkg/cmd/util/downloadrequest/downloadrequest_test.go should be removed. To be sure, the controller has thorough testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple questions, and I think one of the parameters passed in to the Stream
function is no longer used now.
Comments so far have been addressed, ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dismissing request for changes, but looks like a rebase is necessary.
7aa7aa1
to
2be26e4
Compare
Rebased, ready for review. |
@vmware-tanzu/velero-maintainers Please queue this for review before break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just had the places where I think we want to use WithStack or Wrap on the returned error, otherwise looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you've shown me some of the work to use kubebuilder/controller runtime before, but seeing the changes in a PR make it really clear how much nicer this approach is 😄
Most of the comments I've left are cleanup/suggestions and could be addressed in a follow up. The only thing I'd really like to check before merging is the change to the requeue in the BSL controller. I don't know if that's an intentional change, and if so, what is the impact.
Signed-off-by: Carlisia <[email protected]>
Signed-off-by: Carlisia <[email protected]>
Signed-off-by: Carlisia <[email protected]>
Signed-off-by: Carlisia <[email protected]>
Signed-off-by: Carlisia <[email protected]>
Signed-off-by: Carlisia <[email protected]>
Signed-off-by: Carlisia <[email protected]>
Signed-off-by: Carlisia <[email protected]>
Signed-off-by: Carlisia <[email protected]>
Signed-off-by: Carlisia <[email protected]>
777c875
to
1c536ac
Compare
Addressed the corrections (thank you!). Note: I don't know what happened but needed to do a rebase, and the actual commit was "eaten", but the changes were pushed. Ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @carlisia! There are just a couple of changes that need to be made in one of the test cases but it's good otherwise 👍
downloadRequest: builder.ForDownloadRequest(velerov1api.DefaultNamespace, "a-download-request").Phase("").Target(velerov1api.DownloadTargetKindBackupLog, "a-backup-20170912150214").Result(), | ||
backup: defaultBackup(), | ||
expired: true, | ||
expectedReconcileErr: "backups.velero.io \"a-backup-20170912150214\" not found", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like the previous test where the expired DownloadRequest
was deleted, we shouldn't expect an error here. There are a few points in the main test code where we only set the expiration on the DownloadRequest
when it is Processed
when it should be applied to any expired request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my other two separate comments, they address both points here.
if tc.downloadRequest != nil && tc.downloadRequest.Status.Phase == velerov1api.DownloadRequestPhaseProcessed { | ||
if tc.expired { | ||
tc.downloadRequest.Status.Expiration = &metav1.Time{Time: harness.controller.clock.Now().Add(-1 * time.Minute)} | ||
if test.downloadRequest != nil && test.downloadRequest.Status != (velerov1api.DownloadRequestStatus{}) && test.downloadRequest.Status.Phase == velerov1api.DownloadRequestPhaseProcessed { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this whole outer check can be removed as we need to set the expiration for all requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expiration gets set only in the same block of code where we update the request status to processed
(
downloadRequest.Status.Expiration = &metav1.Time{Time: r.Clock.Now().Add(persistence.DownloadURLTTL)} |
This means, not all requests have an expiration. A request that has the phase ""
or New
will not have its expiration set until it gets processed and returned successfully from the reconcile loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which is to say, only requests that have been successfully processed will have it's expiration set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. You are right, of course. Nvm what I said. Let me re-evaluate these tests.
if tc.expired { | ||
assert.True(t, apierrors.IsNotFound(err)) | ||
if test.expired { | ||
if test.downloadRequest.Status.Phase == velerov1api.DownloadRequestPhaseProcessed { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If test.expired
is true, then we should always expect the err to be a NotFound
error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. I was thinking this test block was a mess. Thanks to your other comment, I realize a bug in the test: a request cannot be both expired and have a phase other than processed
, and the last test case if braking this rule. Fixing this.
Signed-off-by: Carlisia <[email protected]>
Thanks for the very attentive reviews @zubron. I was making some incorrect assumptions. All your points were valid and I think I addressed everything. Ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing the tests - LGTM! :)
…nzu#3004) * Migrate DownloadRequest types to kubebuilder Signed-off-by: Carlisia <[email protected]> * Migrate controller to kubebuilder Signed-off-by: Carlisia <[email protected]> * Migrate download request cli to kubebuilder Signed-off-by: Carlisia <[email protected]> * Format w make update Signed-off-by: Carlisia <[email protected]> * Remove download file Signed-off-by: Carlisia <[email protected]> * Remove kubebuilder from backup/restore apis Signed-off-by: Carlisia <[email protected]> * Fix test description Signed-off-by: Carlisia <[email protected]> * Import cleanups Signed-off-by: Carlisia <[email protected]> * Refactor for controller runtime version update Signed-off-by: Carlisia <[email protected]> * Remove year from the copyright Signed-off-by: Carlisia <[email protected]> * Check for expiration regardless of phase Signed-off-by: Carlisia <[email protected]> * Fix typos and godoc Signed-off-by: Carlisia <[email protected]> * Fix test setup and fix a test case Signed-off-by: Carlisia <[email protected]>
…nzu#3004) * Migrate DownloadRequest types to kubebuilder Signed-off-by: Carlisia <[email protected]> * Migrate controller to kubebuilder Signed-off-by: Carlisia <[email protected]> * Migrate download request cli to kubebuilder Signed-off-by: Carlisia <[email protected]> * Format w make update Signed-off-by: Carlisia <[email protected]> * Remove download file Signed-off-by: Carlisia <[email protected]> * Remove kubebuilder from backup/restore apis Signed-off-by: Carlisia <[email protected]> * Fix test description Signed-off-by: Carlisia <[email protected]> * Import cleanups Signed-off-by: Carlisia <[email protected]> * Refactor for controller runtime version update Signed-off-by: Carlisia <[email protected]> * Remove year from the copyright Signed-off-by: Carlisia <[email protected]> * Check for expiration regardless of phase Signed-off-by: Carlisia <[email protected]> * Fix typos and godoc Signed-off-by: Carlisia <[email protected]> * Fix test setup and fix a test case Signed-off-by: Carlisia <[email protected]>
…nzu#3004) * Migrate DownloadRequest types to kubebuilder Signed-off-by: Carlisia <[email protected]> * Migrate controller to kubebuilder Signed-off-by: Carlisia <[email protected]> * Migrate download request cli to kubebuilder Signed-off-by: Carlisia <[email protected]> * Format w make update Signed-off-by: Carlisia <[email protected]> * Remove download file Signed-off-by: Carlisia <[email protected]> * Remove kubebuilder from backup/restore apis Signed-off-by: Carlisia <[email protected]> * Fix test description Signed-off-by: Carlisia <[email protected]> * Import cleanups Signed-off-by: Carlisia <[email protected]> * Refactor for controller runtime version update Signed-off-by: Carlisia <[email protected]> * Remove year from the copyright Signed-off-by: Carlisia <[email protected]> * Check for expiration regardless of phase Signed-off-by: Carlisia <[email protected]> * Fix typos and godoc Signed-off-by: Carlisia <[email protected]> * Fix test setup and fix a test case Signed-off-by: Carlisia <[email protected]>
This closes #2656.