API modified to use source; now supports EmptyDirectory

API is now modified to use a Source struct to handle multiple volumes.

Two volume types are supported now, HostDirectory and EmptyDirectory.
This commit is contained in:
Danny Jones
2014-07-16 12:32:59 -07:00
parent f1a7850454
commit bb2843498d
8 changed files with 104 additions and 41 deletions

View File

@@ -76,25 +76,46 @@ func validateVolumes(volumes []Volume) (util.StringSet, errorList) {
allNames := util.StringSet{}
for i := range volumes {
vol := &volumes[i] // so we can set default values
if vol.HostDirectory != nil {
errs := validateHostDir(vol.HostDirectory)
allErrs.Append(errs...)
errs := errorList{}
// TODO(thockin) enforce that a source is set once we deprecate the implied form.
if vol.Source != nil {
errs = validateSource(vol.Source)
}
if !util.IsDNSLabel(vol.Name) {
allErrs.Append(makeInvalidError("Volume.Name", vol.Name))
errs.Append(makeInvalidError("Volume.Name", vol.Name))
} else if allNames.Has(vol.Name) {
allErrs.Append(makeDuplicateError("Volume.Name", vol.Name))
} else {
errs.Append(makeDuplicateError("Volume.Name", vol.Name))
}
if len(errs) == 0 {
allNames.Insert(vol.Name)
} else {
allErrs.Append(errs...)
}
}
return allNames, allErrs
}
func validateSource(source *VolumeSource) errorList {
numVolumes := 0
allErrs := errorList{}
if source.HostDirectory != nil {
numVolumes++
allErrs.Append(validateHostDir(source.HostDirectory)...)
}
if source.EmptyDirectory != nil {
numVolumes++
//EmptyDirs have nothing to validate
}
if numVolumes != 1 {
allErrs.Append(makeInvalidError("Volume.Source", source))
}
return allErrs
}
func validateHostDir(hostDir *HostDirectory) errorList {
allErrs := errorList{}
if hostDir.Path == "" {
allErrs.Append(makeNotFoundError("Volume.HostDir.Path", hostDir.Path))
allErrs.Append(makeNotFoundError("HostDir.Path", hostDir.Path))
}
return allErrs
}
@@ -178,8 +199,6 @@ func validateVolumeMounts(mounts []VolumeMount, volumes util.StringSet) errorLis
if len(mnt.MountType) != 0 {
glog.Warning("DEPRECATED: VolumeMount.MountType will be removed. The Volume struct will handle types")
}
}
return allErrs
}