-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
base: main
Are you sure you want to change the base?
Remove NewRandomVMIWithEphemeralDisk from tests/utils.go #11923
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
be20e22
to
80e75eb
Compare
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>
80e75eb
to
f76d114
Compare
@nunnatsa: The following test failed, say
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. |
/sig code-quality |
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 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 🙂
withNonEmptyUserData := libvmi.WithCloudInitNoCloudEncodedUserData("#!/bin/bash\necho hello\n") | ||
cirrosOpts := []libvmi.Option{ | ||
libvmi.WithCloudInitNoCloudEncodedUserData("#!/bin/bash\necho hello\n"), | ||
} |
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 would not change the current state because withNonEmptyUserData
makes the code more explanatory
libvmi.WithInterface(v1.Interface{ | ||
Name: "default", | ||
Tag: "specialNet", | ||
InterfaceBindingMethod: v1.InterfaceBindingMethod{ | ||
Masquerade: &v1.InterfaceMasquerade{}, | ||
}, | ||
}), |
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.
nit: I would keep it inline or emphesize the test subject field tag
:
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", | |
}}), |
tests/vmi_cloudinit_test.go
Outdated
// 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()) |
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.
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 |
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.
This comment doesnt add much value IMO, please consider removing it.
|
||
vmi := libvmifact.NewCirros() | ||
vm = libvmi.NewVirtualMachine(vmi) | ||
vm.Namespace = testsuite.GetTestNamespace(vmi) |
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.
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)
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.
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 |
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.
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{}) |
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.
Same here, calling the VMI client create with testsuite.GetTestNamespace(nil)
gives the same result and it will be consistent with the tests code.
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.
please notice that this is not vmi creation, but secret creation. the vmi.NS is not populated at this point.
Agree, but then I'll have to export or copy the logic around the memory resources. So I prefer to keep it like that. |
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 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.
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 existingNewCirros
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.Release note