55 "fmt"
66 "net"
77 "net/url"
8- "os"
98 "slices"
109 "sort"
1110 "strconv"
@@ -53,23 +52,23 @@ var computeReq = resourceRequirements{
5352}
5453
5554// Validate executes platform-specific validation.
56- func Validate (client API , ic * types.InstallConfig ) error {
55+ func Validate (client API , meta * Metadata , ic * types.InstallConfig ) error {
5756 allErrs := field.ErrorList {}
5857
5958 allErrs = append (allErrs , validateNetworks (client , ic .Azure , field .NewPath ("platform" ).Child ("azure" ))... )
6059 allErrs = append (allErrs , validateRegion (client , field .NewPath ("platform" ).Child ("azure" ).Child ("region" ), ic .Azure )... )
6160 if ic .Azure .CloudName == aztypes .StackCloud {
6261 allErrs = append (allErrs , validateAzureStackDiskType (client , ic )... )
6362 }
64- allErrs = append (allErrs , validateInstanceTypes (client , ic )... )
63+ allErrs = append (allErrs , validateInstanceTypes (client , meta , ic )... )
6564 if ic .Azure .CloudName == aztypes .StackCloud && ic .Azure .ClusterOSImage != "" {
6665 StorageEndpointSuffix , err := client .GetStorageEndpointSuffix (context .TODO ())
6766 if err != nil {
6867 return err
6968 }
7069 allErrs = append (allErrs , validateAzureStackClusterOSImage (StorageEndpointSuffix , ic .Azure .ClusterOSImage , field .NewPath ("platform" ).Child ("azure" ))... )
7170 }
72- allErrs = append (allErrs , validateMarketplaceImages (client , ic )... )
71+ allErrs = append (allErrs , validateMarketplaceImages (client , meta , ic )... )
7372 allErrs = append (allErrs , validateBootDiagnostics (client , ic )... )
7473 allErrs = append (allErrs , validateCustomSubnets (client , field .NewPath ("platform" ).Child ("azure" ).Child ("subnetSpec" ), ic )... )
7574 return allErrs .ToAggregate ()
@@ -353,12 +352,15 @@ func validateUltraSSD(client API, fieldPath *field.Path, icZones []string, regio
353352}
354353
355354// ValidateInstanceType ensures the instance type has sufficient Vcpu, Memory, and a valid family type.
356- func ValidateInstanceType (client API , fieldPath * field.Path , region , instanceType , diskType string , req resourceRequirements , ultraSSDEnabled bool , vmNetworkingType string , icZones []string , architecture types.Architecture , securityType aztypes.SecurityTypes ) field.ErrorList {
355+ func ValidateInstanceType (client API , fieldPath * field.Path , region , instanceType , diskType string , req resourceRequirements , ultraSSDEnabled bool , vmNetworkingType string , icZones []string , architecture types.Architecture , securityType aztypes.SecurityTypes , capabilities map [ string ] string ) field.ErrorList {
357356 allErrs := field.ErrorList {}
358357
359- capabilities , err := client .GetVMCapabilities (context .TODO (), instanceType , region )
360- if err != nil {
361- return append (allErrs , field .Invalid (fieldPath .Child ("type" ), instanceType , err .Error ()))
358+ var err error
359+ if capabilities == nil {
360+ capabilities , err = client .GetVMCapabilities (context .TODO (), instanceType , region )
361+ if err != nil {
362+ return append (allErrs , field .Invalid (fieldPath .Child ("type" ), instanceType , err .Error ()))
363+ }
362364 }
363365
364366 allErrs = append (allErrs , validateMininumRequirements (fieldPath .Child ("type" ), req , instanceType , capabilities )... )
@@ -386,7 +388,7 @@ func ValidateInstanceType(client API, fieldPath *field.Path, region, instanceTyp
386388}
387389
388390// validateInstanceTypes checks that the user-provided instance types are valid.
389- func validateInstanceTypes (client API , ic * types.InstallConfig ) field.ErrorList {
391+ func validateInstanceTypes (client API , meta * Metadata , ic * types.InstallConfig ) field.ErrorList {
390392 allErrs := field.ErrorList {}
391393
392394 var securityType aztypes.SecurityTypes
@@ -451,7 +453,7 @@ func validateInstanceTypes(client API, ic *types.InstallConfig) field.ErrorList
451453 zones = defaultZones
452454 }
453455 ultraSSDEnabled := strings .EqualFold (ultraSSDCapability , "Enabled" )
454- allErrs = append (allErrs , ValidateInstanceType (client , fieldPath , ic .Azure .Region , instanceType , diskType , controlPlaneReq , ultraSSDEnabled , vmNetworkingType , zones , architecture , securityType )... )
456+ allErrs = append (allErrs , ValidateInstanceType (client , fieldPath , ic .Azure .Region , instanceType , diskType , controlPlaneReq , ultraSSDEnabled , vmNetworkingType , zones , architecture , securityType , meta . controlPlaneCapabilities )... )
455457 }
456458
457459 for idx , compute := range ic .Compute {
@@ -488,7 +490,7 @@ func validateInstanceTypes(client API, ic *types.InstallConfig) field.ErrorList
488490 }
489491 ultraSSDEnabled := strings .EqualFold (ultraSSDCapability , "Enabled" )
490492 allErrs = append (allErrs , ValidateInstanceType (client , fieldPath .Child ("platform" , "azure" ),
491- ic .Azure .Region , instanceType , diskType , computeReq , ultraSSDEnabled , vmNetworkingType , zones , architecture , securityType )... )
493+ ic .Azure .Region , instanceType , diskType , computeReq , ultraSSDEnabled , vmNetworkingType , zones , architecture , securityType , meta . computeCapabilities )... )
492494 }
493495 }
494496
@@ -507,7 +509,7 @@ func validateInstanceTypes(client API, ic *types.InstallConfig) field.ErrorList
507509 fieldPath := field .NewPath ("platform" , "azure" , "defaultMachinePlatform" )
508510 ultraSSDEnabled := strings .EqualFold (defaultUltraSSDCapability , "Enabled" )
509511 allErrs = append (allErrs , ValidateInstanceType (client , fieldPath ,
510- ic .Azure .Region , defaultInstanceType , defaultDiskType , minReq , ultraSSDEnabled , defaultVMNetworkingType , defaultZones , architecture , securityType )... )
512+ ic .Azure .Region , defaultInstanceType , defaultDiskType , minReq , ultraSSDEnabled , defaultVMNetworkingType , defaultZones , architecture , securityType , nil )... )
511513 }
512514 return allErrs
513515}
@@ -662,46 +664,12 @@ func ValidateForProvisioning(client API, ic *types.InstallConfig) error {
662664 allErrs = append (allErrs , validateResourceGroup (client , field .NewPath ("platform" ).Child ("azure" ), ic .Azure )... )
663665 allErrs = append (allErrs , ValidateDiskEncryptionSet (client , ic )... )
664666 allErrs = append (allErrs , ValidateSecurityProfileDiskEncryptionSet (client , ic )... )
665- allErrs = append (allErrs , validateSkipImageUpload (field .NewPath ("image" ), ic )... )
666667 if ic .Azure .CloudName == aztypes .StackCloud {
667668 allErrs = append (allErrs , checkAzureStackClusterOSImageSet (ic .Azure .ClusterOSImage , field .NewPath ("platform" ).Child ("azure" ))... )
668669 }
669670 return allErrs .ToAggregate ()
670671}
671672
672- func validateSkipImageUpload (fieldPath * field.Path , ic * types.InstallConfig ) field.ErrorList {
673- allErrs := field.ErrorList {}
674- defaultOSImage := aztypes.OSImage {}
675- if ic .Azure .DefaultMachinePlatform != nil {
676- defaultOSImage = aztypes.OSImage {
677- Plan : ic .Azure .DefaultMachinePlatform .OSImage .Plan ,
678- Publisher : ic .Azure .DefaultMachinePlatform .OSImage .Publisher ,
679- SKU : ic .Azure .DefaultMachinePlatform .OSImage .SKU ,
680- Version : ic .Azure .DefaultMachinePlatform .OSImage .Version ,
681- Offer : ic .Azure .DefaultMachinePlatform .OSImage .Offer ,
682- }
683- }
684- controlPlaneOSImage := defaultOSImage
685- if ic .ControlPlane .Platform .Azure != nil {
686- controlPlaneOSImage = ic .ControlPlane .Platform .Azure .OSImage
687- }
688- allErrs = append (allErrs , validateOSImage (fieldPath .Child ("controlplane" ), controlPlaneOSImage )... )
689- computeOSImage := defaultOSImage
690- if len (ic .Compute ) > 0 && ic .Compute [0 ].Platform .Azure != nil {
691- computeOSImage = ic .Compute [0 ].Platform .Azure .OSImage
692- }
693- allErrs = append (allErrs , validateOSImage (fieldPath .Child ("compute" ), computeOSImage )... )
694- return allErrs
695- }
696- func validateOSImage (fieldPath * field.Path , osImage aztypes.OSImage ) field.ErrorList {
697- if _ , ok := os .LookupEnv ("OPENSHIFT_INSTALL_SKIP_IMAGE_UPLOAD" ); ok {
698- if len (osImage .SKU ) > 0 {
699- return nil
700- }
701- return field.ErrorList {field .Invalid (fieldPath , "image" , "cannot skip image upload without marketplace image specified" )}
702- }
703- return nil
704- }
705673func validateResourceGroup (client API , fieldPath * field.Path , platform * aztypes.Platform ) field.ErrorList {
706674 allErrs := field.ErrorList {}
707675 if len (platform .ResourceGroupName ) == 0 {
@@ -766,7 +734,7 @@ func validateAzureStackClusterOSImage(StorageEndpointSuffix string, ClusterOSIma
766734 return allErrs
767735}
768736
769- func validateMarketplaceImages (client API , installConfig * types.InstallConfig ) field.ErrorList {
737+ func validateMarketplaceImages (client API , meta * Metadata , installConfig * types.InstallConfig ) field.ErrorList {
770738 var allErrs field.ErrorList
771739
772740 region := installConfig .Azure .Region
@@ -796,7 +764,7 @@ func validateMarketplaceImages(client API, installConfig *types.InstallConfig) f
796764 instanceType = defaults .ControlPlaneInstanceType (cloudName , region , installConfig .ControlPlane .Architecture )
797765 }
798766
799- capabilities , err := client . GetVMCapabilities ( context . Background (), instanceType , region )
767+ capabilities , err := meta . ControlPlaneCapabilities ( )
800768 if err != nil {
801769 allErrs = append (allErrs , field .Invalid (fldPath .Child ("platform" , "azure" , "type" ), instanceType , err .Error ()))
802770 }
@@ -838,7 +806,7 @@ func validateMarketplaceImages(client API, installConfig *types.InstallConfig) f
838806 instanceType = defaults .ComputeInstanceType (cloudName , region , compute .Architecture )
839807 }
840808
841- capabilities , err := client . GetVMCapabilities ( context . Background (), instanceType , region )
809+ capabilities , err := meta . ComputeCapabilities ( )
842810 if err != nil {
843811 allErrs = append (allErrs , field .Invalid (fldPath .Child ("platform" , "azure" , "type" ), instanceType , err .Error ()))
844812 continue
0 commit comments