-
Notifications
You must be signed in to change notification settings - Fork 60
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
CON-3010 Changes for resize the filesystem for creating clone from sn… #424
base: master
Are you sure you want to change the base?
Changes from all commits
0fdbc31
e917f35
4038d09
82a6e97
d86c975
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2019 Hewlett Packard Enterprise Development LP | ||
// Copyright 2019,2025 Hewlett Packard Enterprise Development LP | ||
// Copyright 2017 The Kubernetes Authors. | ||
|
||
package driver | ||
|
@@ -550,11 +550,12 @@ func (driver *Driver) createVolume( | |
} | ||
log.Tracef("Found parent volume: %+v", existingParentVolume) | ||
|
||
// The requested size is must be at least equal to the snapshot's parent volume size | ||
if size != existingParentVolume.Size { | ||
// CON-3010 If requested size for clone volume is less than parent volume size | ||
// then report error | ||
if size < existingParentVolume.Size { | ||
return nil, | ||
status.Error(codes.InvalidArgument, | ||
fmt.Sprintf("Requested clone size %d is not equal to the parent volume size %d", size, existingParentVolume.Size)) | ||
status.Error(codes.Internal, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldnt it be better to leave the error code as InvalidArgument ? It is not an internal error, since the requested size is wrong, better to return InvalidArgument. |
||
fmt.Sprintf("Requested clone size %d is less than the parent volume size %d", size, existingParentVolume.Size)) | ||
} | ||
|
||
// Create a clone from another volume | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2019 Hewlett Packard Enterprise Development LP | ||
// Copyright 2019,2025 Hewlett Packard Enterprise Development LP | ||
// Copyright 2017 The Kubernetes Authors. | ||
|
||
package driver | ||
|
@@ -26,6 +26,9 @@ import ( | |
"github.com/hpe-storage/common-host-libs/model" | ||
"github.com/hpe-storage/common-host-libs/stringformat" | ||
"github.com/hpe-storage/common-host-libs/util" | ||
mountutil "k8s.io/mount-utils" | ||
"k8s.io/utils/exec" | ||
|
||
"k8s.io/kubernetes/pkg/volume" | ||
) | ||
|
||
|
@@ -409,6 +412,8 @@ func (driver *Driver) stageVolume( | |
volumeID, stagingMountPoint, volAccessType.String(), volCap, log.MapScrubber(publishContext), volumeContext) | ||
defer log.Trace("<<<<< stageVolume") | ||
|
||
var IsVolumeClone bool | ||
|
||
// serialize stage requests | ||
stageLock.Lock() | ||
defer stageLock.Unlock() | ||
|
@@ -498,7 +503,51 @@ func (driver *Driver) stageVolume( | |
|
||
// Store mount info in the staging device | ||
stagingDevice.MountInfo = mountInfo | ||
|
||
// CON-3010 | ||
// Get the PVC details to identify the datasource of PVC | ||
log.Infof("PVC Name %s and PVC Namespace %s", volumeContext[pvcNameAttribute], volumeContext[pvcNamespaceAttribute]) | ||
|
||
if volumeContext[pvcNameAttribute] != "" && volumeContext[pvcNamespaceAttribute] != "" { | ||
pvc, err := driver.flavor.GetPVCByName( volumeContext[pvcNameAttribute], volumeContext[pvcNamespaceAttribute] ) | ||
if err != nil{ | ||
return nil, status.Error(codes.Internal, fmt.Sprintf("Error getting pvc data source for volume %v, %v", volumeID, err)) | ||
} | ||
if pvc.Spec.DataSource != nil { | ||
|
||
// If the DataSource is a VolumeSnapshot | ||
if pvc.Spec.DataSource.Kind == "VolumeSnapshot" { | ||
log.Infof(" Source Kind: VolumeSnapshot\n VolumeSnapshot Name: %s\n", pvc.Spec.DataSource.Name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: is the newlines in between intentional? Might not be needed, since each log will be in a newline by default. |
||
//set to true as volume is created from volume snapshot | ||
IsVolumeClone = true | ||
} | ||
} | ||
} | ||
|
||
// Check whether volume is created from snapshot then only we need resize | ||
if IsVolumeClone { | ||
// Initialize resizeFs | ||
r := mountutil.NewResizeFs(exec.New()) | ||
|
||
log.Infof("Verify whether resize required for device path %v ", device.AltFullPathName) | ||
|
||
// check whether we need resize for file system | ||
needResize, err := r.NeedResize(device.AltFullPathName, stagingMountPoint) | ||
if err != nil { | ||
return nil, status.Errorf(codes.Internal, "Could not determine if volume %q need to be resized, error: %v", volumeID, err) | ||
} | ||
log.Infof("Need resize for filesystem: %v", needResize) | ||
|
||
if needResize { | ||
rohit-balakrishna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
log.Infof("Resize of target path %s is required ", device.AltFullPathName) | ||
if _, err := r.Resize(device.AltFullPathName, stagingMountPoint); err != nil { | ||
return nil, status.Errorf(codes.Internal, "Could not resize volume %q, error : %v", volumeID, err) | ||
} | ||
log.Infof("Resize of target path %s is successful", device.AltFullPathName) | ||
} | ||
} | ||
// CON-3010 | ||
|
||
return stagingDevice, nil | ||
} | ||
|
||
|
@@ -809,6 +858,7 @@ func (driver *Driver) NodePublishVolume(ctx context.Context, request *csi.NodePu | |
} | ||
} | ||
|
||
|
||
log.Infof("NodePublishVolume requested volume %s with access type %s, targetPath %s, capability %v, publishContext %v and volumeContext %v", | ||
request.VolumeId, volAccessType, request.TargetPath, request.VolumeCapability, request.PublishContext, request.VolumeContext) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:2025, please check other files, some have 2024.