@@ -386,3 +386,50 @@ platform:
386386EOF
387387 yq-go m -a -x -i " ${CONFIG} " " ${patch_user_provisioned_dns} "
388388fi
389+
390+ # Add config for dedicated hosts to compute nodes if job is configured
391+ if [[ " ${DEDICATED_HOST} " == " yes" ]]; then
392+ echo " Detected dedicated host configured. Starting install-config patching."
393+ patch_dedicated_host=" ${SHARED_DIR} /install-config-dedicated-host.yaml.patch"
394+
395+ # Create Host for each zone. If no zones configured, error out. Zones can exist before script execution so we'll pull zone listing out for workers.
396+ WORKER_ZONES=$( cat " ${CONFIG} " | yq-v4 ' .compute[] | select(.name == "worker") | .platform.aws.zones' [] )
397+ if [[ " ${WORKER_ZONES} " == " " ]]; then
398+ echo " No zones configured, Unable to determine where to create dedicated hosts."
399+ exit
400+ fi
401+
402+ cat > " ${patch_dedicated_host} " << EOF
403+ compute:
404+ - name: worker
405+ platform:
406+ aws:
407+ dedicatedHosts:
408+ hostAffinity: Host
409+ hosts: []
410+ EOF
411+
412+ for zone in ${WORKER_ZONES} ; do
413+ HOST_TYPE=$( echo " ${COMPUTE_NODE_TYPE} " | cut -d' .' -f1)
414+ echo " Creating dedicated host. Region='${aws_source_region} ' Zone='${zone} ' InstanceFamily='${HOST_TYPE} '"
415+
416+ EXPIRATION_DATE=$( date -d ' 6 hours' --iso=minutes --utc)
417+ HOST_SPECS=' {"ResourceType":"dedicated-host","Tags":[{"Key":"Name","Value":"' ${JOB_NAME_SAFE} ' -' ${zone} ' "},{"Key":"CI-JOB","Value":"' ${JOB_NAME_SAFE} ' "},{"Key":"expirationDate","Value":"' ${EXPIRATION_DATE} ' "},{"Key":"ci-build-info","Value":"' ${BUILD_ID} _${JOB_NAME} ' "}]}'
418+ HOST_ID=$( aws ec2 allocate-hosts --instance-type " ${HOST_TYPE} .4xlarge" --auto-placement ' off' --host-recovery ' off' --tag-specifications " ${HOST_SPECS} " --host-maintenance ' off' --quantity ' 1' --availability-zone " ${zone} " --region " ${aws_source_region} " | jq -r ' .HostIds[0]' )
419+
420+ # We need to pass in the vars since YQ doesnt see the loop variables
421+ ZONE_NAME=" ${zone} " HOST_ID=" ${HOST_ID} " yq-v4 -i ' .compute[] |= (select(.name == "worker") | .platform.aws.dedicatedHosts.hosts += [ { "id": strenv(HOST_ID), "zone": strenv(ZONE_NAME) } ])' " ${patch_dedicated_host} "
422+ done
423+
424+ # Update config with host ID
425+ echo " Patching install-config.yaml for dedicated hosts."
426+ # idPath=".name" originalPath=".compute" otherPath=".compute" yq-v4 eval-all -i '
427+ # (
428+ # (( (eval(strenv(originalPath)) + eval(strenv(otherPath))) | .[] | {(eval(strenv(idPath))): .}) as $item ireduce ({}; . * $item )) as $uniqueMap
429+ # | ( $uniqueMap | to_entries | .[]) as $item ireduce([]; . + $item.value)
430+ # ) as $mergedArray
431+ # | select(fi == 0) | (eval(strenv(originalPath))) = $mergedArray
432+ # ' ${CONFIG} ${patch_dedicated_host}
433+ yq-go m -x -i ${CONFIG} ${patch_dedicated_host}
434+ cp " ${patch_dedicated_host} " " ${ARTIFACT_DIR} /"
435+ fi
0 commit comments