Add StorageClassName validation

This commit is contained in:
Jan Safranek
2017-03-02 10:23:57 +01:00
parent 916a0a63dd
commit 39fa63d0a4
3 changed files with 58 additions and 1 deletions

View File

@@ -80,6 +80,7 @@ func TestValidatePersistentVolumes(t *testing.T) {
PersistentVolumeSource: api.PersistentVolumeSource{
HostPath: &api.HostPathVolumeSource{Path: "/foo"},
},
StorageClassName: "valid",
}),
},
"good-volume-with-retain-policy": {
@@ -230,6 +231,19 @@ func TestValidatePersistentVolumes(t *testing.T) {
},
}),
},
"invalid-storage-class-name": {
isExpectedFailure: true,
volume: testVolume("invalid-storage-class-name", "", api.PersistentVolumeSpec{
Capacity: api.ResourceList{
api.ResourceName(api.ResourceStorage): resource.MustParse("10G"),
},
AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce},
PersistentVolumeSource: api.PersistentVolumeSource{
HostPath: &api.HostPathVolumeSource{Path: "/foo"},
},
StorageClassName: "-invalid-",
}),
},
}
for name, scenario := range scenarios {
@@ -301,6 +315,8 @@ func testVolumeClaimAnnotation(name string, namespace string, ann string, annval
}
func TestValidatePersistentVolumeClaim(t *testing.T) {
invalidClassName := "-invalid-"
validClassName := "valid"
scenarios := map[string]struct {
isExpectedFailure bool
claim *api.PersistentVolumeClaim
@@ -325,6 +341,7 @@ func TestValidatePersistentVolumeClaim(t *testing.T) {
api.ResourceName(api.ResourceStorage): resource.MustParse("10G"),
},
},
StorageClassName: &validClassName,
}),
},
"invalid-label-selector": {
@@ -428,6 +445,29 @@ func TestValidatePersistentVolumeClaim(t *testing.T) {
},
}),
},
"invalid-storage-class-name": {
isExpectedFailure: true,
claim: testVolumeClaim("foo", "ns", api.PersistentVolumeClaimSpec{
Selector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "key2",
Operator: "Exists",
},
},
},
AccessModes: []api.PersistentVolumeAccessMode{
api.ReadWriteOnce,
api.ReadOnlyMany,
},
Resources: api.ResourceRequirements{
Requests: api.ResourceList{
api.ResourceName(api.ResourceStorage): resource.MustParse("10G"),
},
},
StorageClassName: &invalidClassName,
}),
},
}
for name, scenario := range scenarios {