From 9f2922c15a8b31bf075e2fd7fd55311eb14f0959 Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Thu, 26 Oct 2017 06:51:03 +0000 Subject: [PATCH] fix azure pv crash due to readOnly nil --- pkg/volume/azure_dd/azure_mounter.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/volume/azure_dd/azure_mounter.go b/pkg/volume/azure_dd/azure_mounter.go index 74f3d39f083..f42a6a45c10 100644 --- a/pkg/volume/azure_dd/azure_mounter.go +++ b/pkg/volume/azure_dd/azure_mounter.go @@ -43,10 +43,14 @@ var _ volume.Unmounter = &azureDiskUnmounter{} var _ volume.Mounter = &azureDiskMounter{} func (m *azureDiskMounter) GetAttributes() volume.Attributes { - volumeSource, _ := getVolumeSource(m.spec) + readOnly := false + volumeSource, err := getVolumeSource(m.spec) + if err != nil && volumeSource.ReadOnly != nil { + readOnly = *volumeSource.ReadOnly + } return volume.Attributes{ - ReadOnly: *volumeSource.ReadOnly, - Managed: !*volumeSource.ReadOnly, + ReadOnly: readOnly, + Managed: !readOnly, SupportsSELinux: true, } } @@ -94,7 +98,7 @@ func (m *azureDiskMounter) SetUpAt(dir string, fsGroup *int64) error { options := []string{"bind"} - if *volumeSource.ReadOnly { + if volumeSource.ReadOnly != nil && *volumeSource.ReadOnly { options = append(options, "ro") } @@ -138,7 +142,7 @@ func (m *azureDiskMounter) SetUpAt(dir string, fsGroup *int64) error { return mountErr } - if !*volumeSource.ReadOnly { + if volumeSource.ReadOnly == nil || !*volumeSource.ReadOnly { volume.SetVolumeOwnership(m, fsGroup) }