@@ -74,6 +74,7 @@ func TestValidate(t *testing.T) {
7474 subnetsInVPC * SubnetGroups
7575 vpcTags Tags
7676 instanceTypes map [string ]InstanceType
77+ hosts map [string ]Host
7778 proxy string
7879 publicOnly bool
7980 expectErr string
@@ -1200,6 +1201,57 @@ func TestValidate(t *testing.T) {
12001201 },
12011202 expectErr : `^\Qplatform.aws.vpc.subnets: Forbidden: subnet subnet-valid-public-a1 is owned by other clusters [another-cluster] and cannot be used for new installations, another subnet must be created separately\E$` ,
12021203 },
1204+ {
1205+ name : "valid dedicated host placement on compute" ,
1206+ installConfig : icBuild .build (
1207+ icBuild .withComputePlatformZones ([]string {"a" }, true , 0 ),
1208+ icBuild .withComputeHostPlacement ([]string {"h-1234567890abcdef0" }, 0 ),
1209+ ),
1210+ availRegions : validAvailRegions (),
1211+ availZones : validAvailZones (),
1212+ hosts : map [string ]Host {
1213+ "h-1234567890abcdef0" : {ID : "h-1234567890abcdef0" , Zone : "a" },
1214+ },
1215+ },
1216+ {
1217+ name : "invalid dedicated host not found" ,
1218+ installConfig : icBuild .build (
1219+ icBuild .withComputePlatformZones ([]string {"a" }, true , 0 ),
1220+ icBuild .withComputeHostPlacement ([]string {"h-aaaaaaaaaaaaaaaaa" }, 0 ),
1221+ ),
1222+ availRegions : validAvailRegions (),
1223+ availZones : validAvailZones (),
1224+ hosts : map [string ]Host {
1225+ "h-1234567890abcdef0" : {ID : "h-1234567890abcdef0" , Zone : "a" },
1226+ },
1227+ expectErr : "dedicated host h-aaaaaaaaaaaaaaaaa not found" ,
1228+ },
1229+ {
1230+ name : "invalid dedicated host zone not in pool zones" ,
1231+ installConfig : icBuild .build (
1232+ icBuild .withComputePlatformZones ([]string {"a" }, true , 0 ),
1233+ icBuild .withComputeHostPlacement ([]string {"h-bbbbbbbbbbbbbbbbb" }, 0 ),
1234+ ),
1235+ availRegions : validAvailRegions (),
1236+ availZones : validAvailZones (),
1237+ hosts : map [string ]Host {
1238+ "h-bbbbbbbbbbbbbbbbb" : {ID : "h-bbbbbbbbbbbbbbbbb" , Zone : "b" },
1239+ },
1240+ expectErr : "is not available in pool's zone list" ,
1241+ },
1242+ {
1243+ name : "dedicated host placement on compute but for a zone that pool is not using" ,
1244+ installConfig : icBuild .build (
1245+ icBuild .withComputePlatformZones ([]string {"b" }, true , 0 ),
1246+ icBuild .withComputeHostPlacementAndZone ([]string {"h-1234567890abcdef0" }, "b" , 0 ),
1247+ ),
1248+ availRegions : validAvailRegions (),
1249+ availZones : validAvailZones (),
1250+ hosts : map [string ]Host {
1251+ "h-1234567890abcdef0" : {ID : "h-1234567890abcdef0" , Zone : "a" },
1252+ },
1253+ expectErr : "dedicated host was configured with zone b but expected zone a" ,
1254+ },
12031255 }
12041256
12051257 // Register mock http(s) responses for tests.
@@ -1232,6 +1284,7 @@ func TestValidate(t *testing.T) {
12321284 Tags : test .vpcTags ,
12331285 },
12341286 instanceTypes : test .instanceTypes ,
1287+ Hosts : test .hosts ,
12351288 ProvidedSubnets : test .installConfig .Platform .AWS .VPC .Subnets ,
12361289 }
12371290
@@ -1952,6 +2005,34 @@ func (icBuild icBuildForAWS) withComputePlatformZones(zones []string, overwrite
19522005 }
19532006}
19542007
2008+ func (icBuild icBuildForAWS ) withComputeHostPlacement (hostIDs []string , index int ) icOption {
2009+ return func (ic * types.InstallConfig ) {
2010+ aff := aws .HostAffinityDedicatedHost
2011+ dhs := make ([]aws.DedicatedHost , 0 , len (hostIDs ))
2012+ for _ , id := range hostIDs {
2013+ dhs = append (dhs , aws.DedicatedHost {ID : id })
2014+ }
2015+ ic .Compute [index ].Platform .AWS .HostPlacement = & aws.HostPlacement {
2016+ Affinity : & aff ,
2017+ DedicatedHost : dhs ,
2018+ }
2019+ }
2020+ }
2021+
2022+ func (icBuild icBuildForAWS ) withComputeHostPlacementAndZone (hostIDs []string , zone string , index int ) icOption {
2023+ return func (ic * types.InstallConfig ) {
2024+ aff := aws .HostAffinityDedicatedHost
2025+ dhs := make ([]aws.DedicatedHost , 0 , len (hostIDs ))
2026+ for _ , id := range hostIDs {
2027+ dhs = append (dhs , aws.DedicatedHost {ID : id , Zone : zone })
2028+ }
2029+ ic .Compute [index ].Platform .AWS .HostPlacement = & aws.HostPlacement {
2030+ Affinity : & aff ,
2031+ DedicatedHost : dhs ,
2032+ }
2033+ }
2034+ }
2035+
19552036func (icBuild icBuildForAWS ) withControlPlanePlatformAMI (amiID string ) icOption {
19562037 return func (ic * types.InstallConfig ) {
19572038 ic .ControlPlane .Platform .AWS .AMIID = amiID
0 commit comments