in gce-containers-startup/volumes/volumes.go [245:286]
func (env Env) buildVolumeNameToHostPathMap(apiVolumes []api.Volume, volumeMountWantsReadWriteMap map[string]bool) (map[string]VolumeHostPathAndMode, error) {
// For each volume, use the proper handler function to build the volume name -> hostpath+mode map.
volumeNameToHostPathMap := map[string]VolumeHostPathAndMode{}
diskMetadataReadOnlyMap, err := env.buildDiskMetadataReadOnlyMap()
if err != nil {
return nil, fmt.Errorf("Failed to build disk read only map from metadata: %s", err)
}
for _, apiVolume := range apiVolumes {
volumeMountWantsReadWrite, found := volumeMountWantsReadWriteMap[apiVolume.Name]
if !found {
return nil, fmt.Errorf("apiVolume %s not found in the volumeMount RW map. This should not happen.", apiVolume.Name)
}
// Enforce exactly one volume definition.
definitions := 0
var volumeHostPathAndMode VolumeHostPathAndMode
var processError error
if apiVolume.HostPath != nil {
definitions++
volumeHostPathAndMode, processError = env.processHostPathVolume(apiVolume.HostPath)
}
if apiVolume.EmptyDir != nil {
definitions++
volumeHostPathAndMode, processError = env.processEmptyDirVolume(apiVolume.EmptyDir, apiVolume.Name)
}
if apiVolume.GcePersistentDisk != nil {
definitions++
volumeHostPathAndMode, processError = env.processGcePersistentDiskVolume(apiVolume.GcePersistentDisk, volumeMountWantsReadWrite, diskMetadataReadOnlyMap)
}
if definitions != 1 {
return nil, fmt.Errorf("Invalid container declaration: Exactly one volume specification required for volume %s, %d found.", apiVolume.Name, definitions)
}
if processError != nil {
return nil, fmt.Errorf("Volume %s: %s", apiVolume.Name, processError)
} else {
volumeNameToHostPathMap[apiVolume.Name] = volumeHostPathAndMode
}
}
return volumeNameToHostPathMap, nil
}