Skip to content

Commit b9a39e1

Browse files
committed
Added provision/deprovision logic for dedicated hosts
1 parent fdbf3c2 commit b9a39e1

File tree

6 files changed

+98
-0
lines changed

6 files changed

+98
-0
lines changed

ci-operator/step-registry/ipi/conf/aws/ipi-conf-aws-commands.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,50 @@ platform:
386386
EOF
387387
yq-go m -a -x -i "${CONFIG}" "${patch_user_provisioned_dns}"
388388
fi
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

ci-operator/step-registry/ipi/conf/aws/ipi-conf-aws-ref.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,10 @@ ref:
106106
documentation: |-
107107
Experimental feature allowing jobs to use NAT instances instead of NAT gateways, in certain accounts, for cost
108108
reduction purposes.
109+
- name: DEDICATED_HOST
110+
default: "no"
111+
documentation: |-
112+
Allows users to enable configuration of dedicated hosts for compute nodes. Valid options are "yes" and "no". When "yes", the
113+
configuration will create a dedicated host for each zone the "worker" compute pool has configured.
109114
documentation: |-
110115
The IPI AWS configure step generates the AWS-specific install-config.yaml contents based on the cluster profile and optional input files.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../OWNERS
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
set -o nounset
3+
set -o errexit
4+
set -o pipefail
5+
6+
export AWS_SHARED_CREDENTIALS_FILE="${CLUSTER_PROFILE_DIR}/.awscred"
7+
CONFIG="${SHARED_DIR}/install-config.yaml"
8+
patch_dedicated_host="${SHARED_DIR}/install-config-dedicated-host.yaml.patch"
9+
10+
if test ! -f "${patch_dedicated_host}"
11+
then
12+
echo "No dedicated hosts patch file found, so assuming patch never occurred."
13+
exit 0
14+
fi
15+
16+
echo "Deprovisioning dedicated hosts..."
17+
18+
# We get the region information from the install-config.yaml. For the dedicated hosts, we are pulling from the patch file in
19+
# the event that an error occurred during creation of the dedicated host.
20+
REGION=$(yq-v4 -r '.platform.aws.region' ${CONFIG})
21+
for HOST in $(yq-v4 -r '.compute[] | select(.name == "worker") | .platform.aws.dedicatedHosts.hosts[] | .id' "${patch_dedicated_host}"); do
22+
echo "Release host ${HOST}"
23+
aws ec2 release-hosts --region "${REGION}" --host-ids "${HOST}"
24+
done
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"path": "ipi/deprovision/aws/dedicated-hosts/ipi-deprovision-aws-dedicated-hosts-ref.yaml",
3+
"owners": {
4+
"approvers": [
5+
"jhixson74",
6+
"patrickdillon",
7+
"barbacbd"
8+
]
9+
}
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
ref:
2+
as: ipi-deprovision-aws-dedicated-hosts
3+
from: upi-installer
4+
grace_period: 10m
5+
commands: ipi-deprovision-aws-dedicated-hosts-commands.sh
6+
resources:
7+
requests:
8+
cpu: 300m
9+
memory: 300Mi
10+
documentation: |-
11+
This deprovision step tears down any dedicated hosts that were provisioned for AWS IPI dedicated host feature.

0 commit comments

Comments
 (0)