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: missing static PV data in VolumeAttachments #1062

Merged
merged 1 commit into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pkg/azuredisk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,10 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
return nil, status.Error(codes.NotFound, fmt.Sprintf("failed to get azure instance id for node %q (%v)", nodeName, err))
}

volumeContext := req.VolumeContext
volumeContext := req.GetVolumeContext()
if volumeContext == nil {
volumeContext = map[string]string{}
}

if err == nil {
if vmState != nil && strings.ToLower(*vmState) == "failed" {
Expand All @@ -459,13 +462,13 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
klog.V(2).Infof("Attach operation is successful. volume %q is already attached to node %q at lun %d.", diskURI, nodeName, lun)
} else {
var cachingMode compute.CachingTypes
if cachingMode, err = azureutils.GetCachingMode(req.GetVolumeContext()); err != nil {
if cachingMode, err = azureutils.GetCachingMode(volumeContext); err != nil {
return nil, err
}
klog.V(2).Infof("Trying to attach volume %q to node %q", diskURI, nodeName)

asyncAttach := true
if volumeContext != nil && volumeContext[consts.EnableAsyncAttachField] == consts.FalseValue {
if volumeContext[consts.EnableAsyncAttachField] == consts.FalseValue {
asyncAttach = false
}
lun, err = d.cloud.AttachDisk(ctx, asyncAttach, diskName, diskURI, nodeName, cachingMode, disk)
Expand Down Expand Up @@ -494,7 +497,7 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
}

publishContext := map[string]string{consts.LUN: strconv.Itoa(int(lun))}
if disk != nil && volumeContext != nil {
if disk != nil {
if _, ok := volumeContext[consts.RequestedSizeGib]; !ok {
klog.V(2).Infof("found static PV(%s), insert disk properties to volumeattachments", diskURI)
azureutils.InsertDiskProperties(disk, publishContext)
Expand Down
10 changes: 7 additions & 3 deletions pkg/azuredisk/controllerserver_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,11 @@ func (d *DriverV2) ControllerPublishVolume(ctx context.Context, req *csi.Control
return nil, status.Error(codes.NotFound, fmt.Sprintf("failed to get azure instance id for node %q (%v)", nodeName, err))
}

volumeContext := req.GetVolumeContext()
if volumeContext == nil {
volumeContext = map[string]string{}
}

if err == nil {
if vmState != nil && strings.ToLower(*vmState) == "failed" {
klog.Warningf("VM(%q) is in failed state, update VM first", nodeName)
Expand All @@ -422,7 +427,7 @@ func (d *DriverV2) ControllerPublishVolume(ctx context.Context, req *csi.Control
klog.V(2).Infof("Attach operation is successful. volume %q is already attached to node %q at lun %d.", diskURI, nodeName, lun)
} else {
var cachingMode compute.CachingTypes
if cachingMode, err = azureutils.GetCachingMode(req.GetVolumeContext()); err != nil {
if cachingMode, err = azureutils.GetCachingMode(volumeContext); err != nil {
return nil, err
}
klog.V(2).Infof("Trying to attach volume %q to node %q", diskURI, nodeName)
Expand All @@ -448,8 +453,7 @@ func (d *DriverV2) ControllerPublishVolume(ctx context.Context, req *csi.Control
}

publishContext := map[string]string{consts.LUN: strconv.Itoa(int(lun))}
volumeContext := req.VolumeContext
if disk != nil && volumeContext != nil {
if disk != nil {
if _, ok := volumeContext[consts.RequestedSizeGib]; !ok {
klog.V(2).Infof("found static PV(%s), insert disk properties to volumeattachments", diskURI)
azureutils.InsertDiskProperties(disk, publishContext)
Expand Down