Skip to content

Commit 66d6ac4

Browse files
committed
Correct wrong check of resulting image sparsiness
The first issue is that we look at content size since 2168, which is not beneficial in the sparseness check as opposed to disk usage. The second issue is that the check we have in tests for sparsiness is not honest because of the "equal to" part. The virtual size has to be strictly greater than the content (as the content is displayed by tools that understand sparseness). Signed-off-by: Alex Kalenyuk <[email protected]>
1 parent aab2017 commit 66d6ac4

File tree

1 file changed

+2
-33
lines changed

1 file changed

+2
-33
lines changed

tests/framework/pvc.go

+2-33
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"strconv"
87
"strings"
98
"time"
109

@@ -284,22 +283,12 @@ func (f *Framework) VerifyBlankDisk(namespace *k8sv1.Namespace, pvc *k8sv1.Persi
284283
// VerifySparse checks a disk image being sparse after creation/resize.
285284
func (f *Framework) VerifySparse(namespace *k8sv1.Namespace, pvc *k8sv1.PersistentVolumeClaim, imagePath string) (bool, error) {
286285
var info image.ImgInfo
287-
var imageContentSize int64
288286
err := f.GetImageInfo(namespace, pvc, imagePath, &info)
289287
if err != nil {
290288
return false, err
291289
}
292-
// qemu-img info gives us ActualSize but that is size on disk
293-
// which isn't important to us in this comparison; we compare content size
294-
err = f.GetImageContentSize(namespace, pvc, imagePath, &imageContentSize)
295-
if err != nil {
296-
return false, err
297-
}
298-
if info.ActualSize-imageContentSize >= units.MiB {
299-
return false, fmt.Errorf("Diff between content size %d and size on disk %d is significant, something's not right", imageContentSize, info.ActualSize)
300-
}
301-
fmt.Fprintf(ginkgo.GinkgoWriter, "INFO: VerifySparse comparison: Virtual: %d vs Content: %d\n", info.VirtualSize, imageContentSize)
302-
return info.VirtualSize >= imageContentSize, nil
290+
// The content size of a sparse image is significantly lower than the image's virtual size
291+
return info.VirtualSize-info.ActualSize >= units.MiB, nil
303292
}
304293

305294
// VerifyFSOverhead checks whether virtual size is smaller than actual size. That means FS Overhead has been accounted for.
@@ -546,26 +535,6 @@ func (f *Framework) GetImageInfo(namespace *k8sv1.Namespace, pvc *k8sv1.Persiste
546535
return err
547536
}
548537

549-
// GetImageContentSize returns the content size (as opposed to size on disk) of an image
550-
func (f *Framework) GetImageContentSize(namespace *k8sv1.Namespace, pvc *k8sv1.PersistentVolumeClaim, imagePath string, imageSize *int64) error {
551-
cmd := fmt.Sprintf("du -s --apparent-size -B 1 %s | cut -f 1", imagePath)
552-
553-
_, err := f.verifyInPod(namespace, pvc, cmd, func(output, stderr string) (bool, error) {
554-
fmt.Fprintf(ginkgo.GinkgoWriter, "CMD (%s) output %s\n", cmd, output)
555-
556-
size, err := strconv.ParseInt(output, 10, 64)
557-
if err != nil {
558-
klog.Errorf("Invalid image content size:\n%s\n", output)
559-
return false, err
560-
}
561-
*imageSize = size
562-
563-
return true, nil
564-
})
565-
566-
return err
567-
}
568-
569538
func (f *Framework) startVerifierPod(namespace *k8sv1.Namespace, pvc *k8sv1.PersistentVolumeClaim) (*k8sv1.Pod, error) {
570539
var executorPod *k8sv1.Pod
571540
var err error

0 commit comments

Comments
 (0)