AB#2287 support community image IDs (#9)

* support community image IDs
Signed-off-by: Fabian Kammel <fk@edgeless.systems>
This commit is contained in:
Fabian Kammel 2022-08-30 15:15:51 +02:00 committed by GitHub
parent e0a457b6ff
commit 778952e07c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 175 additions and 41 deletions

View file

@ -5,6 +5,7 @@ import (
"fmt"
"strings"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v2"
)
@ -22,10 +23,14 @@ func (c *Client) GetScalingGroupImage(ctx context.Context, scalingGroupID string
res.Properties.VirtualMachineProfile == nil ||
res.Properties.VirtualMachineProfile.StorageProfile == nil ||
res.Properties.VirtualMachineProfile.StorageProfile.ImageReference == nil ||
res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.ID == nil {
res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.ID == nil && res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.CommunityGalleryImageID == nil {
return "", fmt.Errorf("scalet set %q does not have valid image reference", scalingGroupID)
}
return *res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.ID, nil
if res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.ID != nil {
return *res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.ID, nil
} else {
return *res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.CommunityGalleryImageID, nil
}
}
// SetScalingGroupImage sets the image URI of the scaling group.
@ -38,9 +43,7 @@ func (c *Client) SetScalingGroupImage(ctx context.Context, scalingGroupID, image
Properties: &armcompute.VirtualMachineScaleSetUpdateProperties{
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetUpdateVMProfile{
StorageProfile: &armcompute.VirtualMachineScaleSetUpdateStorageProfile{
ImageReference: &armcompute.ImageReference{
ID: &imageURI,
},
ImageReference: imageReferenceFromImage(imageURI),
},
},
},
@ -82,3 +85,15 @@ func (c *Client) ListScalingGroups(ctx context.Context, uid string) (controlPlan
}
return controlPlaneGroupIDs, workerGroupIDs, nil
}
func imageReferenceFromImage(img string) *armcompute.ImageReference {
ref := &armcompute.ImageReference{}
if strings.HasPrefix(img, "/CommunityGalleries") {
ref.CommunityGalleryImageID = to.Ptr(img)
} else {
ref.ID = to.Ptr(img)
}
return ref
}