Skip to content

Instantly share code, notes, and snippets.

@rcarrata
Created August 5, 2020 18:26
Show Gist options
  • Save rcarrata/af176e1a464a511e716e91ce3bacf348 to your computer and use it in GitHub Desktop.
Save rcarrata/af176e1a464a511e716e91ce3bacf348 to your computer and use it in GitHub Desktop.
Machineset for create bare metal nodes in AWS
#!/usr/bin/env bash
export REGION="eu-west-1"
export AZS="${REGION}a ${REGION}b ${REGION}c"
export FLAVOR="m5.metal"
MACHINESET_PREFIX=$(oc get machineset -n openshift-machine-api -o json| jq '.items[0].metadata.labels."machine.openshift.io/cluster-api-cluster"' | tr -d '""')
for AZ in ${AZS}; do
export NAME="${MACHINESET_PREFIX}-metal-${AZ}"
export AZ=$AZ
export SUBNET=${MACHINESET_PREFIX}-private-${AZ}
echo " ** Generating JSON for Infra node $NAME (AZ: ${AZ})"
oc get machineset -n openshift-machine-api -o json\
| jq '.items[0]' \
| jq '.metadata.name=env["NAME"]'\
| jq '.metadata.selfLink=""'\
| jq '.metadata.uid=""'\
| jq '.spec.selector.matchLabels."machine.openshift.io/cluster-api-machineset"=env["NAME"]'\
| jq '.spec.template.metadata.labels."machine.openshift.io/cluster-api-machineset"=env["NAME"]'\
| jq '.spec.template.spec.providerSpec.value.placement.availabilityZone=env["AZ"]'\
| jq '.spec.template.spec.providerSpec.value.placement.region=env["REGION"]'\
| jq '.spec.template.spec.metadata.labels."node-role.kubernetes.io/worker"=""'\
| jq '.spec.template.spec.providerSpec.value.subnet.filters[0].values[0]=env["SUBNET"]' \
| jq 'del (.metadata.annotations)' \
| jq '.spec.template.spec.providerSpec.value.instanceType=env["FLAVOR"]' \
> ./metal-machineset-$NAME.json
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment