@@ -48,8 +48,12 @@ func Validate(ctx context.Context, meta *Metadata, config *types.InstallConfig)
4848 allErrs = append (allErrs , validateAMI (ctx , config )... )
4949 allErrs = append (allErrs , validatePlatform (ctx , meta , field .NewPath ("platform" , "aws" ), config .Platform .AWS , config .Networking , config .Publish )... )
5050
51- if config .ControlPlane != nil && config .ControlPlane .Platform .AWS != nil {
52- allErrs = append (allErrs , validateMachinePool (ctx , meta , field .NewPath ("controlPlane" , "platform" , "aws" ), config .Platform .AWS , config .ControlPlane .Platform .AWS , controlPlaneReq , "" )... )
51+ if config .ControlPlane != nil {
52+ arch := string (config .ControlPlane .Architecture )
53+ pool := & awstypes.MachinePool {}
54+ pool .Set (config .AWS .DefaultMachinePlatform )
55+ pool .Set (config .ControlPlane .Platform .AWS )
56+ allErrs = append (allErrs , validateMachinePool (ctx , meta , field .NewPath ("controlPlane" , "platform" , "aws" ), config .Platform .AWS , pool , controlPlaneReq , "" , arch )... )
5357 }
5458
5559 for idx , compute := range config .Compute {
@@ -62,9 +66,11 @@ func Validate(ctx context.Context, meta *Metadata, config *types.InstallConfig)
6266 }
6367 }
6468
65- if compute .Platform .AWS != nil {
66- allErrs = append (allErrs , validateMachinePool (ctx , meta , fldPath .Child ("platform" , "aws" ), config .Platform .AWS , compute .Platform .AWS , computeReq , compute .Name )... )
67- }
69+ arch := string (compute .Architecture )
70+ pool := & awstypes.MachinePool {}
71+ pool .Set (config .AWS .DefaultMachinePlatform )
72+ pool .Set (compute .Platform .AWS )
73+ allErrs = append (allErrs , validateMachinePool (ctx , meta , fldPath .Child ("platform" , "aws" ), config .Platform .AWS , pool , computeReq , compute .Name , arch )... )
6874 }
6975 return allErrs .ToAggregate ()
7076}
@@ -83,7 +89,7 @@ func validatePlatform(ctx context.Context, meta *Metadata, fldPath *field.Path,
8389 allErrs = append (allErrs , validateSubnets (ctx , meta , fldPath .Child ("subnets" ), platform .Subnets , networking , publish )... )
8490 }
8591 if platform .DefaultMachinePlatform != nil {
86- allErrs = append (allErrs , validateMachinePool (ctx , meta , fldPath .Child ("defaultMachinePlatform" ), platform , platform .DefaultMachinePlatform , controlPlaneReq , "" )... )
92+ allErrs = append (allErrs , validateMachinePool (ctx , meta , fldPath .Child ("defaultMachinePlatform" ), platform , platform .DefaultMachinePlatform , controlPlaneReq , "" , "" )... )
8793 }
8894 return allErrs
8995}
@@ -195,7 +201,7 @@ func validateSubnets(ctx context.Context, meta *Metadata, fldPath *field.Path, s
195201 return allErrs
196202}
197203
198- func validateMachinePool (ctx context.Context , meta * Metadata , fldPath * field.Path , platform * awstypes.Platform , pool * awstypes.MachinePool , req resourceRequirements , poolName string ) field.ErrorList {
204+ func validateMachinePool (ctx context.Context , meta * Metadata , fldPath * field.Path , platform * awstypes.Platform , pool * awstypes.MachinePool , req resourceRequirements , poolName string , arch string ) field.ErrorList {
199205 var err error
200206 allErrs := field.ErrorList {}
201207
@@ -279,6 +285,12 @@ func validateMachinePool(ctx context.Context, meta *Metadata, fldPath *field.Pat
279285 errMsg := fmt .Sprintf ("instance type does not meet minimum resource requirements of %d MiB Memory" , req .minimumMemory )
280286 allErrs = append (allErrs , field .Invalid (fldPath .Child ("type" ), pool .InstanceType , errMsg ))
281287 }
288+ instanceArches := translateEC2Arches (typeMeta .Arches )
289+ // `arch` might not be specified (e.g, defaultMachinePool)
290+ if len (arch ) > 0 && ! instanceArches .Has (arch ) {
291+ errMsg := fmt .Sprintf ("instance type supported architectures %s do not match specified architecture %s" , sets .List (instanceArches ), arch )
292+ allErrs = append (allErrs , field .Invalid (fldPath .Child ("type" ), pool .InstanceType , errMsg ))
293+ }
282294 } else {
283295 errMsg := fmt .Sprintf ("instance type %s not found" , pool .InstanceType )
284296 allErrs = append (allErrs , field .Invalid (fldPath .Child ("type" ), pool .InstanceType , errMsg ))
@@ -292,6 +304,21 @@ func validateMachinePool(ctx context.Context, meta *Metadata, fldPath *field.Pat
292304 return allErrs
293305}
294306
307+ func translateEC2Arches (arches []string ) sets.Set [string ] {
308+ res := sets .New [string ]()
309+ for _ , arch := range arches {
310+ switch arch {
311+ case ec2 .ArchitectureTypeX8664 :
312+ res .Insert (types .ArchitectureAMD64 )
313+ case ec2 .ArchitectureTypeArm64 :
314+ res .Insert (types .ArchitectureARM64 )
315+ default :
316+ continue
317+ }
318+ }
319+ return res
320+ }
321+
295322func validateSecurityGroupIDs (ctx context.Context , meta * Metadata , fldPath * field.Path , platform * awstypes.Platform , pool * awstypes.MachinePool ) field.ErrorList {
296323 allErrs := field.ErrorList {}
297324
0 commit comments