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

Remove NewRandomVMIWithEphemeralDisk from tests/utils.go #11923

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

nunnatsa
Copy link
Contributor

What this PR does

Before this PR

The NewRandomVMIWithEphemeralDisk is deprecated. After merging several PRs to stop using it, it's now only called from 3 other deprecated tests/utils.go's deprecated functions:

  • NewRandomVMIWithEphemeralDiskAndUserdata
  • NewRandomVMIWithEphemeralDiskAndConfigDriveUserdata
  • NewRandomVMIWithEphemeralDiskAndConfigDriveUserdataNetworkData

Now it's the time to finally remove these 4 functions by first replacing all the calls for the utils functions with libvmi functions.

After this PR

4 deprecated util functions removed, and replaced with libvmi functionms.

For the implementation of this change, new factory function added to the libvmifact package:

  • NewCirrosNoUserData - this function creates a Cirros vmi, with no user-data, in order to user-defined user-data. The reason for that is that the existing NewCirros already adds CloudInitNoCloud UserData volume.
    This makes it hard to add other user-data volume, like CloudInitConfigDrive.

In addition, several user-data related libvmi options were added:

  • WithCloudInitNoCloudUserDataSecretName
  • WithCloudInitConfigDriveEncodedUserData
  • WithCloudInitConfigDriveUserDataSecretName
  • WithCloudInitConfigDriveNetworkData
  • WithCloudInitConfigDriveEncodedNetworkData
  • WithCloudInitConfigDriveNetworkDataSecretName

Now we can use the NewCirrosNoUserData factory, together with one of the new (or existing) user-data options; e.g.

vmi := libvmifact.NewCirrosNoUserData(libvmi.WithCloudInitNoCloudUserDataSecretName(secretName))

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. labels May 15, 2024
@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 dhiller, eddev 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

@nunnatsa nunnatsa force-pushed the rm-NewRandomVMIWithEphemeralDisk branch 3 times, most recently from be20e22 to 80e75eb Compare May 15, 2024 19:02
The existing `NewCirros` already adds CloudInitNoCloud UserData volume.
This makes it hard to add other user-data volume, like
CloudInitConfigDrive.

This commit add the new `NewCirrosNoUserData` to create cirros vmi with
no user data at all, so the lib user would be able to safly add thier
own volume.

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
Added the following libvmi options, to allow adding
different types of user data:

* `WithCloudInitNoCloudUserDataSecretName`
* `WithCloudInitConfigDriveEncodedUserData`
* `WithCloudInitConfigDriveUserDataSecretName`
* `WithCloudInitConfigDriveNetworkData`
* `WithCloudInitConfigDriveEncodedNetworkData`
* `WithCloudInitConfigDriveNetworkDataSecretName`

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
Stop using the deprecated
`NewRandomVMIWithEphemeralDiskAndConfigDriveUserdata`
function. Replaced with libvmi.

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
…rdata function

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
Stop using the deprecated
`NewRandomVMIWithEphemeralDiskAndConfigDriveUserdataNetworkData`
function. Replaced with libvmi.

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
…dataNetworkData function

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
NewRandomVMIWithEphemeralDiskAndUserdata is deprecated; use libvmi instead.

use libvmi instead.

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
NewRandomVMIWithEphemeralDiskAndUserdata is deprecated; use libvmi instead.

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
NewRandomVMIWithEphemeralDiskAndUserdata is deprecated; use libvmi instead.

use libvmi instead.

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
NewRandomVMIWithEphemeralDiskAndUserdata is deprecated; use libvmi instead.

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
@nunnatsa nunnatsa force-pushed the rm-NewRandomVMIWithEphemeralDisk branch from 80e75eb to f76d114 Compare May 16, 2024 05:07
@kubevirt-bot
Copy link
Contributor

kubevirt-bot commented May 16, 2024

@nunnatsa: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubevirt-check-tests-for-flakes f76d114 link false /test pull-kubevirt-check-tests-for-flakes

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. I understand the commands that are listed here.

@nunnatsa
Copy link
Contributor Author

/sig code-quality

Copy link
Contributor

@ormergi ormergi 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 the PR, its really nice seeing deprecated helper finally removed.

Just wanted to point out feedback I got on my take of getting rid of NewRandomVMIWithEphemeralDiskAndConfigDriveUserdata #11304.
The new CirrosNoCloudInit factory produce awkward VMI spec where it could hang on reboot for long period of time.
You documented it well, but having the factory available only where it should be use would prevent misuse 🙂
Since the new CirrosNoCloudInit factory is used only at vmi_cloudinit_test.go it would be easy change, please consider it.

Regarding the PR structure, please consider changing it in a way where removal or addition of code would be in the same commit with the changes that replace it (where possible).
For me it would make it easier to review 🙂

Comment on lines -53 to +55
withNonEmptyUserData := libvmi.WithCloudInitNoCloudEncodedUserData("#!/bin/bash\necho hello\n")
cirrosOpts := []libvmi.Option{
libvmi.WithCloudInitNoCloudEncodedUserData("#!/bin/bash\necho hello\n"),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I would not change the current state because withNonEmptyUserData makes the code more explanatory

Comment on lines +442 to +448
libvmi.WithInterface(v1.Interface{
Name: "default",
Tag: "specialNet",
InterfaceBindingMethod: v1.InterfaceBindingMethod{
Masquerade: &v1.InterfaceMasquerade{},
},
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I would keep it inline or emphesize the test subject field tag:

Suggested change
libvmi.WithInterface(v1.Interface{
Name: "default",
Tag: "specialNet",
InterfaceBindingMethod: v1.InterfaceBindingMethod{
Masquerade: &v1.InterfaceMasquerade{},
},
}),
libvmi.WithInterface(v1.Interface{Name: "default", InterfaceBindingMethod: v1.InterfaceBindingMethod{Masquerade: &v1.InterfaceMasquerade{},
Tag: "specialNet",
}}),

Comment on lines 565 to 576
// Store cloudinit data as k8s secret
By("Creating a secret with userdata")
uSecret := libsecret.New(uSecretID, libsecret.DataString{userDataLabel: testUserData})

_, err := virtClient.CoreV1().Secrets(vmi.Namespace).Create(context.Background(), uSecret, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
By("Creating a secret with network data")
nSecret := libsecret.New(nSecretID, libsecret.DataString{networkDataLabel: testNetworkData})

_, err = virtClient.CoreV1().Secrets(vmi.Namespace).Create(context.Background(), nSecret, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
_, err := virtClient.CoreV1().Secrets(vmi.Namespace).Create(context.Background(), uSecret, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())

break
}
_, err = virtClient.CoreV1().Secrets(vmi.Namespace).Create(context.Background(), nSecret, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
Copy link
Contributor

Choose a reason for hiding this comment

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

With this change the By statements indicate when the secret object is instantiated instead of actually be created by the client, in case of an issue it would be confusing to debug.

Could you please move the client create operations closer to the secret instantiation? (move line 572 right after 567)


By("Creating a secret with network data")
nSecret := libsecret.New(nSecretID, libsecret.DataString{networkDataLabel: testNetworkData})
// Store cloudinit data as k8s secret
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment doesnt add much value IMO, please consider removing it.


vmi := libvmifact.NewCirros()
vm = libvmi.NewVirtualMachine(vmi)
vm.Namespace = testsuite.GetTestNamespace(vmi)
Copy link
Contributor

Choose a reason for hiding this comment

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

In general I think its not effective to set namesapce for an object "manually", its better to spesify the namespace on creation instead, it makes the object state true to reality (as it have no namespace before actually created in the cluster), and reduce potential for unexpected behavior (since its specifying once).

The vmi is created with empty namespace, which make the result of testsuite.GetTestNamespace(vmi) similar to calling it with nil - testsuite.GetTestNamespace(nil).

I think we can simplify it by calling the VMI client create with testsuite.GetTestNamespace(nil) instead.
(I dont like the fact we call a function with 'nil', its all over the tests code though)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. But it failed on e2e, since in this test, we're using some other functions. I added it to make the test running.

}

// Store userdata as k8s secret
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, I think this comment add no value, please consider removing it.

@@ -525,7 +518,7 @@ var _ = Describe("[rfe_id:151][crit:high][vendor:cnv-qe@redhat.com][level:compon
By("Creating a secret with user and network data")
secret := libsecret.New(secretID, libsecret.DataString{"networkdata": testNetworkData})

_, err := virtClient.CoreV1().Secrets(vmi.Namespace).Create(context.Background(), secret, metav1.CreateOptions{})
_, err := virtClient.CoreV1().Secrets(testsuite.GetTestNamespace(vmi)).Create(context.Background(), secret, metav1.CreateOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, calling the VMI client create with testsuite.GetTestNamespace(nil) gives the same result and it will be consistent with the tests code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please notice that this is not vmi creation, but secret creation. the vmi.NS is not populated at this point.

@nunnatsa
Copy link
Contributor Author

The new CirrosNoCloudInit factory produce awkward VMI spec where it could hang on reboot for long period of time. You documented it well, but having the factory available only where it should be use would prevent misuse 🙂 Since the new CirrosNoCloudInit factory is used only at vmi_cloudinit_test.go it would be easy change, please consider it.

Agree, but then I'll have to export or copy the logic around the memory resources. So I prefer to keep it like that.

Copy link
Member

Choose a reason for hiding this comment

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

The need to double the builder functions (from 6 to 12) is a smell.

The original builders created for cloudinit probably did not expect to have this matrix of combinations.
But as it is clearly needed now, it is time to re-examine the existing to fit the need of the new.

Given we see now all these combinations, how could we make it better? Assume we can change/refactor the existing.

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. release-note-none Denotes a PR that doesn't merit a release note. sig/code-quality size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants