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

Convert DownloadRequest resource/controller to kubebuilder #3004

Merged
merged 13 commits into from Mar 1, 2021

Conversation

carlisia
Copy link
Contributor

@carlisia carlisia commented Oct 12, 2020

This closes #2656.

@carlisia carlisia added the kind/changelog-not-required PR does not require a user changelog. Often for docs, website, or build changes label Oct 12, 2020
@carlisia carlisia marked this pull request as draft October 12, 2020 17:27
@carlisia carlisia added this to the v1.6.0 milestone Oct 12, 2020
@nrb
Copy link
Contributor

nrb commented Oct 27, 2020

@carlisia I did a quick pass over the code, but is there anything in particular preventing it from moving out of draft right now?

@carlisia
Copy link
Contributor Author

@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

@nrb nrb added this to To do in v1.6.0 Nov 2, 2020
@nrb nrb moved this from To do to Review in progress in v1.6.0 Nov 2, 2020
@carlisia carlisia marked this pull request as ready for review November 3, 2020 23:24
@carlisia
Copy link
Contributor Author

carlisia commented Nov 3, 2020

Note: @nrb agreed that the test pkg/cmd/util/downloadrequest/downloadrequest_test.go should be removed. To be sure, the controller has thorough testing.

nrb
nrb previously requested changes Dec 1, 2020
Copy link
Contributor

@nrb nrb left a 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.

config/rbac/role.yaml Show resolved Hide resolved
@carlisia
Copy link
Contributor Author

carlisia commented Dec 3, 2020

Comments so far have been addressed, ready for review.

@carlisia carlisia requested a review from nrb December 3, 2020 00:10
Copy link
Contributor

@nrb nrb left a 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.

@carlisia
Copy link
Contributor Author

carlisia commented Dec 9, 2020

Rebased, ready for review.

@nrb nrb dismissed their stale review December 10, 2020 22:37

Changes addressed.

nrb
nrb previously approved these changes Dec 11, 2020
@nrb
Copy link
Contributor

nrb commented Dec 11, 2020

@vmware-tanzu/velero-maintainers Please queue this for review before break

v1.6.0 automation moved this from Review in progress to Reviewer approved Dec 16, 2020
dsu-igeek
dsu-igeek previously approved these changes Dec 16, 2020
Copy link
Contributor

@dsu-igeek dsu-igeek left a 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.

pkg/controller/download_request_controller.go Outdated Show resolved Hide resolved
pkg/controller/download_request_controller.go Outdated Show resolved Hide resolved
Copy link
Contributor

@zubron zubron left a 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.

pkg/cmd/util/downloadrequest/downloadrequest.go Outdated Show resolved Hide resolved
pkg/controller/download_request_controller.go Outdated Show resolved Hide resolved
pkg/controller/download_request_controller_test.go Outdated Show resolved Hide resolved
pkg/controller/download_request_controller_test.go Outdated Show resolved Hide resolved
pkg/controller/download_request_controller_test.go Outdated Show resolved Hide resolved
v1.6.0 automation moved this from Reviewer approved to Review in progress Dec 16, 2020
Carlisia added 10 commits February 18, 2021 20:08
Signed-off-by: Carlisia <carlisia@vmware.com>
Signed-off-by: Carlisia <carlisia@vmware.com>
Signed-off-by: Carlisia <carlisia@vmware.com>
Signed-off-by: Carlisia <carlisia@vmware.com>
Signed-off-by: Carlisia <carlisia@vmware.com>
Signed-off-by: Carlisia <carlisia@vmware.com>
Signed-off-by: Carlisia <carlisia@vmware.com>
Signed-off-by: Carlisia <carlisia@vmware.com>
Signed-off-by: Carlisia <carlisia@vmware.com>
Signed-off-by: Carlisia <carlisia@vmware.com>
@carlisia
Copy link
Contributor Author

carlisia commented Feb 19, 2021

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.

nrb
nrb previously approved these changes Feb 21, 2021
Copy link
Contributor

@zubron zubron left a 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",
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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 <carlisia@vmware.com>
@carlisia
Copy link
Contributor Author

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.

Copy link
Contributor

@zubron zubron left a 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! :)

v1.6.0 automation moved this from Review in progress to Reviewer approved Mar 1, 2021
@nrb nrb merged commit 11bfe82 into vmware-tanzu:main Mar 1, 2021
v1.6.0 automation moved this from Reviewer approved to Done Mar 1, 2021
dharmab pushed a commit to dharmab/velero that referenced this pull request May 25, 2021
…nzu#3004)

* Migrate DownloadRequest types to kubebuilder

Signed-off-by: Carlisia <carlisia@vmware.com>

* Migrate controller to kubebuilder

Signed-off-by: Carlisia <carlisia@vmware.com>

* Migrate download request cli to kubebuilder

Signed-off-by: Carlisia <carlisia@vmware.com>

* Format w make update

Signed-off-by: Carlisia <carlisia@vmware.com>

* Remove download file

Signed-off-by: Carlisia <carlisia@vmware.com>

* Remove kubebuilder from backup/restore apis

Signed-off-by: Carlisia <carlisia@vmware.com>

* Fix test description

Signed-off-by: Carlisia <carlisia@vmware.com>

* Import cleanups

Signed-off-by: Carlisia <carlisia@vmware.com>

* Refactor for controller runtime version update

Signed-off-by: Carlisia <carlisia@vmware.com>

* Remove year from the copyright

Signed-off-by: Carlisia <carlisia@vmware.com>

* Check for expiration regardless of phase

Signed-off-by: Carlisia <carlisia@vmware.com>

* Fix typos and godoc

Signed-off-by: Carlisia <carlisia@vmware.com>

* Fix test setup and fix a test case

Signed-off-by: Carlisia <carlisia@vmware.com>
ywk253100 pushed a commit to ywk253100/velero that referenced this pull request Jun 29, 2021
…nzu#3004)

* Migrate DownloadRequest types to kubebuilder

Signed-off-by: Carlisia <carlisia@vmware.com>

* Migrate controller to kubebuilder

Signed-off-by: Carlisia <carlisia@vmware.com>

* Migrate download request cli to kubebuilder

Signed-off-by: Carlisia <carlisia@vmware.com>

* Format w make update

Signed-off-by: Carlisia <carlisia@vmware.com>

* Remove download file

Signed-off-by: Carlisia <carlisia@vmware.com>

* Remove kubebuilder from backup/restore apis

Signed-off-by: Carlisia <carlisia@vmware.com>

* Fix test description

Signed-off-by: Carlisia <carlisia@vmware.com>

* Import cleanups

Signed-off-by: Carlisia <carlisia@vmware.com>

* Refactor for controller runtime version update

Signed-off-by: Carlisia <carlisia@vmware.com>

* Remove year from the copyright

Signed-off-by: Carlisia <carlisia@vmware.com>

* Check for expiration regardless of phase

Signed-off-by: Carlisia <carlisia@vmware.com>

* Fix typos and godoc

Signed-off-by: Carlisia <carlisia@vmware.com>

* Fix test setup and fix a test case

Signed-off-by: Carlisia <carlisia@vmware.com>
gyaozhou pushed a commit to gyaozhou/velero-read that referenced this pull request May 14, 2022
…nzu#3004)

* Migrate DownloadRequest types to kubebuilder

Signed-off-by: Carlisia <carlisia@vmware.com>

* Migrate controller to kubebuilder

Signed-off-by: Carlisia <carlisia@vmware.com>

* Migrate download request cli to kubebuilder

Signed-off-by: Carlisia <carlisia@vmware.com>

* Format w make update

Signed-off-by: Carlisia <carlisia@vmware.com>

* Remove download file

Signed-off-by: Carlisia <carlisia@vmware.com>

* Remove kubebuilder from backup/restore apis

Signed-off-by: Carlisia <carlisia@vmware.com>

* Fix test description

Signed-off-by: Carlisia <carlisia@vmware.com>

* Import cleanups

Signed-off-by: Carlisia <carlisia@vmware.com>

* Refactor for controller runtime version update

Signed-off-by: Carlisia <carlisia@vmware.com>

* Remove year from the copyright

Signed-off-by: Carlisia <carlisia@vmware.com>

* Check for expiration regardless of phase

Signed-off-by: Carlisia <carlisia@vmware.com>

* Fix typos and godoc

Signed-off-by: Carlisia <carlisia@vmware.com>

* Fix test setup and fix a test case

Signed-off-by: Carlisia <carlisia@vmware.com>
@cleverhu cleverhu mentioned this pull request Oct 20, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-unit-tests kind/changelog-not-required PR does not require a user changelog. Often for docs, website, or build changes kind/release-blocker Must fix issues for the coming release (milestone)
Projects
No open projects
v1.6.0
  
Done
Development

Successfully merging this pull request may close these issues.

Convert DownloadRequest resource/controller to the kubebuilder framework
5 participants