Skip to content

Commit 018648f

Browse files
committed
cloudapi: Add architecture support to the optional Blueprint
If included it overrides the architecture in the compose image request. Related: RHEL-60125
1 parent 86f9033 commit 018648f

File tree

4 files changed

+230
-184
lines changed

4 files changed

+230
-184
lines changed

internal/cloudapi/v2/compose.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,9 @@ func (request *ComposeRequest) GetBlueprintFromCompose() (blueprint.Blueprint, e
514514
if rbp.Distro != nil {
515515
bp.Distro = *rbp.Distro
516516
}
517+
if rbp.Architecture != nil {
518+
bp.Arch = *rbp.Architecture
519+
}
517520

518521
if rbp.Packages != nil {
519522
for _, pkg := range *rbp.Packages {
@@ -1144,7 +1147,12 @@ func (request *ComposeRequest) GetImageRequests(distroFactory *distrofactory.Fac
11441147
}
11451148
var irs []imageRequest
11461149
for _, ir := range *request.ImageRequests {
1147-
arch, err := distribution.GetArch(ir.Architecture)
1150+
reqArch := ir.Architecture
1151+
// If there is an architecture in the blueprint it overrides the request's arch
1152+
if len(bp.Arch) > 0 {
1153+
reqArch = bp.Arch
1154+
}
1155+
arch, err := distribution.GetArch(reqArch)
11481156
if err != nil {
11491157
return nil, HTTPError(ErrorUnsupportedArchitecture)
11501158
}

internal/cloudapi/v2/compose_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,33 @@ func TestGetImageRequests_BlueprintDistro(t *testing.T) {
848848
assert.Equal(t, got[0].blueprint.Distro, "fedora-39")
849849
}
850850

851+
// TestGetImageRequests_BlueprintArch test to make sure blueprint architecture overrides
852+
// the request arch
853+
func TestGetImageRequests_BlueprintArch(t *testing.T) {
854+
uo := UploadOptions(struct{}{})
855+
request := &ComposeRequest{
856+
Distribution: "fedora-40",
857+
ImageRequest: &ImageRequest{
858+
Architecture: "x86_64",
859+
ImageType: ImageTypesAws,
860+
UploadOptions: &uo,
861+
Repositories: []Repository{},
862+
},
863+
Blueprint: &Blueprint{
864+
Name: "arch-test",
865+
Architecture: common.ToPtr("aarch64"),
866+
},
867+
}
868+
// NOTE: current directory is the location of this file, back up so it can use ./repositories/
869+
rr, err := reporegistry.New([]string{"../../../"})
870+
require.NoError(t, err)
871+
got, err := request.GetImageRequests(distrofactory.NewDefault(), rr)
872+
assert.NoError(t, err)
873+
require.Len(t, got, 1)
874+
require.Greater(t, len(got[0].repositories), 0)
875+
assert.Equal(t, got[0].blueprint.Arch, "aarch64")
876+
}
877+
851878
func TestOpenSCAPTailoringOptions(t *testing.T) {
852879
cr := ComposeRequest{
853880
Customizations: &Customizations{

0 commit comments

Comments
 (0)