worker: support returning returning images as StreamOptimized
vCenter requires images to be uploaded as vmdk StreamOptimized. Lorax always produced images on this format, so we should make sure to do the same for our VMWare images. Allow LocalTarget to request the images produced by osbuild be converted to be streamOptimized before saving in composer, and hook the weldr API up to enable this option for vmdk images. Ideally this should simply be an option in osbuild, but that would require some more work, which we will not manage in time for RHEL8.3. Therefore do this minimal fix. Note that that means the images produced by our manifests (including in our image-test test cases) are not on the format that the weldr API returns, so the tests we run on them would also, for now, need to convert before uploading to vCenter. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
bdea79613c
commit
b0cd29f78b
5 changed files with 45 additions and 10 deletions
|
|
@ -11,6 +11,7 @@ import (
|
|||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
|
|
@ -65,6 +66,26 @@ func (e *TargetsError) Error() string {
|
|||
return errString
|
||||
}
|
||||
|
||||
func openAsStreamOptimizedVmdk(imagePath string) (*os.File, error) {
|
||||
newPath := imagePath + ".stream"
|
||||
cmd := exec.Command(
|
||||
"/usr/bin/qemu-img", "convert", "-O", "vmdk", "-o", "subformat=streamOptimized",
|
||||
imagePath, newPath)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f, err := os.Open(newPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = os.Remove(newPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return f, err
|
||||
}
|
||||
|
||||
func RunJob(job *worker.Job, store string, uploadFunc func(uuid.UUID, string, io.Reader) error) (*common.ComposeResult, error) {
|
||||
outputDirectory, err := ioutil.TempDir("/var/tmp", "osbuild-worker-*")
|
||||
if err != nil {
|
||||
|
|
@ -87,10 +108,20 @@ func RunJob(job *worker.Job, store string, uploadFunc func(uuid.UUID, string, io
|
|||
for _, t := range job.Targets {
|
||||
switch options := t.Options.(type) {
|
||||
case *target.LocalTargetOptions:
|
||||
f, err := os.Open(path.Join(outputDirectory, options.Filename))
|
||||
if err != nil {
|
||||
r = append(r, err)
|
||||
continue
|
||||
var f *os.File
|
||||
imagePath := path.Join(outputDirectory, options.Filename)
|
||||
if options.StreamOptimized {
|
||||
f, err = openAsStreamOptimizedVmdk(imagePath)
|
||||
if err != nil {
|
||||
r = append(r, err)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
f, err = os.Open(imagePath)
|
||||
if err != nil {
|
||||
r = append(r, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
err = uploadFunc(job.Id, options.Filename, f)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue