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

refactor: Replace deprecated NewRandomVirtualMachine* functions by using libvmi directly #11621

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TheRealSibasishBehera
Copy link
Contributor

Before this PR: The codebase was using deprecated NewRandomVirtualMachineInstanceWithBlockDisk , NewRandomVirtualMachineInstanceWithFileDisk , and NewRandomVirtualMachineInstanceWithDisk functions for testing purposes.

After this PR: Replaced all occurrences of deprecated NewRandomVirtualMachine* functions with equivalent functions from the libvmi library.

Fixes #11565

Why we need it and why it was done in this way

The NewRandomVirtualMachine* functions were deprecated and needed to be replaced to ensure compatibility with future releases. This PR updates the codebase to use the recommended libvmi functions for improved maintainability.

The following tradeoffs were made:

The following alternatives were considered:

Links to places where the discussion took place:

Special notes for your reviewer

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

Release note

NONE

@kubevirt-bot kubevirt-bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. sig/storage labels Mar 29, 2024
@kubevirt-bot
Copy link
Contributor

Hi @TheRealSibasishBehera. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

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.

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign alonakaplan for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@@ -1017,7 +1017,36 @@ var _ = SIGMigrationDescribe("VM Live Migration", func() {
Expect(err.Error()).To(ContainSubstring("DisksNotLiveMigratable"))
})
It("[test_id:1479][storage-req] should migrate a vmi with a shared block disk", decorators.StorageReq, func() {
vmi, _ := tests.NewRandomVirtualMachineInstanceWithBlockDisk(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine), testsuite.GetTestNamespace(nil), k8sv1.ReadWriteMany)
if !libstorage.HasCDI() {
Skip("Skip DataVolume tests when CDI is not present")
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for your PR. We should work hard to eliminate the catch-all tests/utils file.

These Skips were here before your PR, but now they are more spread out. Skip should not be used in tests, because they may cause us to ignore a test silently and unintentionally. Besides, I bet (but not sure) that the [storage-req] label means that these tests are executed only when storage requirements (CDI, block storage) are available. Please avoid them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense , i will change that


dataVolume, err = virtClient.CdiClient().CdiV1beta1().DataVolumes(testsuite.GetTestNamespace(nil)).Create(context.Background(), dataVolume, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
libstorage.EventuallyDV(dataVolume, 240, Or(HaveSucceeded(), WaitForFirstConsumer()))
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that waiting for the DV here is necessary or helpful.

@@ -1077,7 +1106,37 @@ var _ = SIGMigrationDescribe("VM Live Migration", func() {

It("[test_id:1854]should migrate a VMI with shared and non-shared disks", func() {
// Start the VirtualMachineInstance with PVC and Ephemeral Disks
vmi, _ := tests.NewRandomVirtualMachineInstanceWithBlockDisk(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine), testsuite.GetTestNamespace(nil), k8sv1.ReadWriteMany)
if !libstorage.HasCDI() {
Copy link
Member

Choose a reason for hiding this comment

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

tests/migration/migration.go is already too long. I would prefer it that you define a private function such as vmi, err := newAlpineWithDV() and reuse it in this file.

@dankenigsberg
Copy link
Member

/sig code-quality

@@ -1017,7 +1017,36 @@ var _ = SIGMigrationDescribe("VM Live Migration", func() {
Expect(err.Error()).To(ContainSubstring("DisksNotLiveMigratable"))
})
It("[test_id:1479][storage-req] should migrate a vmi with a shared block disk", decorators.StorageReq, func() {
vmi, _ := tests.NewRandomVirtualMachineInstanceWithBlockDisk(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine), testsuite.GetTestNamespace(nil), k8sv1.ReadWriteMany)
if !libstorage.HasCDI() {
Copy link
Member

Choose a reason for hiding this comment

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

@TheRealSibasishBehera you can refer to the document that Felix is writing as part of #11456 . It is still in progress but there is some guidelines to avoid Skip and use the decorators.

Hence you should assume that the feature and components are there and failing as consequence. Hence, this becomes:

Expect(libstorage.HasCDI()).To(BeTrue())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes ,i will make the changes . Thanks

Skip("Skip DataVolume tests when CDI is not present")
}
sc, exists := libstorage.GetRWXBlockStorageClass()
if !exists {
Copy link
Member

Choose a reason for hiding this comment

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

Same here with the skip

@alicefr
Copy link
Member

alicefr commented Apr 3, 2024

@TheRealSibasishBehera I think we need to create another function that wraps all those code duplications. You could create a new template in the factory.go.
I know that this might seem similar to the deprecated function. However, the goal is that you still need to add the options to make this extensible. Something like:

func NewAlpineWithDataVolume(sc string, accessMode  k8sv1.AccessMode, opts ...libvmi.Option) *kvirtv1.VirtualMachineInstance {}

You can also include there the CDI and storage class checks and the dv creation there. In this way you can call the function with different option

libvmifact.NewAlpineWithDataVolume(
   sc, k8sv1.ReadWriteMany,
   libvmi.WithNamespace(testsuite.GetTestNamespace(nil)),
  ....
)

…libvmi equivalents

Signed-off-by: TheRealSibasishBehera <fangedhamster3114@gmail.com>
cd "kubevirt.io/kubevirt/tests/containerdisk"
"kubevirt.io/kubevirt/tests/framework/kubevirt"
Copy link
Member

Choose a reason for hiding this comment

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

this PR adds a lot of dependencies to this file. Must the new functions be introduced here? Did you consider keeping them closer to their callers?

I think that @akalenyu is working on a similar thing.

Copy link
Contributor

@akalenyu akalenyu Apr 9, 2024

Choose a reason for hiding this comment

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

Yep. However, different approach #11670
I believe the DV should be fully passed in, and we could expose certain presets from libdv if needed

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@akalenyu we can, it is just more repetition of the dv specifications, but I guess we want to avoid too many variation of the functions

Copy link
Contributor

Choose a reason for hiding this comment

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

@akalenyu we can, it is just more repetition of the dv specifications, but I guess we want to avoid too many variation of the functions

From my investigation a "one-fits-all" DV would also not work unfortunately,
but yes, I definitely agree we should settle on one of them

Copy link
Member

@alicefr alicefr Apr 10, 2024

Choose a reason for hiding this comment

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

@TheRealSibasishBehera do you mind passing an entire DV as part of the function NewAlpineWithDataVolume and adjust the function calls?

Copy link
Contributor

Choose a reason for hiding this comment

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

@alicefr would you prefer I handle this in my other PR so this PR doesn't have to diverge much?

Copy link
Member

@alicefr alicefr Apr 10, 2024

Choose a reason for hiding this comment

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

@akalenyu mh maybe it is better. However, this function should also be called outside the storage code, see the changes of this PR in migration.go

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah I'll move 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.

@akalenyu mh maybe it is better. However, this function should also be called outside the storage code, see the changes of this PR in migration.go

yeah @alicefr i agree on that part , this function would be called outside storage so it better to keep it in libvmifact .
an alternative can be keeping it in something like libvmifact/storage.go which will have functions involving storage related operations


func getVolumeModeForAccessMode(accessMode k8sv1.PersistentVolumeAccessMode) k8sv1.PersistentVolumeMode {
if accessMode == k8sv1.ReadWriteMany {
return k8sv1.PersistentVolumeBlock
Copy link
Member

Choose a reason for hiding this comment

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

I suspect that ReadWriteMany implies PersistentVolumeBlock only in specific tests or a specific test framework. I think it would be better if the DV requests exactly what it wants to get,

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah those two are not coupled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i will change that

@@ -1017,7 +1017,11 @@ var _ = SIGMigrationDescribe("VM Live Migration", func() {
Expect(err.Error()).To(ContainSubstring("DisksNotLiveMigratable"))
})
It("[test_id:1479][storage-req] should migrate a vmi with a shared block disk", decorators.StorageReq, func() {
vmi, _ := tests.NewRandomVirtualMachineInstanceWithBlockDisk(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskAlpine), testsuite.GetTestNamespace(nil), k8sv1.ReadWriteMany)
Expect(libstorage.HasCDI()).To(BeTrue())
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a trailing reason string, so that if this fails, we'd see a clear failure reason?

@kubevirt-bot kubevirt-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 10, 2024
@kubevirt-bot
Copy link
Contributor

PR needs rebase.

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.

@avlitman
Copy link
Contributor

avlitman commented May 8, 2024

@TheRealSibasishBehera thank you so much for contributing, this is great!
Are you planing on continue with this pr? I'm asking since we talked about fixing this as well, so want to plan.

@RoniKishner
Copy link
Contributor

Hey this will need to be rebase and changed a bit because of #11624

@TheRealSibasishBehera
Copy link
Contributor Author

@TheRealSibasishBehera thank you so much for contributing, this is great! Are you planing on continue with this pr? I'm asking since we talked about fixing this as well, so want to plan.

Yes , I plan to complete this .
#11670 is handling something similar . I am planning match its pattern .
Its still under work . We can wait till the PR is complete there or go with whats done till now regarding how DV creation is handled there.
Can you suggest which one would be the better option here ?

cc @alicefr @akalenyu

@TheRealSibasishBehera
Copy link
Contributor Author

Hey this will need to be rebase and changed a bit because of #11624

Thanks @RoniKishner I will change that

@akalenyu
Copy link
Contributor

@TheRealSibasishBehera thank you so much for contributing, this is great! Are you planing on continue with this pr? I'm asking since we talked about fixing this as well, so want to plan.

Yes , I plan to complete this . #11670 is handling something similar . I am planning match its pattern . Its still under work . We can wait till the PR is complete there or go with whats done till now regarding how DV creation is handled there. Can you suggest which one would be the better option here ?

cc @alicefr @akalenyu

Right so the whole approach of having this type of factory is being challenged,
and thus the PR you mention is now on hold:
#11670 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: yes Indicates the PR's author has DCO signed all their commits. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note-none Denotes a PR that doesn't merit a release note. sig/code-quality sig/storage size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor: replace all the deprecated functions with libvmi
7 participants