Skip to content

Commit

Permalink
Merge pull request kubernetes#100075 from ialidzhikov/automated-cherr…
Browse files Browse the repository at this point in the history
…y-pick-of-#99169-upstream-release-1.20

Automated cherry pick of kubernetes#99169: Use the correct volum handle format for GCE regional PD.
  • Loading branch information
k8s-ci-robot committed Apr 8, 2021
2 parents 6edb1ec + 9c6fb88 commit 54b62e1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion staging/src/k8s.io/csi-translation-lib/plugins/gce_pd.go
Expand Up @@ -226,7 +226,7 @@ func (g *gcePersistentDiskCSITranslator) TranslateInTreePVToCSI(pv *v1.Persisten
if err != nil {
return nil, fmt.Errorf("failed to get region from zones: %v", err)
}
volID = fmt.Sprintf(volIDZonalFmt, UnspecifiedValue, region, pv.Spec.GCEPersistentDisk.PDName)
volID = fmt.Sprintf(volIDRegionalFmt, UnspecifiedValue, region, pv.Spec.GCEPersistentDisk.PDName)
} else {
// Unspecified
volID = fmt.Sprintf(volIDZonalFmt, UnspecifiedValue, UnspecifiedValue, pv.Spec.GCEPersistentDisk.PDName)
Expand Down
47 changes: 47 additions & 0 deletions staging/src/k8s.io/csi-translation-lib/plugins/gce_pd_test.go
Expand Up @@ -23,6 +23,7 @@ import (

v1 "k8s.io/api/core/v1"
storage "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func NewStorageClass(params map[string]string, allowedTopologies []v1.TopologySelectorTerm) *storage.StorageClass {
Expand Down Expand Up @@ -294,3 +295,49 @@ func TestInlineReadOnly(t *testing.T) {
t.Errorf("got am %v, expected access mode of ReadOnlyMany", ams[0])
}
}

func TestTranslateInTreePVToCSIVolIDFmt(t *testing.T) {
g := NewGCEPersistentDiskCSITranslator()
pdName := "pd-name"
tests := []struct {
desc string
topologyLabelKey string
topologyLabelValue string
wantVolID string
}{
{
desc: "beta topology key zonal",
topologyLabelKey: v1.LabelFailureDomainBetaZone,
topologyLabelValue: "us-east1-a",
wantVolID: "projects/UNSPECIFIED/zones/us-east1-a/disks/pd-name",
},
{
desc: "beta topology key regional",
topologyLabelKey: v1.LabelFailureDomainBetaZone,
topologyLabelValue: "us-central1-a__us-central1-c",
wantVolID: "projects/UNSPECIFIED/regions/us-central1/disks/pd-name",
},
}
for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
translatedPV, err := g.TranslateInTreePVToCSI(&v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{tc.topologyLabelKey: tc.topologyLabelValue},
},
Spec: v1.PersistentVolumeSpec{
PersistentVolumeSource: v1.PersistentVolumeSource{
GCEPersistentDisk: &v1.GCEPersistentDiskVolumeSource{
PDName: pdName,
},
},
},
})
if err != nil {
t.Errorf("got error translating in-tree PV to CSI: %v", err)
}
if got := translatedPV.Spec.PersistentVolumeSource.CSI.VolumeHandle; got != tc.wantVolID {
t.Errorf("got translated volume handle: %q, want %q", got, tc.wantVolID)
}
})
}
}

0 comments on commit 54b62e1

Please sign in to comment.