Last active
December 22, 2023 13:56
-
-
Save orimanabu/c034309bd55eeb5636d98ef981497401 to your computer and use it in GitHub Desktop.
rosa-util.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
profile=blank | |
install_mode=hcp | |
cluster_name=hcp | |
#install_mode=classic | |
#cluster_name=classic | |
if [ x"$#" != x"1" ]; then | |
echo "$0 step" | |
exit 1 | |
fi | |
step=$1; shift | |
extra_options="" | |
case ${install_mode} in | |
hcp|hosted*) | |
extra_options="--hosted-cp" | |
;; | |
classic) | |
extra_options="" | |
;; | |
*) | |
echo "unknown install_mode: ${install_mode}" | |
exit 1 | |
;; | |
esac | |
case ${step} in | |
step1|1) | |
echo "=> list ocm-role" | |
rosa --profile ${profile} list ocm-role | |
echo "=> create ocm-role" | |
rosa --profile ${profile} create ocm-role --mode auto --yes | |
echo "=> list user-role" | |
rosa --profile ${profile} list user-role | |
echo "=> create user-role" | |
rosa --profile ${profile} create user-role --mode auto --yes | |
;; | |
step2|2) | |
echo "=> create account-roles" | |
echo "* extra_options: ${extra_options}" | |
rosa --profile ${profile} create account-roles --mode auto --yes ${extra_options} | |
;; | |
step3|3) | |
echo "=> create oidc-config" | |
rosa --profile ${profile} create oidc-config --mode auto --yes | |
;; | |
step4|4) | |
oidc_config_id=$(rosa --profile ${profile} list oidc-config -o json | jq -r 'sort_by(.age)[0] | .id') | |
case ${install_mode} in | |
hcp|hosted*) | |
# for hcp | |
installer_role_arn=$(rosa --profile ${profile} list account-roles -o json | jq -r '.[] | select(.ManagedPolicy == true) | select(.RoleType == "Installer") | .RoleARN') | |
;; | |
classic) | |
# for classic | |
installer_role_arn=$(rosa --profile ${profile} list account-roles -o json | jq -r '.[] | select(.ManagedPolicy != true) | select(.RoleType == "Installer") | .RoleARN') | |
;; | |
esac | |
echo "=> create operator-roles" | |
echo "* cluster_name: ${cluster_name}" | |
echo "* oidc_config_id: ${oidc_config_id}" | |
echo "* installer_role_arn: ${installer_role_arn}" | |
echo "* extra_options: ${extra_options}" | |
rosa --profile ${profile} create operator-roles --prefix ${cluster_name} --oidc-config-id ${oidc_config_id} --installer-role-arn ${installer_role_arn} --mode auto --yes ${extra_options} | |
;; | |
step5|5) | |
vpc_id=$(aws --profile ${profile} ec2 describe-vpcs | jq -r '.Vpcs[] | .VpcId') | |
subnet_ids=$(aws --profile ${profile} ec2 describe-subnets | jq -r '.Subnets[] | select(.VpcId == "'${vpc_id}'") | .SubnetId' | tr '\n' ',' | sed -e 's/,$//') | |
oidc_config_id=$(rosa --profile ${profile} list oidc-config -o json | jq -r 'sort_by(.age)[0] | .id') | |
echo "=> create cluster" | |
echo "* cluster_name: ${cluster_name}" | |
echo "* vpc_id: ${vpc_id}" | |
echo "* subnet_ids: ${subnet_ids}" | |
echo "* oidc_config_id: ${oidc_config_id}" | |
echo "* extra_options: ${extra_options}" | |
rosa --profile ${profile} create cluster --cluster-name ${cluster_name} --sts --oidc-config-id ${oidc_config_id} --operator-roles-prefix ${cluster_name} --subnet-ids ${subnet_ids} --mode auto --yes ${extra_options} | |
;; | |
step6|6) | |
rosa --profile ${profile} describe cluster -c ${cluster_name} | |
rosa --profile ${profile} logs install -c ${cluster_name} --watch | |
;; | |
step7|7) | |
password=$(openssl rand -base64 16) | |
echo "=> create admin" | |
echo "* password: ${password}" | |
rosa --profile ${profile} create admin -c ${cluster_name} -p ${password} | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment