Code change:
resizeError := fmt.Errorf("resize of device %s failed: %v. btrfs output: %s", deviceMountPath, err, string(output)) return false, resizeError } <ins> func (resizefs *ResizeFs) NeedResize(devicePath string, deviceMountPath string) (bool, error) { deviceSize, err := resizefs.getDeviceSize(devicePath) if err != nil { return false, err } var fsSize, blockSize uint64 format, err := getDiskFormat(resizefs.exec, devicePath) if err != nil { formatErr := fmt.Errorf("ResizeFS.Resize - error checking format for device %s: %v", devicePath, err) return false, formatErr } // If disk has no format, there is no need to resize the disk because mkfs.* // by default will use whole disk anyways. if format == "" { return false, nil } klog.V(3).Infof("ResizeFs.needResize - checking mounted volume %s", devicePath) switch format { case "ext3", "ext4": blockSize, fsSize, err = resizefs.getExtSize(devicePath) klog.V(5).Infof("Ext size: filesystem size=%d, block size=%d", fsSize, blockSize) case "xfs": blockSize, fsSize, err = resizefs.getXFSSize(deviceMountPath) klog.V(5).Infof("Xfs size: filesystem size=%d, block size=%d, err=%v", fsSize, blockSize, err) default: klog.Errorf("Not able to parse given filesystem info. fsType: %s, will not resize", format) return false, fmt.Errorf("Could not parse fs info on given filesystem format: %s. Supported fs types are: xfs, ext3, ext4", format) } if err != nil { return false, err } // Tolerate one block difference, just in case of rounding errors somewhere. klog.V(5).Infof("Volume %s: device size=%d, filesystem size=%d, block size=%d", devicePath, deviceSize, fsSize, blockSize) if deviceSize <= fsSize+blockSize { return false, nil } return true, nil } func (resizefs *ResizeFs) getDeviceSize(devicePath string) (uint64, error) { output, err := resizefs.exec.Command("blockdev", "--getsize64", devicePath).CombinedOutput() outStr := strings.TrimSpace(string(output)) if err != nil { return 0, fmt.Errorf("failed to read size of device %s: %s: %s", devicePath, err, outStr) } size, err := strconv.ParseUint(outStr, 10, 64) if err != nil { return 0, fmt.Errorf("failed to parse size of device %s %s: %s", devicePath, outStr, err) } return size, nil } func (resizefs *ResizeFs) getExtSize(devicePath string) (uint64, uint64, error) { output, err := resizefs.exec.Command("dumpe2fs", "-h", devicePath).CombinedOutput() if err != nil { return 0, 0, fmt.Errorf("failed to read size of filesystem on %s: %s: %s", devicePath, err, string(output)) } blockSize, blockCount, _ := resizefs.parseFsInfoOutput(string(output), ":", "block size", "block count") if blockSize == 0 { return 0, 0, fmt.Errorf("could not find block size of device %s", devicePath) } if blockCount == 0 { return 0, 0, fmt.Errorf("could not find block count of device %s", devicePath) } return blockSize, blockSize * blockCount, nil } func (resizefs *ResizeFs) getXFSSize(devicePath string) (uint64, uint64, error) { output, err := resizefs.exec.Command("xfs_io", "-c", "statfs", devicePath).CombinedOutput() if err != nil { return 0, 0, fmt.Errorf("failed to read size of filesystem on %s: %s: %s", devicePath, err, string(output)) } blockSize, blockCount, _ := resizefs.parseFsInfoOutput(string(output), "=", "geom.bsize", "geom.datablocks") if blockSize == 0 { return 0, 0, fmt.Errorf("could not find block size of device %s", devicePath) } if blockCount == 0 { return 0, 0, fmt.Errorf("could not find block count of device %s", devicePath) } return blockSize, blockSize * blockCount, nil } func (resizefs *ResizeFs) parseFsInfoOutput(cmdOutput string, spliter string, blockSizeKey string, blockCountKey string) (uint64, uint64, error) { lines := strings.Split(cmdOutput, "n") var blockSize, blockCount uint64 var err error for _, line := range lines { tokens := strings.Split(line, spliter) if len(tokens) != 2 { continue } key, value := strings.ToLower(strings.TrimSpace(tokens[0])), strings.ToLower(strings.TrimSpace(tokens[1])) if key == blockSizeKey { blockSize, err = strconv.ParseUint(value, 10, 64) if err != nil { return 0, 0, fmt.Errorf("failed to parse block size %s: %s", value, err) } } if key == blockCountKey { blockCount, err = strconv.ParseUint(value, 10, 64) if err != nil { return 0, 0, fmt.Errorf("failed to parse block count %s: %s", value, err) } } } return blockSize, blockCount, err } </ins>

Related discussion:
text: Kubernetes should resize filesystem on a volume when it's created as a clone of a smaller volume / smaller snapshot is restored into it. Example: takes a snapshot of 1 GiB volume with ext3 filesystem on it. restores the snapshot into 2 GiB volume. 2.1 CSI driver restores the snapshot into a bigger volume, but ext3 filesystem still uses only 1 GiB of space. driver should make sure that the filesystem on the volume has been resized before the volume is mounted into a pod. There are few steps needed: [x] Clarify behavior of CSI call, [ ] Update CSI drivers to the new behavior. [x] Move filesystem resize code from kubernetes/kuberenetes to kubernetes/mount-utils, so all CSI drivers can re-use the same code [x] Enhance the code above to compare the volume size from block device perspective and from filesystem perspective. See for proof of concept. [ ] File issues in all community CSI drivers that we care about & fix them. [ ] Update csi-tests to (optionally?) check for volume size when cloning / restoring snapshot to a bigger size.
/assign /sig storage /priority important-soon
True, considering the CSI spec allows restore to a bigger size volume, we should have the support from CO.
This is hard, Kubernets PV controller overwrites on binding. Therefore the external-provisioner cannot create PVC as "marked for resize on node", i.e. with = = the real size of the new volume) and with = size of the original volume. We either need to change the binding mechanism not to overwrite or add a flag (annotation?) that marks the volume for resize on node, even when .
Talked to The external-provisioner could mark for resize on node: Set to the original volume size. Add condition to the PVC. As result, the extenal-provisioner needs to modify , which needs new RBAC and is a breaking change. The PV controller could respect , if set. We discussed and rejected adding a new flag / annotation to PV by the external-provisioner for kubelet to call NodeExpandVolume on the first mount. Such a flag would need to be cleared by kubelet and kubelet can't modify PVs.
From latest discussion last week, I believe the conclusion was to have external-provisioner set to the smaller size.