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

CON-3010 Changes for resize the filesystem for creating clone from sn… #424

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ RUN ln -s /chroot/chroot-host-wrapper.sh /chroot/blkid \
&& ln -s /chroot/chroot-host-wrapper.sh /chroot/mkfs.ext4 \
&& ln -s /chroot/chroot-host-wrapper.sh /chroot/mkfs.xfs \
&& ln -s /chroot/chroot-host-wrapper.sh /chroot/mkfs.btrfs \
&& ln -s /chroot/chroot-host-wrapper.sh /chroot/dumpe2fs \
&& ln -s /chroot/chroot-host-wrapper.sh /chroot/xfs_io \
&& ln -s /chroot/chroot-host-wrapper.sh /chroot/xfs_growfs \
&& ln -s /chroot/chroot-host-wrapper.sh /chroot/xfs_repair \
&& ln -s /chroot/chroot-host-wrapper.sh /chroot/tune2fs \
Expand Down
6 changes: 5 additions & 1 deletion pkg/driver/constants.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Hewlett Packard Enterprise Development LP
// Copyright 2019,2024 Hewlett Packard Enterprise Development LP
Copy link
Collaborator

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.


package driver

Expand Down Expand Up @@ -100,6 +100,10 @@ const (
hostEncryptionSecretNamespaceKey = "hostEncryptionSecretNamespace"
hostEncryptionPassphraseKey = "hostEncryptionPassphrase"

//PVC attributes propogated to the CSI
pvcNameAttribute = "csi.storage.k8s.io/pvc/name"
pvcNamespaceAttribute = "csi.storage.k8s.io/pvc/namespace"

// POD attributes propogated to the CSI
csiEphemeralPodName = "csi.storage.k8s.io/pod.name"
csiEphemeralPodNamespace = "csi.storage.k8s.io/pod.namespace"
Expand Down
11 changes: 6 additions & 5 deletions pkg/driver/controller_server.go
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
Expand Down Expand Up @@ -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,
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Expand Down
52 changes: 51 additions & 1 deletion pkg/driver/node_server.go
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
Expand Down Expand Up @@ -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"
)

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
}

Expand Down Expand Up @@ -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)

Expand Down
17 changes: 16 additions & 1 deletion pkg/flavor/kubernetes/flavor.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Hewlett Packard Enterprise Development LP
// Copyright 2019, 2024 Hewlett Packard Enterprise Development LP

package kubernetes

Expand Down Expand Up @@ -686,6 +686,21 @@ func (flavor *Flavor) getPodByName(name string, namespace string) (*v1.Pod, erro
return pod, nil
}

// GetPVCByName to get the PVC details for given PVC name
func (flavor *Flavor) GetPVCByName(name string, namespace string) (*v1.PersistentVolumeClaim , error) {
log.Tracef(">>>>> GetPVCByName, name: %s, namespace: %s", name, namespace)
defer log.Trace("<<<<< GetPVCByName")

pvc, err := flavor.kubeClient.CoreV1().PersistentVolumeClaims(namespace).Get(context.Background(), name, meta_v1.GetOptions{})
if err != nil {
log.Errorf("Error retrieving the pvc %s/%s, err: %v", namespace, name, err.Error())
return nil, err
}

return pvc, nil
}


// makeVolumeHandle returns csi-<sha256(podUID,volSourceSpecName)>
// Original source location: kubernetes/pkg/volume/csi/csi_mounter.go
// TODO: Must be in-sync with k8s code
Expand Down
4 changes: 3 additions & 1 deletion pkg/flavor/types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Hewlett Packard Enterprise Development LP
// Copyright 2019, 2024 Hewlett Packard Enterprise Development LP

package flavor

Expand All @@ -7,6 +7,7 @@ import (
"github.com/hpe-storage/common-host-libs/model"
storage_v1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/version"
v1 "k8s.io/api/core/v1"
)

const (
Expand Down Expand Up @@ -42,4 +43,5 @@ type Flavor interface {
ListVolumeAttachments() (*storage_v1.VolumeAttachmentList, error)
GetChapCredentials(volumeContext map[string]string) (*model.ChapInfo, error)
CheckConnection() bool
GetPVCByName(name string, namespace string) (*v1.PersistentVolumeClaim , error)
}
7 changes: 6 additions & 1 deletion pkg/flavor/vanilla/flavor.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Hewlett Packard Enterprise Development LP
// Copyright 2019, 2024 Hewlett Packard Enterprise Development LP

package vanilla

Expand All @@ -11,6 +11,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
storage_v1 "k8s.io/api/storage/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/version"
)

Expand Down Expand Up @@ -120,3 +121,7 @@ func (flavor *Flavor) ListVolumeAttachments() (*storage_v1.VolumeAttachmentList,
func (flavor *Flavor) CheckConnection() bool {
return false
}

func (flavor *Flavor) GetPVCByName(name string, namespace string) (*v1.PersistentVolumeClaim , error) {
return nil, nil
}