mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #99169 from TeweiLuo/fix-repd-volhandle-translation
Use the correct volum handle format for GCE regional PD.
This commit is contained in:
commit
1a81b24e52
@ -231,7 +231,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)
|
||||
|
@ -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 {
|
||||
@ -294,3 +295,61 @@ 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: "v1 topology key zonal",
|
||||
topologyLabelKey: v1.LabelTopologyZone,
|
||||
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",
|
||||
},
|
||||
{
|
||||
desc: "v1 topology key regional",
|
||||
topologyLabelKey: v1.LabelTopologyZone,
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user