Skip to content

Commit

Permalink
UPSTREAM: <carry>: Add VM Support for Marketplace Purchase Plans
Browse files Browse the repository at this point in the history
VMs created from images in the marketplace or shared galleries
may require purchase plans. This adds logic to pass through specified
plan data when appropriate.
  • Loading branch information
patrickdillon authored and openshift-merge-robot committed Dec 2, 2021
1 parent f73f0af commit 184cced
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/cloud/azure/services/virtualmachines/virtualmachines.go
Expand Up @@ -241,6 +241,7 @@ func deriveVirtualMachineParameters(vmSpec *Spec, location string, subscription
virtualMachine := &compute.VirtualMachine{
Location: to.StringPtr(location),
Tags: getTagListFromSpec(vmSpec),
Plan: generateImagePlan(vmSpec.Image),
VirtualMachineProperties: &compute.VirtualMachineProperties{
HardwareProfile: &compute.HardwareProfile{
VMSize: compute.VirtualMachineSizeTypes(vmSpec.Size),
Expand Down Expand Up @@ -346,3 +347,20 @@ func GenerateRandomString(n int) (string, error) {
}
return base64.URLEncoding.EncodeToString(b), err
}

func generateImagePlan(image v1beta1.Image) *compute.Plan {
// We only need a purchase plan for third-party marketplace images.
if image.Type == "" || image.Type == v1beta1.AzureImageTypeMarketplaceNoPlan {
return nil
}

if image.Publisher == "" || image.SKU == "" || image.Offer == "" {
return nil
}

return &compute.Plan{
Publisher: to.StringPtr(image.Publisher),
Name: to.StringPtr(image.SKU),
Product: to.StringPtr(image.Offer),
}
}
17 changes: 17 additions & 0 deletions pkg/cloud/azure/services/virtualmachines/virtualmachines_test.go
Expand Up @@ -90,6 +90,23 @@ func TestDeriveVirtualMachineParameters(t *testing.T) {
g.Expect(vm.SecurityProfile.EncryptionAtHost).To(BeNil())
},
},
{
name: "Non-ThirdParty Marketplace Image",
updateSpec: nil,
validate: func(g *WithT, vm *compute.VirtualMachine) {
g.Expect(vm.Plan).To(BeNil())
},
},
{
name: "ThirdParty Marketplace Image",
updateSpec: func(vmSpec *Spec) {
vmSpec.Image.Type = v1beta1.AzureImageTypeMarketplaceWithPlan
},
validate: func(g *WithT, vm *compute.VirtualMachine) {
g.Expect(vm.Plan).ToNot(BeNil())

},
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 184cced

Please sign in to comment.