mirror of https://github.com/kubernetes/kops.git
Merge pull request #10797 from t1cg/azureManagedImage
Allow managed images for Azure instance groups
This commit is contained in:
commit
7d8ef74bcd
|
|
@ -176,9 +176,7 @@ func getStorageProfile(spec *kops.InstanceGroupSpec) (*compute.VirtualMachineSca
|
||||||
storageAccountType = compute.StorageAccountTypesPremiumLRS
|
storageAccountType = compute.StorageAccountTypesPremiumLRS
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(kenji): We currently assume that spec.Image has an
|
imageReference, err := parseImage(spec.Image)
|
||||||
// image URN. Be able to specify image ID as well.
|
|
||||||
imageReference, err := parseImageURN(spec.Image)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -198,14 +196,17 @@ func getStorageProfile(spec *kops.InstanceGroupSpec) (*compute.VirtualMachineSca
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseImageURN parses an image URL and returns an ImageReference.
|
func parseImage(image string) (*compute.ImageReference, error) {
|
||||||
func parseImageURN(urn string) (*compute.ImageReference, error) {
|
if strings.HasPrefix(image, "/subscriptions/") {
|
||||||
// Image URN is of the form <publisher>:<offer>:<sku>:<version>.
|
return &compute.ImageReference{
|
||||||
l := strings.Split(urn, ":")
|
ID: to.StringPtr(image),
|
||||||
if len(l) != 4 {
|
}, nil
|
||||||
return nil, fmt.Errorf("malformed format of image urn: %s", urn)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
l := strings.Split(image, ":")
|
||||||
|
if len(l) != 4 {
|
||||||
|
return nil, fmt.Errorf("malformed format of image urn: %s", image)
|
||||||
|
}
|
||||||
return &compute.ImageReference{
|
return &compute.ImageReference{
|
||||||
Publisher: to.StringPtr(l[0]),
|
Publisher: to.StringPtr(l[0]),
|
||||||
Offer: to.StringPtr(l[1]),
|
Offer: to.StringPtr(l[1]),
|
||||||
|
|
|
||||||
|
|
@ -176,14 +176,14 @@ func TestGetStorageProfile(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseImageURN(t *testing.T) {
|
func TestParseImage(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
urn string
|
image string
|
||||||
success bool
|
success bool
|
||||||
imageRef *compute.ImageReference
|
imageRef *compute.ImageReference
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
urn: "Canonical:UbuntuServer:18.04-LTS:latest",
|
image: "Canonical:UbuntuServer:18.04-LTS:latest",
|
||||||
success: true,
|
success: true,
|
||||||
imageRef: &compute.ImageReference{
|
imageRef: &compute.ImageReference{
|
||||||
Publisher: to.StringPtr("Canonical"),
|
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,
|
success: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
urn: "inv:ali:dfo:rma:t",
|
image: "inv:ali:dfo:rma:t",
|
||||||
success: false,
|
success: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
t.Run(fmt.Sprintf("test case %d", i), func(t *testing.T) {
|
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 !tc.success {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("unexpected success")
|
t.Fatalf("unexpected success")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue