mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
Merge pull request #96821 from wongma7/translateebsinline
Use volumeHandle as PV name when translating EBS inline volume
This commit is contained in:
commit
9720013d92
@ -98,7 +98,7 @@ func (t *awsElasticBlockStoreCSITranslator) TranslateInTreeInlineVolumeToCSI(vol
|
|||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
// Must be unique per disk as it is used as the unique part of the
|
// Must be unique per disk as it is used as the unique part of the
|
||||||
// staging path
|
// staging path
|
||||||
Name: fmt.Sprintf("%s-%s", AWSEBSDriverName, ebsSource.VolumeID),
|
Name: fmt.Sprintf("%s-%s", AWSEBSDriverName, volumeHandle),
|
||||||
},
|
},
|
||||||
Spec: v1.PersistentVolumeSpec{
|
Spec: v1.PersistentVolumeSpec{
|
||||||
PersistentVolumeSource: v1.PersistentVolumeSource{
|
PersistentVolumeSource: v1.PersistentVolumeSource{
|
||||||
|
@ -17,12 +17,20 @@ limitations under the License.
|
|||||||
package plugins
|
package plugins
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
v1 "k8s.io/api/core/v1"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
storage "k8s.io/api/storage/v1"
|
storage "k8s.io/api/storage/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
normalVolumeID = "vol-02399794d890f9375"
|
||||||
|
awsVolumeID = "aws:///vol-02399794d890f9375"
|
||||||
|
awsZoneVolumeID = "aws://us-west-2a/vol-02399794d890f9375"
|
||||||
|
invalidVolumeID = "aws://us-west-2a/02399794d890f9375"
|
||||||
|
)
|
||||||
|
|
||||||
func TestKubernetesVolumeIDToEBSVolumeID(t *testing.T) {
|
func TestKubernetesVolumeIDToEBSVolumeID(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
@ -32,22 +40,22 @@ func TestKubernetesVolumeIDToEBSVolumeID(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Normal ID format",
|
name: "Normal ID format",
|
||||||
kubernetesID: "vol-02399794d890f9375",
|
kubernetesID: normalVolumeID,
|
||||||
ebsVolumeID: "vol-02399794d890f9375",
|
ebsVolumeID: normalVolumeID,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "aws:///{volumeId} format",
|
name: "aws:///{volumeId} format",
|
||||||
kubernetesID: "aws:///vol-02399794d890f9375",
|
kubernetesID: awsVolumeID,
|
||||||
ebsVolumeID: "vol-02399794d890f9375",
|
ebsVolumeID: normalVolumeID,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "aws://{zone}/{volumeId} format",
|
name: "aws://{zone}/{volumeId} format",
|
||||||
kubernetesID: "aws://us-west-2a/vol-02399794d890f9375",
|
kubernetesID: awsZoneVolumeID,
|
||||||
ebsVolumeID: "vol-02399794d890f9375",
|
ebsVolumeID: normalVolumeID,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "fails on invalid volume ID",
|
name: "fails on invalid volume ID",
|
||||||
kubernetesID: "aws://us-west-2a/02399794d890f9375",
|
kubernetesID: invalidVolumeID,
|
||||||
expErr: true,
|
expErr: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -112,3 +120,81 @@ func TestTranslateEBSInTreeStorageClassToCSI(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTranslateInTreeInlineVolumeToCSI(t *testing.T) {
|
||||||
|
translator := NewAWSElasticBlockStoreCSITranslator()
|
||||||
|
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
volumeSource v1.VolumeSource
|
||||||
|
expPVName string
|
||||||
|
expErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Normal ID format",
|
||||||
|
volumeSource: v1.VolumeSource{
|
||||||
|
AWSElasticBlockStore: &v1.AWSElasticBlockStoreVolumeSource{
|
||||||
|
VolumeID: normalVolumeID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expPVName: "ebs.csi.aws.com-" + normalVolumeID,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "aws:///{volumeId} format",
|
||||||
|
volumeSource: v1.VolumeSource{
|
||||||
|
AWSElasticBlockStore: &v1.AWSElasticBlockStoreVolumeSource{
|
||||||
|
VolumeID: awsVolumeID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expPVName: "ebs.csi.aws.com-" + normalVolumeID,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "aws://{zone}/{volumeId} format",
|
||||||
|
volumeSource: v1.VolumeSource{
|
||||||
|
AWSElasticBlockStore: &v1.AWSElasticBlockStoreVolumeSource{
|
||||||
|
VolumeID: awsZoneVolumeID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expPVName: "ebs.csi.aws.com-" + normalVolumeID,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "fails on invalid volume ID",
|
||||||
|
volumeSource: v1.VolumeSource{
|
||||||
|
AWSElasticBlockStore: &v1.AWSElasticBlockStoreVolumeSource{
|
||||||
|
VolumeID: invalidVolumeID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "fails on empty volume source",
|
||||||
|
volumeSource: v1.VolumeSource{},
|
||||||
|
expErr: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
t.Logf("Testing %v", tc.name)
|
||||||
|
got, err := translator.TranslateInTreeInlineVolumeToCSI(&v1.Volume{Name: "volume", VolumeSource: tc.volumeSource})
|
||||||
|
if err != nil && !tc.expErr {
|
||||||
|
t.Fatalf("Did not expect error but got: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err == nil && tc.expErr {
|
||||||
|
t.Fatalf("Expected error, but did not get one.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
if !reflect.DeepEqual(got.Name, tc.expPVName) {
|
||||||
|
t.Errorf("Got PV name: %v, expected :%v", got.Name, tc.expPVName)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(got.Spec.CSI.VolumeHandle, normalVolumeID) {
|
||||||
|
t.Errorf("Got PV volumeHandle: %v, expected :%v", got.Spec.CSI.VolumeHandle, normalVolumeID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user