Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add kind parameter in azure disk CSI migration #81633

Merged
merged 1 commit into from Aug 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 19 additions & 4 deletions staging/src/k8s.io/csi-translation-lib/plugins/azure_disk.go
Expand Up @@ -34,6 +34,7 @@ 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"
)
Expand Down Expand Up @@ -79,7 +80,7 @@ func (t *azureDiskCSITranslator) TranslateInTreeInlineVolumeToCSI(volume *v1.Vol
VolumeHandle: azureSource.DataDiskURI,
ReadOnly: *azureSource.ReadOnly,
FSType: *azureSource.FSType,
VolumeAttributes: map[string]string{},
VolumeAttributes: map[string]string{azureDiskKind: "Managed"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you write a quick unit test?

},
},
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce},
Expand All @@ -92,6 +93,9 @@ func (t *azureDiskCSITranslator) TranslateInTreeInlineVolumeToCSI(volume *v1.Vol
if *azureSource.FSType != "" {
pv.Spec.PersistentVolumeSource.CSI.VolumeAttributes[azureDiskFSType] = *azureSource.FSType
}
if azureSource.Kind != nil {
pv.Spec.PersistentVolumeSource.CSI.VolumeAttributes[azureDiskKind] = string(*azureSource.Kind)
}

return pv, nil
}
Expand All @@ -111,17 +115,21 @@ func (t *azureDiskCSITranslator) TranslateInTreePVToCSI(pv *v1.PersistentVolume)
VolumeHandle: azureSource.DataDiskURI,
ReadOnly: *azureSource.ReadOnly,
FSType: *azureSource.FSType,
VolumeAttributes: map[string]string{},
VolumeAttributes: map[string]string{azureDiskKind: "Managed"},
}

if *azureSource.CachingMode != "" {
if azureSource.CachingMode != nil {
csiSource.VolumeAttributes[azureDiskCachingMode] = string(*azureSource.CachingMode)
}

if *azureSource.FSType != "" {
if azureSource.FSType != nil {
feiskyer marked this conversation as resolved.
Show resolved Hide resolved
csiSource.VolumeAttributes[azureDiskFSType] = *azureSource.FSType
}

if azureSource.Kind != nil {
csiSource.VolumeAttributes[azureDiskKind] = string(*azureSource.Kind)
}

pv.Spec.PersistentVolumeSource.AzureDisk = nil
pv.Spec.PersistentVolumeSource.CSI = csiSource
pv.Spec.AccessModes = backwardCompatibleAccessModes(pv.Spec.AccessModes)
Expand All @@ -144,11 +152,13 @@ func (t *azureDiskCSITranslator) TranslateCSIPVToInTree(pv *v1.PersistentVolume)
}

// refer to https://github.com/kubernetes-sigs/azuredisk-csi-driver/blob/master/docs/driver-parameters.md
managed := v1.AzureManagedDisk
azureSource := &v1.AzureDiskVolumeSource{
DiskName: diskName,
DataDiskURI: diskURI,
FSType: &csiSource.FSType,
ReadOnly: &csiSource.ReadOnly,
Kind: &managed,
}

if csiSource.VolumeAttributes != nil {
Expand All @@ -160,6 +170,11 @@ func (t *azureDiskCSITranslator) TranslateCSIPVToInTree(pv *v1.PersistentVolume)
if fsType, ok := csiSource.VolumeAttributes[azureDiskFSType]; ok && fsType != "" {
azureSource.FSType = &fsType
}

if kind, ok := csiSource.VolumeAttributes[azureDiskKind]; ok && kind != "" {
diskKind := v1.AzureDataDiskKind(kind)
azureSource.Kind = &diskKind
}
}

pv.Spec.CSI = nil
Expand Down