Validate that PV capacity and PVC capacity requests are greater than zero

This commit is contained in:
Ian Chakeres
2017-11-11 15:39:37 -08:00
parent 81fa823a6c
commit 98e2c8cdee
3 changed files with 51 additions and 5 deletions

View File

@@ -260,6 +260,21 @@ func TestValidatePersistentVolumes(t *testing.T) {
},
}),
},
"bad-volume-zero-capacity": {
isExpectedFailure: true,
volume: testVolume("foo", "", core.PersistentVolumeSpec{
Capacity: core.ResourceList{
core.ResourceName(core.ResourceStorage): resource.MustParse("0"),
},
AccessModes: []core.PersistentVolumeAccessMode{core.ReadWriteOnce},
PersistentVolumeSource: core.PersistentVolumeSource{
HostPath: &core.HostPathVolumeSource{
Path: "/foo",
Type: newHostPathType(string(core.HostPathDirectory)),
},
},
}),
},
"missing-accessmodes": {
isExpectedFailure: true,
volume: testVolume("goodname", "missing-accessmodes", core.PersistentVolumeSpec{
@@ -732,6 +747,29 @@ func TestValidatePersistentVolumeClaim(t *testing.T) {
StorageClassName: &validClassName,
}),
},
"invalid-claim-zero-capacity": {
isExpectedFailure: true,
claim: testVolumeClaim("foo", "ns", core.PersistentVolumeClaimSpec{
Selector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "key2",
Operator: "Exists",
},
},
},
AccessModes: []core.PersistentVolumeAccessMode{
core.ReadWriteOnce,
core.ReadOnlyMany,
},
Resources: core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceName(core.ResourceStorage): resource.MustParse("0G"),
},
},
StorageClassName: &validClassName,
}),
},
"invalid-label-selector": {
isExpectedFailure: true,
claim: testVolumeClaim("foo", "ns", core.PersistentVolumeClaimSpec{