Skip to content

Commit 082fcc4

Browse files
committed
OCPBUGS-22840: ic/azure: validate field Plan when for marketplace images
If you try to deploy a cluster with a marketplace image that requires a purchase plan to be accepted but set it to `NoPurchasePlan` in the install-config, the VM provisioning will fail with: ``` ERROR Error: waiting for creation of Linux Virtual Machine: (Name "jima02test-7jf8d-bootstrap" / Resource Group "jima02test-7jf8d-rg"): Code="VMMarketplaceInvalidInput" Message="Creating a virtual machine from Marketplace image or a custom image sourced from a Marketplace image requires Plan information in the request. VM: '/subscriptions/$ID/resourceGroups/jima02test-7jf8d-rg/providers/Microsoft.Compute/virtualMachines/jima02test-7jf8d-bootstrap'." ``` Let's check if the `Plan` field actually matches what's expected based on the image's plan properties.
1 parent 7661345 commit 082fcc4

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

pkg/asset/installconfig/azure/validation.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -827,17 +827,25 @@ func validateMarketplaceImage(client API, region string, instanceHyperVGenSet se
827827
return field.Invalid(osImageFieldPath, osImage.SKU, errMsg)
828828
}
829829

830-
// Images with no purchase plan have no terms to be accepted
831-
if osImage.Plan == aztypes.ImageNoPurchasePlan {
832-
return nil
833-
}
834-
835-
termsAccepted, err := client.AreMarketplaceImageTermsAccepted(context.Background(), osImage.Publisher, osImage.Offer, osImage.SKU)
836-
if err != nil {
837-
return field.Invalid(osImageFieldPath, osImage, fmt.Sprintf("could not determine if the license terms for the marketplace image have been accepted: %v", err))
830+
// Image has license terms to be accepted
831+
osImagePlan := osImage.Plan
832+
if len(osImagePlan) == 0 {
833+
// Use the default if not set in the install-config
834+
osImagePlan = aztypes.ImageWithPurchasePlan
838835
}
839-
if !termsAccepted {
840-
return field.Invalid(osImageFieldPath, osImage, "the license terms for the marketplace image have not been accepted")
836+
if plan := vmImage.Plan; plan != nil {
837+
if osImagePlan == aztypes.ImageNoPurchasePlan {
838+
return field.Invalid(osImageFieldPath, osImage, "marketplace image requires license terms to be accepted")
839+
}
840+
termsAccepted, err := client.AreMarketplaceImageTermsAccepted(context.Background(), osImage.Publisher, osImage.Offer, osImage.SKU)
841+
if err != nil {
842+
return field.Invalid(osImageFieldPath, osImage, fmt.Sprintf("could not determine if the license terms for the marketplace image have been accepted: %v", err))
843+
}
844+
if !termsAccepted {
845+
return field.Invalid(osImageFieldPath, osImage, "the license terms for the marketplace image have not been accepted")
846+
}
847+
} else if osImagePlan == aztypes.ImageWithPurchasePlan {
848+
return field.Invalid(osImageFieldPath, osImage, "image has no license terms. Set Plan to \"NoPurchasePlan\" to continue.")
841849
}
842850

843851
return nil

pkg/asset/installconfig/azure/validation_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ var (
213213
}()
214214

215215
marketplaceImageAPIResult = azenc.VirtualMachineImage{
216+
Name: to.StringPtr("VMImage"),
217+
VirtualMachineImageProperties: &azenc.VirtualMachineImageProperties{
218+
HyperVGeneration: azenc.HyperVGenerationTypesV1,
219+
Plan: &azenc.PurchasePlan{},
220+
},
221+
}
222+
223+
marketplaceImageAPIResultNoPlan = azenc.VirtualMachineImage{
216224
Name: to.StringPtr("VMImage"),
217225
VirtualMachineImageProperties: &azenc.VirtualMachineImageProperties{
218226
HyperVGeneration: azenc.HyperVGenerationTypesV1,
@@ -1283,7 +1291,7 @@ func TestAzureMarketplaceImage(t *testing.T) {
12831291
},
12841292
}, nil).AnyTimes()
12851293
azureClient.EXPECT().AreMarketplaceImageTermsAccepted(gomock.Any(), validOSImagePublisher, validOSImageOffer, erroringOSImageSKU).Return(true, nil).AnyTimes()
1286-
azureClient.EXPECT().GetMarketplaceImage(gomock.Any(), validRegion, validOSImagePublisher, validOSImageOffer, noPlanOSImageSKU, validOSImageVersion).Return(marketplaceImageAPIResult, nil).AnyTimes()
1294+
azureClient.EXPECT().GetMarketplaceImage(gomock.Any(), validRegion, validOSImagePublisher, validOSImageOffer, noPlanOSImageSKU, validOSImageVersion).Return(marketplaceImageAPIResultNoPlan, nil).AnyTimes()
12871295
// Should not check terms of images with no purchase plan
12881296
azureClient.EXPECT().AreMarketplaceImageTermsAccepted(gomock.Any(), validOSImagePublisher, validOSImageOffer, noPlanOSImageSKU).MaxTimes(0)
12891297

0 commit comments

Comments
 (0)