node: device-mgr: e2e: Update the e2e test to reproduce issue:109595

Breakdown of the steps implemented as part of this e2e test is as follows:
1. Create a file `registration` at path `/var/lib/kubelet/device-plugins/sample/`
2. Create sample device plugin with an environment variable with
   `REGISTER_CONTROL_FILE=/var/lib/kubelet/device-plugins/sample/registration` that
    waits for a client to delete the control file.
3. Trigger plugin registeration by deleting the abovementioned directory.
4. Create a test pod requesting devices exposed by the device plugin.
5. Stop kubelet.
6. Remove pods using CRI to ensure new pods are created after kubelet restart.
7. Restart kubelet.
8. Wait for the sample device plugin pod to be running. In this case,
   the registration is not triggered.
9. Ensure that resource capacity/allocatable exported by the device plugin is zero.
10. The test pod should fail with `UnexpectedAdmissionError`
11. Delete the test pod.
12. Delete the sample device plugin pod.
13. Remove `/var/lib/kubelet/device-plugins/sample/` and its content, the directory
    created to control registration

Signed-off-by: Swati Sehgal <swsehgal@redhat.com>
This commit is contained in:
Swati Sehgal
2022-12-24 02:15:33 +00:00
parent db7afc1cd8
commit 674879a959
2 changed files with 183 additions and 84 deletions

View File

@@ -87,11 +87,16 @@ func updateImageAllowList(ctx context.Context) {
} else {
e2epod.ImagePrePullList.Insert(gpuDevicePluginImage)
}
if samplePluginImage, err := getSampleDevicePluginImage(); err != nil {
if samplePluginImage, err := getContainerImageFromE2ETestDaemonset(SampleDevicePluginDSYAML); err != nil {
klog.Errorln(err)
} else {
e2epod.ImagePrePullList.Insert(samplePluginImage)
}
if samplePluginImageCtrlReg, err := getContainerImageFromE2ETestDaemonset(SampleDevicePluginControlRegistrationDSYAML); err != nil {
klog.Errorln(err)
} else {
e2epod.ImagePrePullList.Insert(samplePluginImageCtrlReg)
}
}
func getNodeProblemDetectorImage() string {
@@ -222,19 +227,19 @@ func getGPUDevicePluginImage(ctx context.Context) (string, error) {
return ds.Spec.Template.Spec.Containers[0].Image, nil
}
func getSampleDevicePluginImage() (string, error) {
data, err := e2etestfiles.Read(SampleDevicePluginDSYAML)
func getContainerImageFromE2ETestDaemonset(dsYamlPath string) (string, error) {
data, err := e2etestfiles.Read(dsYamlPath)
if err != nil {
return "", fmt.Errorf("failed to read the sample plugin yaml: %w", err)
return "", fmt.Errorf("failed to read the daemonset yaml: %w", err)
}
ds, err := e2emanifest.DaemonSetFromData(data)
if err != nil {
return "", fmt.Errorf("failed to parse daemon set for sample plugin: %w", err)
return "", fmt.Errorf("failed to parse daemonset yaml: %w", err)
}
if len(ds.Spec.Template.Spec.Containers) < 1 {
return "", fmt.Errorf("failed to parse the sample plugin image: cannot extract the container from YAML")
return "", fmt.Errorf("failed to parse the container image: cannot extract the container from YAML")
}
return ds.Spec.Template.Spec.Containers[0].Image, nil
}