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