mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
@@ -1312,6 +1312,31 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"v1beta1.ISCSI": {
|
||||
"id": "v1beta1.ISCSI",
|
||||
"required": [
|
||||
"targetPortal",
|
||||
"iqn"
|
||||
],
|
||||
"properties": {
|
||||
"fsType": {
|
||||
"type": "string"
|
||||
},
|
||||
"lun": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"targetPortal": {
|
||||
"type": "string"
|
||||
},
|
||||
"readOnly": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"iqn": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"v1beta1.HTTPGetAction": {
|
||||
"id": "v1beta1.HTTPGetAction",
|
||||
"properties": {
|
||||
@@ -2042,7 +2067,8 @@
|
||||
"hostDir",
|
||||
"emptyDir",
|
||||
"persistentDisk",
|
||||
"gitRepo"
|
||||
"gitRepo",
|
||||
"iscsi"
|
||||
],
|
||||
"properties": {
|
||||
"emptyDir": {
|
||||
@@ -2056,7 +2082,10 @@
|
||||
},
|
||||
"persistentDisk": {
|
||||
"type": "v1beta1.GCEPersistentDisk"
|
||||
}
|
||||
},
|
||||
"iscsi": {
|
||||
"type": "v1beta1.ISCSI"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,6 +307,10 @@ func validateSource(source *api.VolumeSource) errs.ValidationErrorList {
|
||||
numVolumes++
|
||||
allErrs = append(allErrs, validateNFS(source.NFS).Prefix("nfs")...)
|
||||
}
|
||||
if source.ISCSI != nil {
|
||||
numVolumes++
|
||||
allErrs = append(allErrs, validateISCSIVolumeSource(source.ISCSI).Prefix("iscsi")...)
|
||||
}
|
||||
if numVolumes != 1 {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("", source, "exactly 1 volume type is required"))
|
||||
}
|
||||
@@ -329,6 +333,23 @@ func validateGitRepoVolumeSource(gitRepo *api.GitRepoVolumeSource) errs.Validati
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func validateISCSIVolumeSource(iscsi *api.ISCSIVolumeSource) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
if iscsi.TargetPortal == "" {
|
||||
allErrs = append(allErrs, errs.NewFieldRequired("targetPortal"))
|
||||
}
|
||||
if iscsi.IQN == "" {
|
||||
allErrs = append(allErrs, errs.NewFieldRequired("iqn"))
|
||||
}
|
||||
if iscsi.FSType == "" {
|
||||
allErrs = append(allErrs, errs.NewFieldRequired("fsType"))
|
||||
}
|
||||
if iscsi.Lun < 0 || iscsi.Lun > 255 {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("lun", iscsi.Lun, ""))
|
||||
}
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func validateGCEPersistentDiskVolumeSource(PD *api.GCEPersistentDiskVolumeSource) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
if PD.PDName == "" {
|
||||
|
||||
@@ -517,16 +517,19 @@ func TestValidateVolumes(t *testing.T) {
|
||||
{Name: "empty", VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}},
|
||||
{Name: "gcepd", VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{"my-PD", "ext4", 1, false}}},
|
||||
{Name: "gitrepo", VolumeSource: api.VolumeSource{GitRepo: &api.GitRepoVolumeSource{"my-repo", "hashstring"}}},
|
||||
{Name: "iscsidisk", VolumeSource: api.VolumeSource{ISCSI: &api.ISCSIVolumeSource{"127.0.0.1", "iqn.2015-02.example.com:test", 1, "ext4", false}}},
|
||||
{Name: "secret", VolumeSource: api.VolumeSource{Secret: &api.SecretVolumeSource{"my-secret"}}},
|
||||
}
|
||||
names, errs := validateVolumes(successCase)
|
||||
if len(errs) != 0 {
|
||||
t.Errorf("expected success: %v", errs)
|
||||
}
|
||||
if len(names) != len(successCase) || !names.HasAll("abc", "123", "abc-123", "empty", "gcepd", "gitrepo", "secret") {
|
||||
if len(names) != len(successCase) || !names.HasAll("abc", "123", "abc-123", "empty", "gcepd", "gitrepo", "secret", "iscsidisk") {
|
||||
t.Errorf("wrong names result: %v", names)
|
||||
}
|
||||
emptyVS := api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}
|
||||
emptyPortal := api.VolumeSource{ISCSI: &api.ISCSIVolumeSource{"", "iqn.2015-02.example.com:test", 1, "ext4", false}}
|
||||
emptyIQN := api.VolumeSource{ISCSI: &api.ISCSIVolumeSource{"127.0.0.1", "", 1, "ext4", false}}
|
||||
errorCases := map[string]struct {
|
||||
V []api.Volume
|
||||
T errors.ValidationErrorType
|
||||
@@ -536,6 +539,8 @@ func TestValidateVolumes(t *testing.T) {
|
||||
"name > 63 characters": {[]api.Volume{{Name: strings.Repeat("a", 64), VolumeSource: emptyVS}}, errors.ValidationErrorTypeInvalid, "[0].name"},
|
||||
"name not a DNS label": {[]api.Volume{{Name: "a.b.c", VolumeSource: emptyVS}}, errors.ValidationErrorTypeInvalid, "[0].name"},
|
||||
"name not unique": {[]api.Volume{{Name: "abc", VolumeSource: emptyVS}, {Name: "abc", VolumeSource: emptyVS}}, errors.ValidationErrorTypeDuplicate, "[1].name"},
|
||||
"empty portal": {[]api.Volume{{Name: "badportal", VolumeSource: emptyPortal}}, errors.ValidationErrorTypeRequired, "[0].source.iscsi.targetPortal"},
|
||||
"empty iqn": {[]api.Volume{{Name: "badiqn", VolumeSource: emptyIQN}}, errors.ValidationErrorTypeRequired, "[0].source.iscsi.iqn"},
|
||||
}
|
||||
for k, v := range errorCases {
|
||||
_, errs := validateVolumes(v.V)
|
||||
|
||||
Reference in New Issue
Block a user