@@ -1001,29 +1001,58 @@ func Test_Run_Positive_VolumeFSResizeControllerAttachEnabled(t *testing.T) {
1001
1001
fsMode := v1 .PersistentVolumeFilesystem
1002
1002
1003
1003
var tests = []struct {
1004
- name string
1005
- volumeMode * v1.PersistentVolumeMode
1004
+ name string
1005
+ volumeMode * v1.PersistentVolumeMode
1006
+ expansionFailed bool
1007
+ pvName string
1008
+ pvcSize resource.Quantity
1009
+ pvcStatusSize resource.Quantity
1010
+ oldPVSize resource.Quantity
1011
+ newPVSize resource.Quantity
1006
1012
}{
1007
1013
{
1008
- name : "expand-fs-volume" ,
1009
- volumeMode : & fsMode ,
1014
+ name : "expand-fs-volume" ,
1015
+ volumeMode : & fsMode ,
1016
+ pvName : "pv" ,
1017
+ pvcSize : resource .MustParse ("10G" ),
1018
+ pvcStatusSize : resource .MustParse ("10G" ),
1019
+ newPVSize : resource .MustParse ("15G" ),
1020
+ oldPVSize : resource .MustParse ("10G" ),
1010
1021
},
1011
1022
{
1012
- name : "expand-raw-block" ,
1013
- volumeMode : & blockMode ,
1023
+ name : "expand-raw-block" ,
1024
+ volumeMode : & blockMode ,
1025
+ pvName : "pv" ,
1026
+ pvcSize : resource .MustParse ("10G" ),
1027
+ pvcStatusSize : resource .MustParse ("10G" ),
1028
+ newPVSize : resource .MustParse ("15G" ),
1029
+ oldPVSize : resource .MustParse ("10G" ),
1030
+ },
1031
+ {
1032
+ name : "expand-fs-volume with in-use error" ,
1033
+ volumeMode : & fsMode ,
1034
+ expansionFailed : true ,
1035
+ pvName : volumetesting .FailWithInUseVolumeName ,
1036
+ pvcSize : resource .MustParse ("10G" ),
1037
+ pvcStatusSize : resource .MustParse ("10G" ),
1038
+ newPVSize : resource .MustParse ("15G" ),
1039
+ oldPVSize : resource .MustParse ("13G" ),
1014
1040
},
1015
1041
}
1016
1042
1017
1043
for _ , tc := range tests {
1018
1044
t .Run (tc .name , func (t * testing.T ) {
1019
1045
pv := & v1.PersistentVolume {
1020
1046
ObjectMeta : metav1.ObjectMeta {
1021
- Name : "pv" ,
1047
+ Name : tc . pvName ,
1022
1048
UID : "pvuid" ,
1023
1049
},
1024
1050
Spec : v1.PersistentVolumeSpec {
1025
1051
ClaimRef : & v1.ObjectReference {Name : "pvc" },
1026
1052
VolumeMode : tc .volumeMode ,
1053
+ Capacity : v1.ResourceList {
1054
+ v1 .ResourceStorage : tc .oldPVSize ,
1055
+ },
1027
1056
},
1028
1057
}
1029
1058
pvc := & v1.PersistentVolumeClaim {
@@ -1032,9 +1061,19 @@ func Test_Run_Positive_VolumeFSResizeControllerAttachEnabled(t *testing.T) {
1032
1061
UID : "pvcuid" ,
1033
1062
},
1034
1063
Spec : v1.PersistentVolumeClaimSpec {
1064
+ Resources : v1.ResourceRequirements {
1065
+ Requests : v1.ResourceList {
1066
+ v1 .ResourceStorage : tc .pvcSize ,
1067
+ },
1068
+ },
1035
1069
VolumeName : "pv" ,
1036
1070
VolumeMode : tc .volumeMode ,
1037
1071
},
1072
+ Status : v1.PersistentVolumeClaimStatus {
1073
+ Capacity : v1.ResourceList {
1074
+ v1 .ResourceStorage : tc .pvcStatusSize ,
1075
+ },
1076
+ },
1038
1077
}
1039
1078
pod := & v1.Pod {
1040
1079
ObjectMeta : metav1.ObjectMeta {
@@ -1058,7 +1097,10 @@ func Test_Run_Positive_VolumeFSResizeControllerAttachEnabled(t *testing.T) {
1058
1097
volumePluginMgr , fakePlugin := volumetesting .GetTestVolumePluginMgr (t )
1059
1098
dsw := cache .NewDesiredStateOfWorld (volumePluginMgr )
1060
1099
asw := cache .NewActualStateOfWorld (nodeName , volumePluginMgr )
1061
- kubeClient := createtestClientWithPVPVC (pv , pvc )
1100
+ kubeClient := createtestClientWithPVPVC (pv , pvc , v1.AttachedVolume {
1101
+ Name : v1 .UniqueVolumeName (fmt .Sprintf ("fake-plugin/%s" , tc .pvName )),
1102
+ DevicePath : "fake/path" ,
1103
+ })
1062
1104
fakeRecorder := & record.FakeRecorder {}
1063
1105
fakeHandler := volumetesting .NewBlockVolumePathHandler ()
1064
1106
oex := operationexecutor .NewOperationExecutor (operationexecutor .NewOperationGenerator (
@@ -1104,24 +1146,36 @@ func Test_Run_Positive_VolumeFSResizeControllerAttachEnabled(t *testing.T) {
1104
1146
close (stopChan )
1105
1147
<- stoppedChan
1106
1148
1107
- // Mark volume as fsResizeRequired.
1149
+ // Simulate what DSOWP does
1150
+ pv .Spec .Capacity [v1 .ResourceStorage ] = tc .newPVSize
1151
+ volumeSpec = & volume.Spec {PersistentVolume : pv }
1152
+ dsw .AddPodToVolume (podName , pod , volumeSpec , volumeSpec .Name (), "" /* volumeGidValue */ )
1153
+ // mark volume as resize required
1108
1154
asw .MarkFSResizeRequired (volumeName , podName )
1155
+
1109
1156
_ , _ , podExistErr := asw .PodExistsInVolume (podName , volumeName )
1110
- if ! cache .IsFSResizeRequiredError (podExistErr ) {
1111
- t .Fatalf ("Volume should be marked as fsResizeRequired, but receive unexpected error: %v" , podExistErr )
1112
- }
1157
+ if tc .expansionFailed {
1158
+ if cache .IsFSResizeRequiredError (podExistErr ) {
1159
+ t .Fatalf ("volume %s should not throw fsResizeRequired error: %v" , volumeName , podExistErr )
1160
+ }
1161
+ } else {
1162
+ if ! cache .IsFSResizeRequiredError (podExistErr ) {
1163
+ t .Fatalf ("Volume should be marked as fsResizeRequired, but receive unexpected error: %v" , podExistErr )
1164
+ }
1113
1165
1114
- // Start the reconciler again, we hope reconciler will perform the
1115
- // resize operation and clear the fsResizeRequired flag for volume.
1116
- go reconciler .Run (wait .NeverStop )
1166
+ // Start the reconciler again, we hope reconciler will perform the
1167
+ // resize operation and clear the fsResizeRequired flag for volume.
1168
+ go reconciler .Run (wait .NeverStop )
1117
1169
1118
- waitErr := retryWithExponentialBackOff (testOperationBackOffDuration , func () (done bool , err error ) {
1119
- mounted , _ , err := asw .PodExistsInVolume (podName , volumeName )
1120
- return mounted && err == nil , nil
1121
- })
1122
- if waitErr != nil {
1123
- t .Fatal ("Volume resize should succeeded" )
1170
+ waitErr := retryWithExponentialBackOff (testOperationBackOffDuration , func () (done bool , err error ) {
1171
+ mounted , _ , err := asw .PodExistsInVolume (podName , volumeName )
1172
+ return mounted && err == nil , nil
1173
+ })
1174
+ if waitErr != nil {
1175
+ t .Fatal ("Volume resize should succeeded" )
1176
+ }
1124
1177
}
1178
+
1125
1179
})
1126
1180
}
1127
1181
}
@@ -1653,6 +1707,12 @@ func createtestClientWithPVPVC(pv *v1.PersistentVolume, pvc *v1.PersistentVolume
1653
1707
fakeClient .AddReactor ("get" , "persistentvolumes" , func (action core.Action ) (bool , runtime.Object , error ) {
1654
1708
return true , pv , nil
1655
1709
})
1710
+ fakeClient .AddReactor ("patch" , "persistentvolumeclaims" , func (action core.Action ) (bool , runtime.Object , error ) {
1711
+ if action .GetSubresource () == "status" {
1712
+ return true , pvc , nil
1713
+ }
1714
+ return true , nil , fmt .Errorf ("no reaction implemented for %s" , action )
1715
+ })
1656
1716
fakeClient .AddReactor ("*" , "*" , func (action core.Action ) (bool , runtime.Object , error ) {
1657
1717
return true , nil , fmt .Errorf ("no reaction implemented for %s" , action )
1658
1718
})
0 commit comments