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

Delete old version DVs with DIC GC #2749

Merged
merged 1 commit into from
Sep 11, 2023

Conversation

ido106
Copy link
Contributor

@ido106 ido106 commented Jun 12, 2023

Signed-off-by: Ido Aharon iaharon@redhat.com

What this PR does / why we need it:
In the old versions, the garbage collection label was added to DV only. In the new version, the GC looks for this label in the PVC, so it does not find it and does not delete the DV's from the old versions

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes bz #2209969

Special notes for your reviewer:

Release note:

Delete old version DV's with DIC garbage collector

@kubevirt-bot kubevirt-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: no Indicates the PR's author has not DCO signed all their commits. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 12, 2023
@kubevirt-bot
Copy link
Contributor

Hi @ido106. Thanks for your PR.

I'm waiting for a kubevirt member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ido106 ido106 force-pushed the garbage_collect_old_dvs_dic branch from 4edfb75 to a12b74a Compare June 12, 2023 16:11
@kubevirt-bot kubevirt-bot added dco-signoff: yes Indicates the PR's author has DCO signed all their commits. and removed dco-signoff: no Indicates the PR's author has not DCO signed all their commits. labels Jun 12, 2023
@ido106 ido106 force-pushed the garbage_collect_old_dvs_dic branch from a12b74a to 804ceba Compare August 21, 2023 08:37
@kubevirt-bot kubevirt-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 21, 2023
@ido106 ido106 force-pushed the garbage_collect_old_dvs_dic branch 3 times, most recently from 22c28e3 to 8faf5e4 Compare August 24, 2023 14:58
@ido106 ido106 changed the title [WIP] Delete old version DV's with DIC GC Delete old version DV's with DIC GC Aug 24, 2023
@kubevirt-bot kubevirt-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 24, 2023
@akalenyu
Copy link
Collaborator

/ok-to-test

@kubevirt-bot kubevirt-bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 30, 2023
@akalenyu
Copy link
Collaborator

If there is a bug opened for this, would be great to include it under Fixes #

@ido106
Copy link
Contributor Author

ido106 commented Aug 30, 2023

If there is a bug opened for this, would be great to include it under Fixes #

There is only a Jira card
https://issues.redhat.com/browse/CNV-29106

@akalenyu
Copy link
Collaborator

If there is a bug opened for this, would be great to include it under Fixes #

There is only a Jira card https://issues.redhat.com/browse/CNV-29106

Yup, if you look at that issue it translates to a bugzilla

@ido106
Copy link
Contributor Author

ido106 commented Aug 31, 2023

If there is a bug opened for this, would be great to include it under Fixes #

There is only a Jira card https://issues.redhat.com/browse/CNV-29106

Yup, if you look at that issue it translates to a bugzilla

Ok, I added the Bugzilla bug number

return err
}

for _, dv := range dvList.Items {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Out of curiosity, why don't we apply here the logic used above?

if len(pvcList.Items) > maxImports {
		sort.Slice(pvcList.Items, func(i, j int) bool {
			return pvcList.Items[i].Annotations[AnnLastUseTime] > pvcList.Items[j].Annotations[AnnLastUseTime]
		})
for _, pvc := range pvcList.Items[maxImports:] {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At first I did that, but then we decided to delete all those DVs because they are all old.
@arnongilboa
Maybe we'll change it back?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, we would like to delete these (very) old ones and no need to sort, but we can sure add

if len(dvList.Items) > maxImports

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

}

if pvc.Labels[common.DataImportCronLabel] != cronName {
if err := r.deleteDvPvc(ctx, dv.Name, dv.Namespace); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe log the deletion of these dvs/pvcs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay

@ido106 ido106 force-pushed the garbage_collect_old_dvs_dic branch 2 times, most recently from 9796b25 to 91a73d7 Compare September 3, 2023 10:49
@ido106
Copy link
Contributor Author

ido106 commented Sep 3, 2023

/retest

@ido106
Copy link
Contributor Author

ido106 commented Sep 4, 2023

The functional test works on my machine. Does someone know what the problem is?

You should be able to reproduce the failures if you start a fresh dev cluster with KUBEVIRT_STORAGE=hpp

Great, thanks !

@ido106 ido106 force-pushed the garbage_collect_old_dvs_dic branch 3 times, most recently from 2135092 to 00cfb22 Compare September 6, 2023 13:41
@ido106
Copy link
Contributor Author

ido106 commented Sep 6, 2023

Is 7406 cool now ?
@akalenyu

@ido106
Copy link
Contributor Author

ido106 commented Sep 7, 2023

/retest

@ido106 ido106 changed the title Delete old version DV's with DIC GC Delete old version DVs with DIC GC Sep 7, 2023
Copy link
Collaborator

@akalenyu akalenyu left a comment

Choose a reason for hiding this comment

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

Looks good just not sure if you meant to keep the separate test

@@ -367,6 +369,120 @@ var _ = Describe("DataImportCron", func() {
Entry("[test_id:8266] succeed deleting error DVs when importing new ones", false, true, 2, cdiv1.DataImportCronSourceFormatPvc),
)

It("[test_id:XXXX] Succeed garbage collecting old version DVs", func() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can delete this test now that we are doing the check in 7406

Copy link
Contributor Author

@ido106 ido106 Sep 7, 2023

Choose a reason for hiding this comment

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

Yup, I was just waiting to see if 7406 is good before deleting the old test

Eventually(func() bool {
_, err := f.CdiClient.CdiV1beta1().DataVolumes(ns).Get(context.TODO(), oldDvName, metav1.GetOptions{})
return err != nil
}, dataImportCronTimeout, pollingInterval).Should(Equal(true), "Garbage collection failed cleaning old DV")
Copy link
Collaborator

@akalenyu akalenyu Sep 7, 2023

Choose a reason for hiding this comment

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

Just a nit, if you want, can do something like this:

Eventually(func() error {
	_, err := f.CdiClient.CdiV1beta1().DataVolumes(ns).Get(context.TODO(), oldDvName, metav1.GetOptions{})
	return err
}, dataImportCronTimeout, pollingInterval).Should(Satisfy(errors.IsNotFound), "Garbage collection failed cleaning old DV")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, I will fix it

@ido106 ido106 force-pushed the garbage_collect_old_dvs_dic branch 2 times, most recently from f635c1a to fc7884f Compare September 7, 2023 09:48
@akalenyu
Copy link
Collaborator

akalenyu commented Sep 7, 2023

/approve

@akalenyu
Copy link
Collaborator

akalenyu commented Sep 7, 2023

/cc @arnongilboa

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: akalenyu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 7, 2023
}

if pvc.Labels[common.DataImportCronLabel] != cronName {
r.log.Info("Deleting dv/pvc", "name", pvc.Name, "pvc.uid", pvc.UID)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this log line should be a bit different from the one above, e.g. "Deleting old version dv/pvc"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

cron = newDataImportCron(cronName)
importsToKeep := int32(1)
cron.Spec.ImportsToKeep = &importsToKeep
cron.Annotations[AnnSourceDesiredDigest] = testDigest
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do you need to set digest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, we don't need it. Probably left over from the old test I wrote.
Fixed

@@ -48,6 +48,7 @@ var _ = Describe("DataImportCron", func() {
ns string
scName string
originalProfileSpec *cdiv1.StorageProfileSpec
oldDvName = "src-garbage-0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

oldDvName should move into the function, as nobody else is using it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay

Comment on lines 451 to 452
for i := 1; i <= garbageSources; i++ {
srcName := fmt.Sprintf("src-garbage-%d", i)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure I like this naming hack, oldDvName should have a better name than "src-garbage-0", e.g. "old-version-dv", and the loop can be reverted to 0-based.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, no problem. Fixed

Signed-off-by: Ido Aharon <iaharon@redhat.com>
@ido106
Copy link
Contributor Author

ido106 commented Sep 10, 2023

Do you have any more comments?
@arnongilboa

@arnongilboa
Copy link
Collaborator

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 11, 2023
@kubevirt-bot kubevirt-bot merged commit 5b68719 into kubevirt:main Sep 11, 2023
18 checks passed
arnongilboa pushed a commit to arnongilboa/containerized-data-importer that referenced this pull request Sep 28, 2023
Manual backport of kubevirt#2749

Signed-off-by: Ido Aharon <iaharon@redhat.com>
kubevirt-bot pushed a commit that referenced this pull request Oct 4, 2023
Manual backport of #2749

Signed-off-by: Ido Aharon <iaharon@redhat.com>
Co-authored-by: Ido Aharon <iaharon@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants