Skip to content

Commit 0827b34

Browse files
committed
Use scratch space for non-archive uploads
Basically a follow up to 3219 for upload sources, which suffer from the same issue of losing sparseness. Signed-off-by: Alex Kalenyuk <[email protected]>
1 parent 0a9de7d commit 0827b34

File tree

4 files changed

+13
-20
lines changed

4 files changed

+13
-20
lines changed

cmd/cdi-cloner/clone-source.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"crypto/x509"
77
"errors"
88
"flag"
9+
"fmt"
910
"io"
1011
"net/http"
1112
"os"
@@ -55,7 +56,7 @@ func (er *execReader) Close() error {
5556
}
5657

5758
func init() {
58-
flag.StringVar(&contentType, "content-type", "", "filesystem-clone|blockdevice-clone")
59+
flag.StringVar(&contentType, "content-type", "", fmt.Sprintf("%s|%s", common.FilesystemCloneContentType, common.BlockdeviceClone))
5960
flag.StringVar(&mountPoint, "mount", "", "pvc mount point")
6061
flag.Uint64Var(&uploadBytes, "upload-bytes", 0, "approx number of bytes in input")
6162
klog.InitFlags(nil)
@@ -133,7 +134,7 @@ func pipeToSnappy(reader io.ReadCloser) io.ReadCloser {
133134

134135
func validateContentType() {
135136
switch contentType {
136-
case "filesystem-clone", "blockdevice-clone":
137+
case common.FilesystemCloneContentType, common.BlockdeviceClone:
137138
default:
138139
klog.Fatalf("Invalid content-type %q", contentType)
139140
}
@@ -198,13 +199,13 @@ func newTarReader(preallocation bool) (io.ReadCloser, error) {
198199

199200
func getInputStream(preallocation bool) io.ReadCloser {
200201
switch contentType {
201-
case "filesystem-clone":
202+
case common.FilesystemCloneContentType:
202203
rc, err := newTarReader(preallocation)
203204
if err != nil {
204205
klog.Fatalf("Error creating tar reader for %q: %+v", mountPoint, err)
205206
}
206207
return rc
207-
case "blockdevice-clone":
208+
case common.BlockdeviceClone:
208209
rc, err := os.Open(mountPoint)
209210
if err != nil {
210211
klog.Fatalf("Error opening block device %q: %+v", mountPoint, err)

pkg/importer/upload-datasource.go

-4
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ func (ud *UploadDataSource) Info() (ProcessingPhase, error) {
5151
if ud.contentType == cdiv1.DataVolumeArchive {
5252
return ProcessingPhaseTransferDataDir, nil
5353
}
54-
if !ud.readers.Convert {
55-
// Uploading a raw file, we can write that directly to the target.
56-
return ProcessingPhaseTransferDataFile, nil
57-
}
5854
return ProcessingPhaseTransferScratch, nil
5955
}
6056

pkg/importer/upload-datasource_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ var _ = Describe("Upload data source", func() {
7171
Expect(ProcessingPhaseTransferDataDir).To(Equal(result))
7272
})
7373

74-
It("Info should return TransferData, when passed in a valid raw image", func() {
74+
It("Info should return TransferScratch, when passed in a valid raw image", func() {
7575
// Don't need to defer close, since ud.Close will close the reader
7676
file, err := os.Open(tinyCoreFilePath)
7777
Expect(err).NotTo(HaveOccurred())
7878
ud = NewUploadDataSource(file, dvKubevirt)
7979
result, err := ud.Info()
8080
Expect(err).NotTo(HaveOccurred())
81-
Expect(ProcessingPhaseTransferDataFile).To(Equal(result))
81+
Expect(ProcessingPhaseTransferScratch).To(Equal(result))
8282
})
8383

8484
DescribeTable("calling transfer should", func(fileName string, dvContentType cdiv1.DataVolumeContentType, expectedPhase ProcessingPhase, scratchPath string, want []byte, wantErr bool) {
@@ -136,7 +136,7 @@ var _ = Describe("Upload data source", func() {
136136
ud = NewUploadDataSource(sourceFile, dvKubevirt)
137137
result, err := ud.Info()
138138
Expect(err).NotTo(HaveOccurred())
139-
Expect(ProcessingPhaseTransferDataFile).To(Equal(result))
139+
Expect(ProcessingPhaseTransferScratch).To(Equal(result))
140140
result, err = ud.TransferFile(filepath.Join(tmpDir, "file"))
141141
Expect(err).ToNot(HaveOccurred())
142142
Expect(ProcessingPhaseResize).To(Equal(result))
@@ -149,7 +149,7 @@ var _ = Describe("Upload data source", func() {
149149
ud = NewUploadDataSource(sourceFile, dvKubevirt)
150150
result, err := ud.Info()
151151
Expect(err).NotTo(HaveOccurred())
152-
Expect(ProcessingPhaseTransferDataFile).To(Equal(result))
152+
Expect(ProcessingPhaseTransferScratch).To(Equal(result))
153153
result, err = ud.TransferFile("/invalidpath/invalidfile")
154154
Expect(err).To(HaveOccurred())
155155
Expect(ProcessingPhaseError).To(Equal(result))
@@ -204,14 +204,14 @@ var _ = Describe("Async Upload data source", func() {
204204
Expect(ProcessingPhaseTransferScratch).To(Equal(result))
205205
})
206206

207-
It("Info should return TransferData, when passed in a valid raw image", func() {
207+
It("Info should return TransferScratch, when passed in a valid raw image", func() {
208208
// Don't need to defer close, since ud.Close will close the reader
209209
file, err := os.Open(tinyCoreFilePath)
210210
Expect(err).NotTo(HaveOccurred())
211211
aud = NewAsyncUploadDataSource(file)
212212
result, err := aud.Info()
213213
Expect(err).NotTo(HaveOccurred())
214-
Expect(ProcessingPhaseTransferDataFile).To(Equal(result))
214+
Expect(ProcessingPhaseTransferScratch).To(Equal(result))
215215
})
216216

217217
DescribeTable("calling transfer should", func(fileName, scratchPath string, want []byte, wantErr bool) {
@@ -260,7 +260,7 @@ var _ = Describe("Async Upload data source", func() {
260260
aud = NewAsyncUploadDataSource(sourceFile)
261261
result, err := aud.Info()
262262
Expect(err).NotTo(HaveOccurred())
263-
Expect(ProcessingPhaseTransferDataFile).To(Equal(result))
263+
Expect(ProcessingPhaseTransferScratch).To(Equal(result))
264264
result, err = aud.TransferFile(filepath.Join(tmpDir, "file"))
265265
Expect(err).ToNot(HaveOccurred())
266266
Expect(ProcessingPhaseValidatePause).To(Equal(result))
@@ -274,7 +274,7 @@ var _ = Describe("Async Upload data source", func() {
274274
aud = NewAsyncUploadDataSource(sourceFile)
275275
result, err := aud.Info()
276276
Expect(err).NotTo(HaveOccurred())
277-
Expect(ProcessingPhaseTransferDataFile).To(Equal(result))
277+
Expect(ProcessingPhaseTransferScratch).To(Equal(result))
278278
result, err = aud.TransferFile("/invalidpath/invalidfile")
279279
Expect(err).To(HaveOccurred())
280280
Expect(ProcessingPhaseError).To(Equal(result))

tests/upload_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,6 @@ var _ = Describe("[rfe_id:138][crit:high][vendor:[email protected]][level:compon
413413
same, err := f.VerifyTargetPVCContentMD5(f.Namespace, archivePVC, pathInPvc, expectedMd5)
414414
Expect(err).ToNot(HaveOccurred())
415415
Expect(same).To(BeTrue())
416-
By("Verifying the image is sparse")
417-
Expect(f.VerifySparse(f.Namespace, archivePVC, pathInPvc, utils.UploadFileSize)).To(BeTrue())
418416
}
419417
} else {
420418
checkFailureNoValidToken(archivePVC)
@@ -733,8 +731,6 @@ var _ = Describe("[rfe_id:138][crit:high][vendor:[email protected]][level:compon
733731
same, err := f.VerifyTargetPVCContentMD5(f.Namespace, pvc, pathInPvc, expectedMd5)
734732
Expect(err).ToNot(HaveOccurred())
735733
Expect(same).To(BeTrue())
736-
By("Verifying the image is sparse")
737-
Expect(f.VerifySparse(f.Namespace, pvc, pathInPvc, utils.UploadFileSize)).To(BeTrue())
738734
}
739735
} else {
740736
checkFailureNoValidToken(pvcPrime)

0 commit comments

Comments
 (0)