Skip to content

Commit

Permalink
Merge pull request kubernetes#107518 from andyzhangx/automated-cherry…
Browse files Browse the repository at this point in the history
…-pick-of-#107429-upstream-release-1.23

Automated cherry pick of kubernetes#107429: fix: azuredisk parameter lowercase translation issue
  • Loading branch information
k8s-ci-robot committed Jan 14, 2022
2 parents ce3d579 + 50e8132 commit 14982cf
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 22 deletions.
24 changes: 15 additions & 9 deletions staging/src/k8s.io/csi-translation-lib/plugins/azure_disk.go
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}
Expand Down
138 changes: 125 additions & 13 deletions staging/src/k8s.io/csi-translation-lib/plugins/azure_disk_test.go
Expand Up @@ -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,
},
Expand Down Expand Up @@ -267,21 +267,25 @@ 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"
managed := v1.AzureManagedDisk

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{
Expand All @@ -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,
},
Expand All @@ -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,
Expand Down

0 comments on commit 14982cf

Please sign in to comment.