Merge pull request #10797 from t1cg/azureManagedImage

Allow managed images for Azure instance groups
This commit is contained in:
Kubernetes Prow Robot 2021-02-12 16:27:05 -08:00 committed by GitHub
commit 7d8ef74bcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 15 deletions

View File

@ -176,9 +176,7 @@ func getStorageProfile(spec *kops.InstanceGroupSpec) (*compute.VirtualMachineSca
storageAccountType = compute.StorageAccountTypesPremiumLRS
}
// TODO(kenji): We currently assume that spec.Image has an
// image URN. Be able to specify image ID as well.
imageReference, err := parseImageURN(spec.Image)
imageReference, err := parseImage(spec.Image)
if err != nil {
return nil, err
}
@ -198,14 +196,17 @@ func getStorageProfile(spec *kops.InstanceGroupSpec) (*compute.VirtualMachineSca
}, nil
}
// parseImageURN parses an image URL and returns an ImageReference.
func parseImageURN(urn string) (*compute.ImageReference, error) {
// Image URN is of the form <publisher>:<offer>:<sku>:<version>.
l := strings.Split(urn, ":")
if len(l) != 4 {
return nil, fmt.Errorf("malformed format of image urn: %s", urn)
func parseImage(image string) (*compute.ImageReference, error) {
if strings.HasPrefix(image, "/subscriptions/") {
return &compute.ImageReference{
ID: to.StringPtr(image),
}, nil
}
l := strings.Split(image, ":")
if len(l) != 4 {
return nil, fmt.Errorf("malformed format of image urn: %s", image)
}
return &compute.ImageReference{
Publisher: to.StringPtr(l[0]),
Offer: to.StringPtr(l[1]),

View File

@ -176,14 +176,14 @@ func TestGetStorageProfile(t *testing.T) {
}
}
func TestParseImageURN(t *testing.T) {
func TestParseImage(t *testing.T) {
testCases := []struct {
urn string
image string
success bool
imageRef *compute.ImageReference
}{
{
urn: "Canonical:UbuntuServer:18.04-LTS:latest",
image: "Canonical:UbuntuServer:18.04-LTS:latest",
success: true,
imageRef: &compute.ImageReference{
Publisher: to.StringPtr("Canonical"),
@ -193,17 +193,24 @@ func TestParseImageURN(t *testing.T) {
},
},
{
urn: "invalidformat",
image: "/subscriptions/<subscription id>/resourceGroups/<resource group>/providers/<provider>/images/<image>",
success: true,
imageRef: &compute.ImageReference{
ID: to.StringPtr("/subscriptions/<subscription id>/resourceGroups/<resource group>/providers/<provider>/images/<image>"),
},
},
{
image: "invalidformat",
success: false,
},
{
urn: "inv:ali:dfo:rma:t",
image: "inv:ali:dfo:rma:t",
success: false,
},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("test case %d", i), func(t *testing.T) {
imageRef, err := parseImageURN(tc.urn)
imageRef, err := parseImage(tc.image)
if !tc.success {
if err == nil {
t.Fatalf("unexpected success")