mirror of https://github.com/k3s-io/k3s
Merge pull request #54607 from andyzhangx/azure-readonly-fix
Automatic merge from submit-queue (batch tested with PRs 54593, 54607, 54539, 54105). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. fix azure pv crash due to volumeSource.ReadOnly value nil **What this PR does / why we need it**: kubelet in agent would crash due to volumeSource.ReadOnly is nil in some condition **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #54149 **Special notes for your reviewer**: #54149 is the issue: volumeSource.ReadOnly is nil, make kubelet in azure agent node crash. "volumeSource.ReadOnly is nil" could be regarded as `false` value @rootfs **Release note**: ``` fix azure pv crash due to volumeSource.ReadOnly value nil ``` /sig azurepull/6/head
commit
189dfe0577
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue