mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
fix: azuredisk parameter lowercase translation issue
This commit is contained in:
parent
cd02a3035f
commit
d957dcf5a0
@ -37,8 +37,8 @@ const (
|
||||
// Parameter names defined in azure disk CSI driver, refer to
|
||||
// https://github.com/kubernetes-sigs/azuredisk-csi-driver/blob/master/docs/driver-parameters.md
|
||||
azureDiskKind = "kind"
|
||||
azureDiskCachingMode = "cachingMode"
|
||||
azureDiskFSType = "fsType"
|
||||
azureDiskCachingMode = "cachingmode"
|
||||
azureDiskFSType = "fstype"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -203,13 +203,19 @@ func (t *azureDiskCSITranslator) TranslateCSIPVToInTree(pv *v1.PersistentVolume)
|
||||
}
|
||||
|
||||
if csiSource.VolumeAttributes != nil {
|
||||
if cachingMode, ok := csiSource.VolumeAttributes[azureDiskCachingMode]; ok {
|
||||
mode := v1.AzureDataDiskCachingMode(cachingMode)
|
||||
azureSource.CachingMode = &mode
|
||||
}
|
||||
|
||||
if fsType, ok := csiSource.VolumeAttributes[azureDiskFSType]; ok && fsType != "" {
|
||||
azureSource.FSType = &fsType
|
||||
for k, v := range csiSource.VolumeAttributes {
|
||||
switch strings.ToLower(k) {
|
||||
case azureDiskCachingMode:
|
||||
if v != "" {
|
||||
mode := v1.AzureDataDiskCachingMode(v)
|
||||
azureSource.CachingMode = &mode
|
||||
}
|
||||
case azureDiskFSType:
|
||||
if v != "" {
|
||||
fsType := v
|
||||
azureSource.FSType = &fsType
|
||||
}
|
||||
}
|
||||
}
|
||||
azureSource.Kind = &managed
|
||||
}
|
||||
|
@ -220,9 +220,9 @@ func TestTranslateAzureDiskInTreePVToCSI(t *testing.T) {
|
||||
FSType: "fstype",
|
||||
ReadOnly: true,
|
||||
VolumeAttributes: map[string]string{
|
||||
azureDiskCachingMode: "cachingmode",
|
||||
azureDiskFSType: fsType,
|
||||
azureDiskKind: "Managed",
|
||||
"cachingmode": "cachingmode",
|
||||
azureDiskFSType: fsType,
|
||||
azureDiskKind: "Managed",
|
||||
},
|
||||
VolumeHandle: diskURI,
|
||||
},
|
||||
@ -267,7 +267,9 @@ func TestTranslateAzureDiskInTreePVToCSI(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTranslateTranslateCSIPVToInTree(t *testing.T) {
|
||||
cachingMode := corev1.AzureDataDiskCachingMode("cachingmode")
|
||||
cachingModeNone := corev1.AzureDataDiskCachingNone
|
||||
cachingModeReadOnly := corev1.AzureDataDiskCachingReadOnly
|
||||
cachingModeReadWrite := corev1.AzureDataDiskCachingReadWrite
|
||||
fsType := "fstype"
|
||||
readOnly := true
|
||||
diskURI := "/subscriptions/12/resourceGroups/23/providers/Microsoft.Compute/disks/name"
|
||||
@ -275,13 +277,15 @@ func TestTranslateTranslateCSIPVToInTree(t *testing.T) {
|
||||
|
||||
translator := NewAzureDiskCSITranslator()
|
||||
cases := []struct {
|
||||
name string
|
||||
volume *corev1.PersistentVolume
|
||||
expVol *corev1.PersistentVolume
|
||||
expErr bool
|
||||
name string
|
||||
cachingMode corev1.AzureDataDiskCachingMode
|
||||
volume *corev1.PersistentVolume
|
||||
expVol *corev1.PersistentVolume
|
||||
expErr bool
|
||||
}{
|
||||
{
|
||||
name: "azure disk volume",
|
||||
name: "azure disk volume with ReadOnly cachingMode",
|
||||
cachingMode: corev1.AzureDataDiskCachingReadOnly,
|
||||
volume: &corev1.PersistentVolume{
|
||||
Spec: corev1.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: corev1.PersistentVolumeSource{
|
||||
@ -290,9 +294,9 @@ func TestTranslateTranslateCSIPVToInTree(t *testing.T) {
|
||||
FSType: "fstype",
|
||||
ReadOnly: true,
|
||||
VolumeAttributes: map[string]string{
|
||||
azureDiskCachingMode: "cachingmode",
|
||||
azureDiskFSType: fsType,
|
||||
azureDiskKind: "managed",
|
||||
"cachingmode": "ReadOnly",
|
||||
azureDiskFSType: fsType,
|
||||
azureDiskKind: "managed",
|
||||
},
|
||||
VolumeHandle: diskURI,
|
||||
},
|
||||
@ -303,7 +307,115 @@ func TestTranslateTranslateCSIPVToInTree(t *testing.T) {
|
||||
Spec: corev1.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: corev1.PersistentVolumeSource{
|
||||
AzureDisk: &corev1.AzureDiskVolumeSource{
|
||||
CachingMode: &cachingMode,
|
||||
CachingMode: &cachingModeReadOnly,
|
||||
DataDiskURI: diskURI,
|
||||
FSType: &fsType,
|
||||
ReadOnly: &readOnly,
|
||||
Kind: &managed,
|
||||
DiskName: "name",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expErr: false,
|
||||
},
|
||||
{
|
||||
name: "azure disk volume with ReadOnly cachingMode",
|
||||
cachingMode: corev1.AzureDataDiskCachingReadOnly,
|
||||
volume: &corev1.PersistentVolume{
|
||||
Spec: corev1.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: corev1.PersistentVolumeSource{
|
||||
CSI: &corev1.CSIPersistentVolumeSource{
|
||||
Driver: "disk.csi.azure.com",
|
||||
FSType: "fstype",
|
||||
ReadOnly: true,
|
||||
VolumeAttributes: map[string]string{
|
||||
"cachingmode": "ReadOnly",
|
||||
"fstype": fsType,
|
||||
azureDiskKind: "managed",
|
||||
},
|
||||
VolumeHandle: diskURI,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expVol: &corev1.PersistentVolume{
|
||||
Spec: corev1.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: corev1.PersistentVolumeSource{
|
||||
AzureDisk: &corev1.AzureDiskVolumeSource{
|
||||
CachingMode: &cachingModeReadOnly,
|
||||
DataDiskURI: diskURI,
|
||||
FSType: &fsType,
|
||||
ReadOnly: &readOnly,
|
||||
Kind: &managed,
|
||||
DiskName: "name",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expErr: false,
|
||||
},
|
||||
{
|
||||
name: "azure disk volume with None cachingMode",
|
||||
cachingMode: corev1.AzureDataDiskCachingReadOnly,
|
||||
volume: &corev1.PersistentVolume{
|
||||
Spec: corev1.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: corev1.PersistentVolumeSource{
|
||||
CSI: &corev1.CSIPersistentVolumeSource{
|
||||
Driver: "disk.csi.azure.com",
|
||||
FSType: "fstype",
|
||||
ReadOnly: true,
|
||||
VolumeAttributes: map[string]string{
|
||||
"cachingMode": "None",
|
||||
"fsType": fsType,
|
||||
azureDiskKind: "managed",
|
||||
},
|
||||
VolumeHandle: diskURI,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expVol: &corev1.PersistentVolume{
|
||||
Spec: corev1.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: corev1.PersistentVolumeSource{
|
||||
AzureDisk: &corev1.AzureDiskVolumeSource{
|
||||
CachingMode: &cachingModeNone,
|
||||
DataDiskURI: diskURI,
|
||||
FSType: &fsType,
|
||||
ReadOnly: &readOnly,
|
||||
Kind: &managed,
|
||||
DiskName: "name",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expErr: false,
|
||||
},
|
||||
{
|
||||
name: "azure disk volume with ReadWrite cachingMode",
|
||||
cachingMode: corev1.AzureDataDiskCachingReadOnly,
|
||||
volume: &corev1.PersistentVolume{
|
||||
Spec: corev1.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: corev1.PersistentVolumeSource{
|
||||
CSI: &corev1.CSIPersistentVolumeSource{
|
||||
Driver: "disk.csi.azure.com",
|
||||
FSType: "fstype",
|
||||
ReadOnly: true,
|
||||
VolumeAttributes: map[string]string{
|
||||
"cachingMode": "ReadWrite",
|
||||
"fsType": fsType,
|
||||
azureDiskKind: "managed",
|
||||
},
|
||||
VolumeHandle: diskURI,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expVol: &corev1.PersistentVolume{
|
||||
Spec: corev1.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: corev1.PersistentVolumeSource{
|
||||
AzureDisk: &corev1.AzureDiskVolumeSource{
|
||||
CachingMode: &cachingModeReadWrite,
|
||||
DataDiskURI: diskURI,
|
||||
FSType: &fsType,
|
||||
ReadOnly: &readOnly,
|
||||
|
Loading…
Reference in New Issue
Block a user