Skip to content

Commit 21b0cac

Browse files
authored
Merge pull request kubernetes#74932 from davidz627/fix/gcePartitionTranslation
Fix 0 partitions defaulting for CSI Translation Library
2 parents 365c504 + e59f261 commit 21b0cac

File tree

1 file changed

+8
-2
lines changed
  • staging/src/k8s.io/csi-translation-lib/plugins

1 file changed

+8
-2
lines changed

staging/src/k8s.io/csi-translation-lib/plugins/gce_pd.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,19 @@ func (g *gcePersistentDiskCSITranslator) TranslateInTreePVToCSI(pv *v1.Persisten
8787
}
8888

8989
gceSource := pv.Spec.PersistentVolumeSource.GCEPersistentDisk
90+
91+
partition := ""
92+
if gceSource.Partition != 0 {
93+
partition = strconv.Itoa(int(gceSource.Partition))
94+
}
95+
9096
csiSource := &v1.CSIPersistentVolumeSource{
9197
Driver: GCEPDDriverName,
9298
VolumeHandle: volID,
9399
ReadOnly: gceSource.ReadOnly,
94100
FSType: gceSource.FSType,
95101
VolumeAttributes: map[string]string{
96-
"partition": strconv.FormatInt(int64(gceSource.Partition), 10),
102+
"partition": partition,
97103
},
98104
}
99105

@@ -121,7 +127,7 @@ func (g *gcePersistentDiskCSITranslator) TranslateCSIPVToInTree(pv *v1.Persisten
121127
FSType: csiSource.FSType,
122128
ReadOnly: csiSource.ReadOnly,
123129
}
124-
if partition, ok := csiSource.VolumeAttributes["partition"]; ok {
130+
if partition, ok := csiSource.VolumeAttributes["partition"]; ok && partition != "" {
125131
partInt, err := strconv.Atoi(partition)
126132
if err != nil {
127133
return nil, fmt.Errorf("Failed to convert partition %v to integer: %v", partition, err)

0 commit comments

Comments
 (0)