Fix partition for 0 partitions defaulting

pull/564/head
David Zhu 2019-03-04 17:26:01 -08:00
parent feb0937fa4
commit e59f261c12
1 changed files with 8 additions and 2 deletions

View File

@ -87,13 +87,19 @@ func (g *gcePersistentDiskCSITranslator) TranslateInTreePVToCSI(pv *v1.Persisten
}
gceSource := pv.Spec.PersistentVolumeSource.GCEPersistentDisk
partition := ""
if gceSource.Partition != 0 {
partition = strconv.Itoa(int(gceSource.Partition))
}
csiSource := &v1.CSIPersistentVolumeSource{
Driver: GCEPDDriverName,
VolumeHandle: volID,
ReadOnly: gceSource.ReadOnly,
FSType: gceSource.FSType,
VolumeAttributes: map[string]string{
"partition": strconv.FormatInt(int64(gceSource.Partition), 10),
"partition": partition,
},
}
@ -121,7 +127,7 @@ func (g *gcePersistentDiskCSITranslator) TranslateCSIPVToInTree(pv *v1.Persisten
FSType: csiSource.FSType,
ReadOnly: csiSource.ReadOnly,
}
if partition, ok := csiSource.VolumeAttributes["partition"]; ok {
if partition, ok := csiSource.VolumeAttributes["partition"]; ok && partition != "" {
partInt, err := strconv.Atoi(partition)
if err != nil {
return nil, fmt.Errorf("Failed to convert partition %v to integer: %v", partition, err)