image: only archive release images + QEMU / OpenStack image

This commit is contained in:
Malte Poll 2024-01-05 09:49:11 +01:00
parent 8a74893461
commit 9a27e7bf77

View File

@ -14,6 +14,7 @@ import (
"strings" "strings"
"github.com/edgelesssys/constellation/v2/internal/api/versionsapi" "github.com/edgelesssys/constellation/v2/internal/api/versionsapi"
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/v2/internal/osimage" "github.com/edgelesssys/constellation/v2/internal/osimage"
) )
@ -24,10 +25,16 @@ func uploadImage(ctx context.Context, archiveC archivist, uploadC uploader, req
return err return err
} }
defer imageReader.Close() defer imageReader.Close()
archiveURL, err := archiveC.Archive(ctx, req.Version, strings.ToLower(req.Provider.String()), req.AttestationVariant, imageReader)
var archiveURL string
if needsArchival(req.Provider, req.Version) {
var err error
archiveURL, err = archiveC.Archive(ctx, req.Version, strings.ToLower(req.Provider.String()), req.AttestationVariant, imageReader)
if err != nil { if err != nil {
return err return err
} }
}
// upload to CSP // upload to CSP
imageReferences, err := uploadC.Upload(ctx, req) imageReferences, err := uploadC.Upload(ctx, req)
if err != nil { if err != nil {
@ -56,3 +63,12 @@ func uploadImage(ctx context.Context, archiveC archivist, uploadC uploader, req
return nil return nil
} }
func needsArchival(provider cloudprovider.Provider, version versionsapi.Version) bool {
switch provider {
case cloudprovider.OpenStack, cloudprovider.QEMU: // image upload for some CSPs only consists of this archival step
return true
}
return version.Stream() == "stable" || version.Ref() == "-"
}