2020-05-13 15:13:05 +03:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
# ssh-agent.sh is intended to behave very similarly to ssh: specify the master or
|
|
|
|
# worker hostname that you want to connect to, along with any other ssh options
|
|
|
|
# you want to pass in
|
|
|
|
|
|
|
|
usage() {
|
2020-11-06 20:52:12 +03:00
|
|
|
echo "usage: CLUSTER=cluster $0 hostname_pattern" >&2
|
|
|
|
echo " Examples: CLUSTER=cluster $0 master1" >&2
|
Ssh docs/examples , PR template update (#1446)
* Fix -> remove the dash, valid names are master0,master1,master2, but not master-0,master-1,master-2
* Add more information, show example with nodes, show multiple ways to ssh to a worker node
* Change VSTS to ADO because that is the tool we use now
* Add an additional example of connecting to a worker
* respected->respective, english is hard
2021-04-19 13:36:36 +03:00
|
|
|
echo " CLUSTER=cluster $0 eastus1 # worker node 1" >&2
|
2020-11-06 20:52:12 +03:00
|
|
|
echo " CLUSTER=cluster $0 bootstrap" >&2
|
2020-05-13 15:13:05 +03:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2020-06-25 16:40:26 +03:00
|
|
|
if [[ "$#" -ne 1 ]]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
2020-05-13 15:13:05 +03:00
|
|
|
cleanup() {
|
|
|
|
rm -rf id_rsa
|
|
|
|
}
|
|
|
|
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
|
eval "$(ssh-agent | grep -v '^echo ')"
|
|
|
|
|
|
|
|
if [[ -z "$RESOURCEID" ]]; then
|
2021-04-16 14:01:51 +03:00
|
|
|
if [[ -z "$CLUSTER" ]]; then
|
|
|
|
echo "CLUSTER must be specified"
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
2020-05-13 15:13:05 +03:00
|
|
|
RESOURCEID="/subscriptions/${AZURE_SUBSCRIPTION_ID}/resourceGroups/${RESOURCEGROUP}/providers/Microsoft.RedHatOpenShift/openShiftClusters/${CLUSTER}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
CLUSTER_RESOURCEGROUP=$(go run ./hack/db "$RESOURCEID" | jq -r .openShiftCluster.properties.clusterProfile.resourceGroupId | cut -d/ -f5)
|
|
|
|
|
|
|
|
go run ./hack/db "$RESOURCEID" | jq -r .openShiftCluster.properties.sshKey | base64 -d | openssl rsa -inform der -outform pem >id_rsa 2>/dev/null
|
|
|
|
chmod 0600 id_rsa
|
|
|
|
|
2021-03-19 22:01:12 +03:00
|
|
|
# seeing ARM cache issues with -g $CLUSTER_RESOURCEGROUP, so using --query
|
2023-04-14 22:55:23 +03:00
|
|
|
IP=$(az network nic list --query "[?resourceGroup == '$CLUSTER_RESOURCEGROUP' && contains(name, '$1')].ipConfigurations[0].privateIPAddress" -o tsv)
|
2020-05-13 15:13:05 +03:00
|
|
|
|
|
|
|
if [[ $(grep -c . <<<"$IP") -ne 1 ]]; then
|
|
|
|
echo -e "VM with pattern $1 not found in resourceGroup $CLUSTER_RESOURCEGROUP\n"
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i id_rsa -l core "$IP"
|