Skip to content

Commit 6eb87d2

Browse files
committed
OCPBUGS-24575: ic: aws: validate instance architecture
Check during install-config validation that node architecture and VM type are consistent.
1 parent 09ff70e commit 6eb87d2

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

pkg/asset/installconfig/aws/validation.go

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
295322
func validateSecurityGroupIDs(ctx context.Context, meta *Metadata, fldPath *field.Path, platform *awstypes.Platform, pool *awstypes.MachinePool) field.ErrorList {
296323
allErrs := field.ErrorList{}
297324

pkg/asset/installconfig/aws/validation_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"sort"
88
"testing"
99

10+
"github.com/aws/aws-sdk-go/service/ec2"
1011
"github.com/aws/aws-sdk-go/service/route53"
1112
"github.com/golang/mock/gomock"
1213
"github.com/stretchr/testify/assert"
@@ -210,14 +211,17 @@ func validInstanceTypes() map[string]InstanceType {
210211
"t2.small": {
211212
DefaultVCpus: 1,
212213
MemInMiB: 2048,
214+
Arches: []string{ec2.ArchitectureTypeX8664},
213215
},
214216
"m5.large": {
215217
DefaultVCpus: 2,
216218
MemInMiB: 8192,
219+
Arches: []string{ec2.ArchitectureTypeX8664},
217220
},
218221
"m5.xlarge": {
219222
DefaultVCpus: 4,
220223
MemInMiB: 16384,
224+
Arches: []string{ec2.ArchitectureTypeX8664},
221225
},
222226
}
223227
}
@@ -566,7 +570,7 @@ func TestValidate(t *testing.T) {
566570
ic.Compute = []types.MachinePool{edgePool}
567571
return ic
568572
}(),
569-
expectErr: `^compute\[0\]\.platform\.aws: Required value: edge compute pools are only supported on the AWS platform$`,
573+
expectErr: `^\[compute\[0\]\.platform\.aws: Required value: edge compute pools are only supported on the AWS platform, compute\[0\].platform.aws: Required value: zone is required when using edge machine pools\]$`,
570574
}, {
571575
name: "invalid edge pool missing subnets on availability zones",
572576
installConfig: func() *types.InstallConfig {

0 commit comments

Comments
 (0)