mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Fix existing unit tests
This commit is contained in:
parent
b2e18c0b20
commit
de7f5b66ed
@ -67,10 +67,10 @@ func Test_AddPodToVolume_Positive_NewPodNewVolume(t *testing.T) {
|
|||||||
t.Fatalf("AddPodToVolume failed. Expected: <no error> Actual: <%v>", err)
|
t.Fatalf("AddPodToVolume failed. Expected: <no error> Actual: <%v>", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
verifyVolumeExistsDsw(t, generatedVolumeName, dsw)
|
verifyVolumeExistsDsw(t, generatedVolumeName, "" /* SELinuxContext */, dsw)
|
||||||
verifyVolumeExistsInVolumesToMount(
|
verifyVolumeExistsInVolumesToMount(
|
||||||
t, generatedVolumeName, false /* expectReportedInUse */, dsw)
|
t, generatedVolumeName, false /* expectReportedInUse */, dsw)
|
||||||
verifyPodExistsInVolumeDsw(t, podName, generatedVolumeName, dsw)
|
verifyPodExistsInVolumeDsw(t, podName, generatedVolumeName, "" /* SELinuxContext */, dsw)
|
||||||
verifyVolumeExistsWithSpecNameInVolumeDsw(t, podName, volumeSpec.Name(), dsw)
|
verifyVolumeExistsWithSpecNameInVolumeDsw(t, podName, volumeSpec.Name(), dsw)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,10 +112,10 @@ func Test_AddPodToVolume_Positive_ExistingPodExistingVolume(t *testing.T) {
|
|||||||
t.Fatalf("AddPodToVolume failed. Expected: <no error> Actual: <%v>", err)
|
t.Fatalf("AddPodToVolume failed. Expected: <no error> Actual: <%v>", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
verifyVolumeExistsDsw(t, generatedVolumeName, dsw)
|
verifyVolumeExistsDsw(t, generatedVolumeName, "" /* SELinuxContext */, dsw)
|
||||||
verifyVolumeExistsInVolumesToMount(
|
verifyVolumeExistsInVolumesToMount(
|
||||||
t, generatedVolumeName, false /* expectReportedInUse */, dsw)
|
t, generatedVolumeName, false /* expectReportedInUse */, dsw)
|
||||||
verifyPodExistsInVolumeDsw(t, podName, generatedVolumeName, dsw)
|
verifyPodExistsInVolumeDsw(t, podName, generatedVolumeName, "" /* SELinuxContext */, dsw)
|
||||||
verifyVolumeExistsWithSpecNameInVolumeDsw(t, podName, volumeSpec.Name(), dsw)
|
verifyVolumeExistsWithSpecNameInVolumeDsw(t, podName, volumeSpec.Name(), dsw)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,18 +314,18 @@ func Test_DeletePodFromVolume_Positive_PodExistsVolumeExists(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("AddPodToVolume failed. Expected: <no error> Actual: <%v>", err)
|
t.Fatalf("AddPodToVolume failed. Expected: <no error> Actual: <%v>", err)
|
||||||
}
|
}
|
||||||
verifyVolumeExistsDsw(t, generatedVolumeName, dsw)
|
verifyVolumeExistsDsw(t, generatedVolumeName, "" /* SELinuxContext */, dsw)
|
||||||
verifyVolumeExistsInVolumesToMount(
|
verifyVolumeExistsInVolumesToMount(
|
||||||
t, generatedVolumeName, false /* expectReportedInUse */, dsw)
|
t, generatedVolumeName, false /* expectReportedInUse */, dsw)
|
||||||
verifyPodExistsInVolumeDsw(t, podName, generatedVolumeName, dsw)
|
verifyPodExistsInVolumeDsw(t, podName, generatedVolumeName, "" /* SELinuxContext */, dsw)
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
dsw.DeletePodFromVolume(podName, generatedVolumeName)
|
dsw.DeletePodFromVolume(podName, generatedVolumeName)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
verifyVolumeDoesntExist(t, generatedVolumeName, dsw)
|
verifyVolumeDoesntExist(t, generatedVolumeName, "" /* SELinuxContext */, dsw)
|
||||||
verifyVolumeDoesntExistInVolumesToMount(t, generatedVolumeName, dsw)
|
verifyVolumeDoesntExistInVolumesToMount(t, generatedVolumeName, dsw)
|
||||||
verifyPodDoesntExistInVolumeDsw(t, podName, generatedVolumeName, dsw)
|
verifyPodDoesntExistInVolumeDsw(t, podName, generatedVolumeName, "" /* SELinuxContext */, dsw)
|
||||||
verifyVolumeDoesntExistWithSpecNameInVolumeDsw(t, podName, volumeSpec.Name(), dsw)
|
verifyVolumeDoesntExistWithSpecNameInVolumeDsw(t, podName, volumeSpec.Name(), dsw)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,36 +430,36 @@ func Test_MarkVolumesReportedInUse_Positive_NewPodNewVolume(t *testing.T) {
|
|||||||
dsw.MarkVolumesReportedInUse(volumesReportedInUse)
|
dsw.MarkVolumesReportedInUse(volumesReportedInUse)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
verifyVolumeExistsDsw(t, generatedVolume1Name, dsw)
|
verifyVolumeExistsDsw(t, generatedVolume1Name, "" /* SELinuxContext */, dsw)
|
||||||
verifyVolumeExistsInVolumesToMount(
|
verifyVolumeExistsInVolumesToMount(
|
||||||
t, generatedVolume1Name, false /* expectReportedInUse */, dsw)
|
t, generatedVolume1Name, false /* expectReportedInUse */, dsw)
|
||||||
verifyPodExistsInVolumeDsw(t, pod1Name, generatedVolume1Name, dsw)
|
verifyPodExistsInVolumeDsw(t, pod1Name, generatedVolume1Name, "" /* SELinuxContext */, dsw)
|
||||||
verifyVolumeExistsDsw(t, generatedVolume2Name, dsw)
|
verifyVolumeExistsDsw(t, generatedVolume2Name, "" /* SELinuxContext */, dsw)
|
||||||
verifyVolumeExistsInVolumesToMount(
|
verifyVolumeExistsInVolumesToMount(
|
||||||
t, generatedVolume2Name, true /* expectReportedInUse */, dsw)
|
t, generatedVolume2Name, true /* expectReportedInUse */, dsw)
|
||||||
verifyPodExistsInVolumeDsw(t, pod2Name, generatedVolume2Name, dsw)
|
verifyPodExistsInVolumeDsw(t, pod2Name, generatedVolume2Name, "" /* SELinuxContext */, dsw)
|
||||||
verifyVolumeExistsDsw(t, generatedVolume3Name, dsw)
|
verifyVolumeExistsDsw(t, generatedVolume3Name, "" /* SELinuxContext */, dsw)
|
||||||
verifyVolumeExistsInVolumesToMount(
|
verifyVolumeExistsInVolumesToMount(
|
||||||
t, generatedVolume3Name, false /* expectReportedInUse */, dsw)
|
t, generatedVolume3Name, false /* expectReportedInUse */, dsw)
|
||||||
verifyPodExistsInVolumeDsw(t, pod3Name, generatedVolume3Name, dsw)
|
verifyPodExistsInVolumeDsw(t, pod3Name, generatedVolume3Name, "" /* SELinuxContext */, dsw)
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
volumesReportedInUse = []v1.UniqueVolumeName{generatedVolume3Name}
|
volumesReportedInUse = []v1.UniqueVolumeName{generatedVolume3Name}
|
||||||
dsw.MarkVolumesReportedInUse(volumesReportedInUse)
|
dsw.MarkVolumesReportedInUse(volumesReportedInUse)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
verifyVolumeExistsDsw(t, generatedVolume1Name, dsw)
|
verifyVolumeExistsDsw(t, generatedVolume1Name, "" /* SELinuxContext */, dsw)
|
||||||
verifyVolumeExistsInVolumesToMount(
|
verifyVolumeExistsInVolumesToMount(
|
||||||
t, generatedVolume1Name, false /* expectReportedInUse */, dsw)
|
t, generatedVolume1Name, false /* expectReportedInUse */, dsw)
|
||||||
verifyPodExistsInVolumeDsw(t, pod1Name, generatedVolume1Name, dsw)
|
verifyPodExistsInVolumeDsw(t, pod1Name, generatedVolume1Name, "" /* SELinuxContext */, dsw)
|
||||||
verifyVolumeExistsDsw(t, generatedVolume2Name, dsw)
|
verifyVolumeExistsDsw(t, generatedVolume2Name, "" /* SELinuxContext */, dsw)
|
||||||
verifyVolumeExistsInVolumesToMount(
|
verifyVolumeExistsInVolumesToMount(
|
||||||
t, generatedVolume2Name, false /* expectReportedInUse */, dsw)
|
t, generatedVolume2Name, false /* expectReportedInUse */, dsw)
|
||||||
verifyPodExistsInVolumeDsw(t, pod2Name, generatedVolume2Name, dsw)
|
verifyPodExistsInVolumeDsw(t, pod2Name, generatedVolume2Name, "" /* SELinuxContext */, dsw)
|
||||||
verifyVolumeExistsDsw(t, generatedVolume3Name, dsw)
|
verifyVolumeExistsDsw(t, generatedVolume3Name, "" /* SELinuxContext */, dsw)
|
||||||
verifyVolumeExistsInVolumesToMount(
|
verifyVolumeExistsInVolumesToMount(
|
||||||
t, generatedVolume3Name, true /* expectReportedInUse */, dsw)
|
t, generatedVolume3Name, true /* expectReportedInUse */, dsw)
|
||||||
verifyPodExistsInVolumeDsw(t, pod3Name, generatedVolume3Name, dsw)
|
verifyPodExistsInVolumeDsw(t, pod3Name, generatedVolume3Name, "" /* SELinuxContext */, dsw)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_AddPodToVolume_WithEmptyDirSizeLimit(t *testing.T) {
|
func Test_AddPodToVolume_WithEmptyDirSizeLimit(t *testing.T) {
|
||||||
@ -598,8 +598,8 @@ func Test_AddPodToVolume_WithEmptyDirSizeLimit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func verifyVolumeExistsDsw(
|
func verifyVolumeExistsDsw(
|
||||||
t *testing.T, expectedVolumeName v1.UniqueVolumeName, dsw DesiredStateOfWorld) {
|
t *testing.T, expectedVolumeName v1.UniqueVolumeName, expectedSELinuxContext string, dsw DesiredStateOfWorld) {
|
||||||
volumeExists := dsw.VolumeExists(expectedVolumeName)
|
volumeExists := dsw.VolumeExists(expectedVolumeName, expectedSELinuxContext)
|
||||||
if !volumeExists {
|
if !volumeExists {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"VolumeExists(%q) failed. Expected: <true> Actual: <%v>",
|
"VolumeExists(%q) failed. Expected: <true> Actual: <%v>",
|
||||||
@ -609,8 +609,8 @@ func verifyVolumeExistsDsw(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func verifyVolumeDoesntExist(
|
func verifyVolumeDoesntExist(
|
||||||
t *testing.T, expectedVolumeName v1.UniqueVolumeName, dsw DesiredStateOfWorld) {
|
t *testing.T, expectedVolumeName v1.UniqueVolumeName, expectedSELinuxContext string, dsw DesiredStateOfWorld) {
|
||||||
volumeExists := dsw.VolumeExists(expectedVolumeName)
|
volumeExists := dsw.VolumeExists(expectedVolumeName, expectedSELinuxContext)
|
||||||
if volumeExists {
|
if volumeExists {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"VolumeExists(%q) returned incorrect value. Expected: <false> Actual: <%v>",
|
"VolumeExists(%q) returned incorrect value. Expected: <false> Actual: <%v>",
|
||||||
@ -661,9 +661,10 @@ func verifyPodExistsInVolumeDsw(
|
|||||||
t *testing.T,
|
t *testing.T,
|
||||||
expectedPodName volumetypes.UniquePodName,
|
expectedPodName volumetypes.UniquePodName,
|
||||||
expectedVolumeName v1.UniqueVolumeName,
|
expectedVolumeName v1.UniqueVolumeName,
|
||||||
|
expectedSeLinuxContext string,
|
||||||
dsw DesiredStateOfWorld) {
|
dsw DesiredStateOfWorld) {
|
||||||
if podExistsInVolume := dsw.PodExistsInVolume(
|
if podExistsInVolume := dsw.PodExistsInVolume(
|
||||||
expectedPodName, expectedVolumeName); !podExistsInVolume {
|
expectedPodName, expectedVolumeName, expectedSeLinuxContext); !podExistsInVolume {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"DSW PodExistsInVolume returned incorrect value. Expected: <true> Actual: <%v>",
|
"DSW PodExistsInVolume returned incorrect value. Expected: <true> Actual: <%v>",
|
||||||
podExistsInVolume)
|
podExistsInVolume)
|
||||||
@ -674,9 +675,10 @@ func verifyPodDoesntExistInVolumeDsw(
|
|||||||
t *testing.T,
|
t *testing.T,
|
||||||
expectedPodName volumetypes.UniquePodName,
|
expectedPodName volumetypes.UniquePodName,
|
||||||
expectedVolumeName v1.UniqueVolumeName,
|
expectedVolumeName v1.UniqueVolumeName,
|
||||||
|
expectedSeLinuxContext string,
|
||||||
dsw DesiredStateOfWorld) {
|
dsw DesiredStateOfWorld) {
|
||||||
if podExistsInVolume := dsw.PodExistsInVolume(
|
if podExistsInVolume := dsw.PodExistsInVolume(
|
||||||
expectedPodName, expectedVolumeName); podExistsInVolume {
|
expectedPodName, expectedVolumeName, expectedSeLinuxContext); podExistsInVolume {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"DSW PodExistsInVolume returned incorrect value. Expected: <true> Actual: <%v>",
|
"DSW PodExistsInVolume returned incorrect value. Expected: <true> Actual: <%v>",
|
||||||
podExistsInVolume)
|
podExistsInVolume)
|
||||||
|
@ -56,7 +56,7 @@ func TestMetricCollection(t *testing.T) {
|
|||||||
podName := util.GetUniquePodName(pod)
|
podName := util.GetUniquePodName(pod)
|
||||||
|
|
||||||
// Add one volume to DesiredStateOfWorld
|
// Add one volume to DesiredStateOfWorld
|
||||||
generatedVolumeName, err := dsw.AddPodToVolume(podName, pod, volumeSpec, volumeSpec.Name(), "", "" /* seLinuxLabel */)
|
generatedVolumeName, err := dsw.AddPodToVolume(podName, pod, volumeSpec, volumeSpec.Name(), "", nil /* seLinuxOptions */)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("AddPodToVolume failed. Expected: <no error> Actual: <%v>", err)
|
t.Fatalf("AddPodToVolume failed. Expected: <no error> Actual: <%v>", err)
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,7 @@ func TestFindAndAddNewPods_FindAndRemoveDeletedPods(t *testing.T) {
|
|||||||
t.Fatalf("Failed to remove pods from desired state of world since they no longer exist")
|
t.Fatalf("Failed to remove pods from desired state of world since they no longer exist")
|
||||||
}
|
}
|
||||||
|
|
||||||
volumeExists := dswp.desiredStateOfWorld.VolumeExists(expectedVolumeName)
|
volumeExists := dswp.desiredStateOfWorld.VolumeExists(expectedVolumeName, "" /* SELinuxContext */)
|
||||||
if volumeExists {
|
if volumeExists {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"VolumeExists(%q) failed. Expected: <false> Actual: <%v>",
|
"VolumeExists(%q) failed. Expected: <false> Actual: <%v>",
|
||||||
@ -252,7 +252,7 @@ func TestFindAndAddNewPods_FindAndRemoveDeletedPods(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if podExistsInVolume := dswp.desiredStateOfWorld.PodExistsInVolume(
|
if podExistsInVolume := dswp.desiredStateOfWorld.PodExistsInVolume(
|
||||||
podName, expectedVolumeName); podExistsInVolume {
|
podName, expectedVolumeName, "" /* SELinuxContext */); podExistsInVolume {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"DSW PodExistsInVolume returned incorrect value. Expected: <false> Actual: <%v>",
|
"DSW PodExistsInVolume returned incorrect value. Expected: <false> Actual: <%v>",
|
||||||
podExistsInVolume)
|
podExistsInVolume)
|
||||||
@ -283,7 +283,7 @@ func TestFindAndRemoveDeletedPodsWithActualState(t *testing.T) {
|
|||||||
dswp.findAndRemoveDeletedPods()
|
dswp.findAndRemoveDeletedPods()
|
||||||
// Although Pod status is terminated, pod still exists in pod manager and actual state does not has this pod and volume information
|
// Although Pod status is terminated, pod still exists in pod manager and actual state does not has this pod and volume information
|
||||||
// desired state populator will fail to delete this pod and volume first
|
// desired state populator will fail to delete this pod and volume first
|
||||||
volumeExists := dswp.desiredStateOfWorld.VolumeExists(expectedVolumeName)
|
volumeExists := dswp.desiredStateOfWorld.VolumeExists(expectedVolumeName, "" /* SELinuxContext */)
|
||||||
if !volumeExists {
|
if !volumeExists {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"VolumeExists(%q) failed. Expected: <true> Actual: <%v>",
|
"VolumeExists(%q) failed. Expected: <true> Actual: <%v>",
|
||||||
@ -292,7 +292,7 @@ func TestFindAndRemoveDeletedPodsWithActualState(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if podExistsInVolume := dswp.desiredStateOfWorld.PodExistsInVolume(
|
if podExistsInVolume := dswp.desiredStateOfWorld.PodExistsInVolume(
|
||||||
podName, expectedVolumeName); !podExistsInVolume {
|
podName, expectedVolumeName, "" /* SELinuxContext */); !podExistsInVolume {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"DSW PodExistsInVolume returned incorrect value. Expected: <true> Actual: <%v>",
|
"DSW PodExistsInVolume returned incorrect value. Expected: <true> Actual: <%v>",
|
||||||
podExistsInVolume)
|
podExistsInVolume)
|
||||||
@ -302,7 +302,7 @@ func TestFindAndRemoveDeletedPodsWithActualState(t *testing.T) {
|
|||||||
// desired state populator now can successfully delete the pod and volume
|
// desired state populator now can successfully delete the pod and volume
|
||||||
reconcileASW(fakeASW, dswp.desiredStateOfWorld, t)
|
reconcileASW(fakeASW, dswp.desiredStateOfWorld, t)
|
||||||
dswp.findAndRemoveDeletedPods()
|
dswp.findAndRemoveDeletedPods()
|
||||||
if !dswp.desiredStateOfWorld.VolumeExists(expectedVolumeName) {
|
if !dswp.desiredStateOfWorld.VolumeExists(expectedVolumeName, "" /* SELinuxContext */) {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"VolumeExists(%q) failed. Expected: <false> Actual: <%v>",
|
"VolumeExists(%q) failed. Expected: <false> Actual: <%v>",
|
||||||
expectedVolumeName,
|
expectedVolumeName,
|
||||||
@ -315,7 +315,7 @@ func TestFindAndRemoveDeletedPodsWithActualState(t *testing.T) {
|
|||||||
// desired state populator now can successfully delete the pod and volume
|
// desired state populator now can successfully delete the pod and volume
|
||||||
reconcileASW(fakeASW, dswp.desiredStateOfWorld, t)
|
reconcileASW(fakeASW, dswp.desiredStateOfWorld, t)
|
||||||
dswp.findAndRemoveDeletedPods()
|
dswp.findAndRemoveDeletedPods()
|
||||||
volumeExists = dswp.desiredStateOfWorld.VolumeExists(expectedVolumeName)
|
volumeExists = dswp.desiredStateOfWorld.VolumeExists(expectedVolumeName, "" /* SELinuxContext */)
|
||||||
if volumeExists {
|
if volumeExists {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"VolumeExists(%q) failed. Expected: <false> Actual: <%v>",
|
"VolumeExists(%q) failed. Expected: <false> Actual: <%v>",
|
||||||
@ -324,7 +324,7 @@ func TestFindAndRemoveDeletedPodsWithActualState(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if podExistsInVolume := dswp.desiredStateOfWorld.PodExistsInVolume(
|
if podExistsInVolume := dswp.desiredStateOfWorld.PodExistsInVolume(
|
||||||
podName, expectedVolumeName); podExistsInVolume {
|
podName, expectedVolumeName, "" /* SELinuxContext */); podExistsInVolume {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"DSW PodExistsInVolume returned incorrect value. Expected: <false> Actual: <%v>",
|
"DSW PodExistsInVolume returned incorrect value. Expected: <false> Actual: <%v>",
|
||||||
podExistsInVolume)
|
podExistsInVolume)
|
||||||
@ -369,7 +369,7 @@ func TestFindAndRemoveDeletedPodsWithUncertain(t *testing.T) {
|
|||||||
t.Fatalf("Failed to remove pods from desired state of world since they no longer exist")
|
t.Fatalf("Failed to remove pods from desired state of world since they no longer exist")
|
||||||
}
|
}
|
||||||
|
|
||||||
volumeExists := dswp.desiredStateOfWorld.VolumeExists(expectedVolumeName)
|
volumeExists := dswp.desiredStateOfWorld.VolumeExists(expectedVolumeName, "" /* SELinuxContext */)
|
||||||
if volumeExists {
|
if volumeExists {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"VolumeExists(%q) failed. Expected: <false> Actual: <%v>",
|
"VolumeExists(%q) failed. Expected: <false> Actual: <%v>",
|
||||||
@ -378,7 +378,7 @@ func TestFindAndRemoveDeletedPodsWithUncertain(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if podExistsInVolume := dswp.desiredStateOfWorld.PodExistsInVolume(
|
if podExistsInVolume := dswp.desiredStateOfWorld.PodExistsInVolume(
|
||||||
podName, expectedVolumeName); podExistsInVolume {
|
podName, expectedVolumeName, "" /* SELinuxContext */); podExistsInVolume {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"DSW PodExistsInVolume returned incorrect value. Expected: <false> Actual: <%v>",
|
"DSW PodExistsInVolume returned incorrect value. Expected: <false> Actual: <%v>",
|
||||||
podExistsInVolume)
|
podExistsInVolume)
|
||||||
@ -443,7 +443,7 @@ func prepareDSWPWithPodPV(t *testing.T) (*desiredStateOfWorldPopulator, *fakePod
|
|||||||
|
|
||||||
expectedVolumeName := v1.UniqueVolumeName(generatedVolumeName)
|
expectedVolumeName := v1.UniqueVolumeName(generatedVolumeName)
|
||||||
|
|
||||||
volumeExists := fakesDSW.VolumeExists(expectedVolumeName)
|
volumeExists := fakesDSW.VolumeExists(expectedVolumeName, "" /* SELinuxContext */)
|
||||||
if !volumeExists {
|
if !volumeExists {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"VolumeExists(%q) failed. Expected: <true> Actual: <%v>",
|
"VolumeExists(%q) failed. Expected: <true> Actual: <%v>",
|
||||||
@ -452,7 +452,7 @@ func prepareDSWPWithPodPV(t *testing.T) (*desiredStateOfWorldPopulator, *fakePod
|
|||||||
}
|
}
|
||||||
|
|
||||||
if podExistsInVolume := fakesDSW.PodExistsInVolume(
|
if podExistsInVolume := fakesDSW.PodExistsInVolume(
|
||||||
podName, expectedVolumeName); !podExistsInVolume {
|
podName, expectedVolumeName, "" /* SELinuxContext */); !podExistsInVolume {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"DSW PodExistsInVolume returned incorrect value. Expected: <true> Actual: <%v>",
|
"DSW PodExistsInVolume returned incorrect value. Expected: <true> Actual: <%v>",
|
||||||
podExistsInVolume)
|
podExistsInVolume)
|
||||||
@ -514,7 +514,7 @@ func TestFindAndRemoveNonattachableVolumes(t *testing.T) {
|
|||||||
|
|
||||||
expectedVolumeName := v1.UniqueVolumeName(generatedVolumeName)
|
expectedVolumeName := v1.UniqueVolumeName(generatedVolumeName)
|
||||||
|
|
||||||
volumeExists := fakesDSW.VolumeExists(expectedVolumeName)
|
volumeExists := fakesDSW.VolumeExists(expectedVolumeName, "" /* SELinuxContext */)
|
||||||
if !volumeExists {
|
if !volumeExists {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"VolumeExists(%q) failed. Expected: <true> Actual: <%v>",
|
"VolumeExists(%q) failed. Expected: <true> Actual: <%v>",
|
||||||
@ -614,7 +614,7 @@ func TestFindAndAddNewPods_FindAndRemoveDeletedPods_Valid_Block_VolumeDevices(t
|
|||||||
|
|
||||||
expectedVolumeName := v1.UniqueVolumeName(generatedVolumeName)
|
expectedVolumeName := v1.UniqueVolumeName(generatedVolumeName)
|
||||||
|
|
||||||
volumeExists := fakesDSW.VolumeExists(expectedVolumeName)
|
volumeExists := fakesDSW.VolumeExists(expectedVolumeName, "" /* SELinuxContext */)
|
||||||
if !volumeExists {
|
if !volumeExists {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"VolumeExists(%q) failed. Expected: <true> Actual: <%v>",
|
"VolumeExists(%q) failed. Expected: <true> Actual: <%v>",
|
||||||
@ -623,7 +623,7 @@ func TestFindAndAddNewPods_FindAndRemoveDeletedPods_Valid_Block_VolumeDevices(t
|
|||||||
}
|
}
|
||||||
|
|
||||||
if podExistsInVolume := fakesDSW.PodExistsInVolume(
|
if podExistsInVolume := fakesDSW.PodExistsInVolume(
|
||||||
podName, expectedVolumeName); !podExistsInVolume {
|
podName, expectedVolumeName, "" /* SELinuxContext */); !podExistsInVolume {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"DSW PodExistsInVolume returned incorrect value. Expected: <true> Actual: <%v>",
|
"DSW PodExistsInVolume returned incorrect value. Expected: <true> Actual: <%v>",
|
||||||
podExistsInVolume)
|
podExistsInVolume)
|
||||||
@ -647,7 +647,7 @@ func TestFindAndAddNewPods_FindAndRemoveDeletedPods_Valid_Block_VolumeDevices(t
|
|||||||
t.Fatalf("Failed to remove pods from desired state of world since they no longer exist")
|
t.Fatalf("Failed to remove pods from desired state of world since they no longer exist")
|
||||||
}
|
}
|
||||||
|
|
||||||
volumeExists = fakesDSW.VolumeExists(expectedVolumeName)
|
volumeExists = fakesDSW.VolumeExists(expectedVolumeName, "" /* SELinuxContext */)
|
||||||
if volumeExists {
|
if volumeExists {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"VolumeExists(%q) failed. Expected: <false> Actual: <%v>",
|
"VolumeExists(%q) failed. Expected: <false> Actual: <%v>",
|
||||||
@ -656,7 +656,7 @@ func TestFindAndAddNewPods_FindAndRemoveDeletedPods_Valid_Block_VolumeDevices(t
|
|||||||
}
|
}
|
||||||
|
|
||||||
if podExistsInVolume := fakesDSW.PodExistsInVolume(
|
if podExistsInVolume := fakesDSW.PodExistsInVolume(
|
||||||
podName, expectedVolumeName); podExistsInVolume {
|
podName, expectedVolumeName, "" /* SELinuxContext */); podExistsInVolume {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"DSW PodExistsInVolume returned incorrect value. Expected: <false> Actual: <%v>",
|
"DSW PodExistsInVolume returned incorrect value. Expected: <false> Actual: <%v>",
|
||||||
podExistsInVolume)
|
podExistsInVolume)
|
||||||
@ -709,7 +709,7 @@ func TestCreateVolumeSpec_Valid_File_VolumeMounts(t *testing.T) {
|
|||||||
pod := createPodWithVolume("dswp-test-pod", "dswp-test-volume-name", "file-bound", containers)
|
pod := createPodWithVolume("dswp-test-pod", "dswp-test-volume-name", "file-bound", containers)
|
||||||
|
|
||||||
fakePodManager.AddPod(pod)
|
fakePodManager.AddPod(pod)
|
||||||
mountsMap, devicesMap := util.GetPodVolumeNames(pod)
|
mountsMap, devicesMap, _ := util.GetPodVolumeNames(pod)
|
||||||
_, volumeSpec, _, err :=
|
_, volumeSpec, _, err :=
|
||||||
dswp.createVolumeSpec(pod.Spec.Volumes[0], pod, mountsMap, devicesMap)
|
dswp.createVolumeSpec(pod.Spec.Volumes[0], pod, mountsMap, devicesMap)
|
||||||
|
|
||||||
@ -755,7 +755,7 @@ func TestCreateVolumeSpec_Valid_Nil_VolumeMounts(t *testing.T) {
|
|||||||
pod := createPodWithVolume("dswp-test-pod", "dswp-test-volume-name", "file-bound", containers)
|
pod := createPodWithVolume("dswp-test-pod", "dswp-test-volume-name", "file-bound", containers)
|
||||||
|
|
||||||
fakePodManager.AddPod(pod)
|
fakePodManager.AddPod(pod)
|
||||||
mountsMap, devicesMap := util.GetPodVolumeNames(pod)
|
mountsMap, devicesMap, _ := util.GetPodVolumeNames(pod)
|
||||||
_, volumeSpec, _, err :=
|
_, volumeSpec, _, err :=
|
||||||
dswp.createVolumeSpec(pod.Spec.Volumes[0], pod, mountsMap, devicesMap)
|
dswp.createVolumeSpec(pod.Spec.Volumes[0], pod, mountsMap, devicesMap)
|
||||||
|
|
||||||
@ -801,7 +801,7 @@ func TestCreateVolumeSpec_Valid_Block_VolumeDevices(t *testing.T) {
|
|||||||
pod := createPodWithVolume("dswp-test-pod", "dswp-test-volume-name", "block-bound", containers)
|
pod := createPodWithVolume("dswp-test-pod", "dswp-test-volume-name", "block-bound", containers)
|
||||||
|
|
||||||
fakePodManager.AddPod(pod)
|
fakePodManager.AddPod(pod)
|
||||||
mountsMap, devicesMap := util.GetPodVolumeNames(pod)
|
mountsMap, devicesMap, _ := util.GetPodVolumeNames(pod)
|
||||||
_, volumeSpec, _, err :=
|
_, volumeSpec, _, err :=
|
||||||
dswp.createVolumeSpec(pod.Spec.Volumes[0], pod, mountsMap, devicesMap)
|
dswp.createVolumeSpec(pod.Spec.Volumes[0], pod, mountsMap, devicesMap)
|
||||||
|
|
||||||
@ -847,7 +847,7 @@ func TestCreateVolumeSpec_Invalid_File_VolumeDevices(t *testing.T) {
|
|||||||
pod := createPodWithVolume("dswp-test-pod", "dswp-test-volume-name", "file-bound", containers)
|
pod := createPodWithVolume("dswp-test-pod", "dswp-test-volume-name", "file-bound", containers)
|
||||||
|
|
||||||
fakePodManager.AddPod(pod)
|
fakePodManager.AddPod(pod)
|
||||||
mountsMap, devicesMap := util.GetPodVolumeNames(pod)
|
mountsMap, devicesMap, _ := util.GetPodVolumeNames(pod)
|
||||||
_, volumeSpec, _, err :=
|
_, volumeSpec, _, err :=
|
||||||
dswp.createVolumeSpec(pod.Spec.Volumes[0], pod, mountsMap, devicesMap)
|
dswp.createVolumeSpec(pod.Spec.Volumes[0], pod, mountsMap, devicesMap)
|
||||||
|
|
||||||
@ -893,7 +893,7 @@ func TestCreateVolumeSpec_Invalid_Block_VolumeMounts(t *testing.T) {
|
|||||||
pod := createPodWithVolume("dswp-test-pod", "dswp-test-volume-name", "block-bound", containers)
|
pod := createPodWithVolume("dswp-test-pod", "dswp-test-volume-name", "block-bound", containers)
|
||||||
|
|
||||||
fakePodManager.AddPod(pod)
|
fakePodManager.AddPod(pod)
|
||||||
mountsMap, devicesMap := util.GetPodVolumeNames(pod)
|
mountsMap, devicesMap, _ := util.GetPodVolumeNames(pod)
|
||||||
_, volumeSpec, _, err :=
|
_, volumeSpec, _, err :=
|
||||||
dswp.createVolumeSpec(pod.Spec.Volumes[0], pod, mountsMap, devicesMap)
|
dswp.createVolumeSpec(pod.Spec.Volumes[0], pod, mountsMap, devicesMap)
|
||||||
|
|
||||||
@ -1142,7 +1142,7 @@ func reprocess(dswp *desiredStateOfWorldPopulator, uniquePodName types.UniquePod
|
|||||||
func getResizeRequiredVolumes(dsw cache.DesiredStateOfWorld, asw cache.ActualStateOfWorld, newSize resource.Quantity) []v1.UniqueVolumeName {
|
func getResizeRequiredVolumes(dsw cache.DesiredStateOfWorld, asw cache.ActualStateOfWorld, newSize resource.Quantity) []v1.UniqueVolumeName {
|
||||||
resizeRequiredVolumes := []v1.UniqueVolumeName{}
|
resizeRequiredVolumes := []v1.UniqueVolumeName{}
|
||||||
for _, volumeToMount := range dsw.GetVolumesToMount() {
|
for _, volumeToMount := range dsw.GetVolumesToMount() {
|
||||||
_, _, err := asw.PodExistsInVolume(volumeToMount.PodName, volumeToMount.VolumeName, newSize)
|
_, _, err := asw.PodExistsInVolume(volumeToMount.PodName, volumeToMount.VolumeName, newSize, "" /* SELinuxContext */)
|
||||||
if cache.IsFSResizeRequiredError(err) {
|
if cache.IsFSResizeRequiredError(err) {
|
||||||
resizeRequiredVolumes = append(resizeRequiredVolumes, volumeToMount.VolumeName)
|
resizeRequiredVolumes = append(resizeRequiredVolumes, volumeToMount.VolumeName)
|
||||||
}
|
}
|
||||||
|
@ -260,7 +260,13 @@ func Test_Run_Positive_VolumeAttachAndMountMigrationEnabled(t *testing.T) {
|
|||||||
|
|
||||||
podName := util.GetUniquePodName(pod)
|
podName := util.GetUniquePodName(pod)
|
||||||
generatedVolumeName, err := dsw.AddPodToVolume(
|
generatedVolumeName, err := dsw.AddPodToVolume(
|
||||||
podName, pod, migratedSpec, migratedSpec.Name(), "" /* volumeGidValue */)
|
podName,
|
||||||
|
pod,
|
||||||
|
migratedSpec,
|
||||||
|
migratedSpec.Name(),
|
||||||
|
"", /* volumeGidValue */
|
||||||
|
nil, /* SELinuxContexts */
|
||||||
|
)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1340,13 +1346,13 @@ func Test_Run_Positive_VolumeFSResizeControllerAttachEnabled(t *testing.T) {
|
|||||||
// Simulate what DSOWP does
|
// Simulate what DSOWP does
|
||||||
pvWithSize.Spec.Capacity[v1.ResourceStorage] = tc.newPVSize
|
pvWithSize.Spec.Capacity[v1.ResourceStorage] = tc.newPVSize
|
||||||
volumeSpec = &volume.Spec{PersistentVolume: pvWithSize}
|
volumeSpec = &volume.Spec{PersistentVolume: pvWithSize}
|
||||||
dsw.AddPodToVolume(podName, pod, volumeSpec, volumeSpec.Name(), "" /* volumeGidValue */, nil /* seLinuxLabel */)
|
dsw.AddPodToVolume(podName, pod, volumeSpec, volumeSpec.Name(), "" /* volumeGidValue */, nil /* seLinuxContexts */)
|
||||||
|
|
||||||
t.Logf("Changing size of the volume to %s", tc.newPVSize.String())
|
t.Logf("Changing size of the volume to %s", tc.newPVSize.String())
|
||||||
newSize := tc.newPVSize.DeepCopy()
|
newSize := tc.newPVSize.DeepCopy()
|
||||||
dsw.UpdatePersistentVolumeSize(volumeName, &newSize)
|
dsw.UpdatePersistentVolumeSize(volumeName, &newSize)
|
||||||
|
|
||||||
_, _, podExistErr := asw.PodExistsInVolume(podName, volumeName, newSize)
|
_, _, podExistErr := asw.PodExistsInVolume(podName, volumeName, newSize, "" /* SELinuxLabel */)
|
||||||
if tc.expansionFailed {
|
if tc.expansionFailed {
|
||||||
if cache.IsFSResizeRequiredError(podExistErr) {
|
if cache.IsFSResizeRequiredError(podExistErr) {
|
||||||
t.Fatalf("volume %s should not throw fsResizeRequired error: %v", volumeName, podExistErr)
|
t.Fatalf("volume %s should not throw fsResizeRequired error: %v", volumeName, podExistErr)
|
||||||
@ -1358,7 +1364,7 @@ func Test_Run_Positive_VolumeFSResizeControllerAttachEnabled(t *testing.T) {
|
|||||||
go reconciler.Run(wait.NeverStop)
|
go reconciler.Run(wait.NeverStop)
|
||||||
|
|
||||||
waitErr := retryWithExponentialBackOff(testOperationBackOffDuration, func() (done bool, err error) {
|
waitErr := retryWithExponentialBackOff(testOperationBackOffDuration, func() (done bool, err error) {
|
||||||
mounted, _, err := asw.PodExistsInVolume(podName, volumeName, newSize)
|
mounted, _, err := asw.PodExistsInVolume(podName, volumeName, newSize, "" /* SELinuxContext */)
|
||||||
return mounted && err == nil, nil
|
return mounted && err == nil, nil
|
||||||
})
|
})
|
||||||
if waitErr != nil {
|
if waitErr != nil {
|
||||||
@ -1913,7 +1919,7 @@ func waitForUncertainPodMount(t *testing.T, volumeName v1.UniqueVolumeName, podN
|
|||||||
err := retryWithExponentialBackOff(
|
err := retryWithExponentialBackOff(
|
||||||
testOperationBackOffDuration,
|
testOperationBackOffDuration,
|
||||||
func() (bool, error) {
|
func() (bool, error) {
|
||||||
mounted, _, err := asw.PodExistsInVolume(podName, volumeName, resource.Quantity{})
|
mounted, _, err := asw.PodExistsInVolume(podName, volumeName, resource.Quantity{}, "" /* SELinuxContext */)
|
||||||
if mounted || err != nil {
|
if mounted || err != nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
@ -785,7 +785,7 @@ func TestGetPodVolumeNames(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
mounts, devices := GetPodVolumeNames(test.pod)
|
mounts, devices, _ := GetPodVolumeNames(test.pod)
|
||||||
if !mounts.Equal(test.expectedMounts) {
|
if !mounts.Equal(test.expectedMounts) {
|
||||||
t.Errorf("Expected mounts: %q, got %q", mounts.List(), test.expectedMounts.List())
|
t.Errorf("Expected mounts: %q, got %q", mounts.List(), test.expectedMounts.List())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user