Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mantle/cmd/ore/azure/create-gallery-image.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (

galleryImageName string
galleryName string
architecture string
)

func init() {
Expand All @@ -45,6 +46,7 @@ func init() {
sv(&galleryName, "gallery-name", "kola", "gallery name")
sv(&blobUrl, "image-blob", "", "source blob url")
sv(&resourceGroup, "resource-group", "kola", "resource group name")
sv(&architecture, "arch", "", "The target architecture for the image")

Azure.AddCommand(cmdCreateGalleryImage)
}
Expand All @@ -71,7 +73,7 @@ func runCreateGalleryImage(cmd *cobra.Command, args []string) error {
}
sourceImageId := *img.ID

galleryImage, err := api.CreateGalleryImage(galleryImageName, galleryName, resourceGroup, sourceImageId)
galleryImage, err := api.CreateGalleryImage(galleryImageName, galleryName, resourceGroup, sourceImageId, architecture)
if err != nil {
fmt.Fprintf(os.Stderr, "Couldn't create Azure Shared Image Gallery image: %v\n", err)
os.Exit(1)
Expand Down
19 changes: 17 additions & 2 deletions mantle/platform/api/azure/gallery.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package azure
import (
"context"
"fmt"
"runtime"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
Expand All @@ -26,7 +27,7 @@ import (
"github.com/coreos/coreos-assembler/mantle/util"
)

func (a *API) CreateGalleryImage(name, galleryName, resourceGroup, sourceImageID string) (armcompute.GalleryImageVersion, error) {
func (a *API) CreateGalleryImage(name, galleryName, resourceGroup, sourceImageID, architecture string) (armcompute.GalleryImageVersion, error) {
ctx := context.Background()

// Ensure the Azure Shared Image Gallery exists. BeginCreateOrUpdate will create the gallery
Expand Down Expand Up @@ -54,6 +55,19 @@ func (a *API) CreateGalleryImage(name, galleryName, resourceGroup, sourceImageID
},
}

var azureArch armcompute.Architecture
if architecture == "" {
architecture = runtime.GOARCH
}
switch architecture {
case "amd64", "x86_64":
azureArch = armcompute.ArchitectureX64
case "arm64", "aarch64":
azureArch = armcompute.ArchitectureArm64
default:
return armcompute.GalleryImageVersion{}, fmt.Errorf("unsupported azure architecture %q", architecture)
}

// Create a Gallery Image Definition with the specified Hyper-V generation (V1 or V2).
galleryImagePoller, err := a.galImgClient.BeginCreateOrUpdate(ctx, resourceGroup, galleryName, name, armcompute.GalleryImage{
Location: &a.opts.Location,
Expand All @@ -66,7 +80,8 @@ func (a *API) CreateGalleryImage(name, galleryName, resourceGroup, sourceImageID
Offer: to.Ptr(name),
SKU: to.Ptr(util.RandomName("sku")),
},
Features: galleryImageFeatures,
Features: galleryImageFeatures,
Architecture: &azureArch,
},
}, nil)
if err != nil {
Expand Down
Loading