Last active
March 18, 2020 13:37
-
-
Save praveenkumar/5d6803ee38783dac5178eea3e1283324 to your computer and use it in GitHub Desktop.
Debugging etcd issue.
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 | |
set -euo pipefail | |
export LC_ALL=C | |
export LANG=C | |
INSTALL_DIR=crc-tmp-install-data | |
JQ=${JQ:-jq} | |
OC=${OC:-oc} | |
YQ=${YQ:-yq} | |
OPENSHIFT_INSTALL=${OPENSHIFT_INSTALL:-./openshift-install} | |
CRC_VM_NAME=${CRC_VM_NAME:-crc} | |
BASE_DOMAIN=${CRC_BASE_DOMAIN:-testing} | |
MIRROR=${MIRROR:-https://mirror.openshift.com/pub/openshift-v4/clients/ocp} | |
SSH="ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i id_rsa_crc" | |
# Download the oc binary if not present in current directory | |
if ! which $OC; then | |
if [[ ! -e oc ]] ; then | |
curl -L "${MIRROR}/latest/openshift-client-linux-${OPENSHIFT_RELEASE_VERSION}.tar.gz" | tar zx oc | |
fi | |
OC=./oc | |
fi | |
# Download yq for manipulating in place yaml configs | |
if ! which $YQ; then | |
if [[ ! -e yq ]]; then | |
curl -L https://github.com/mikefarah/yq/releases/download/2.2.1/yq_linux_amd64 -o yq | |
chmod +x yq | |
fi | |
YQ=./yq | |
fi | |
if ! which ${JQ}; then | |
sudo yum -y install /usr/bin/jq | |
fi | |
if [ "${OPENSHIFT_PULL_SECRET}" = "" ]; then | |
echo "OpenShift pull secret must be specified through the OPENSHIFT_PULL_SECRET environment variable" | |
exit 1 | |
fi | |
if [ "${OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE}" = "" ]; then | |
echo "OpenShift image override must be specified through the OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE environment variable" | |
exit 1 | |
fi | |
export OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE | |
echo "Setting OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE to ${OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE}" | |
# Extract openshift-install binary if not present in current direcory | |
if ! which $OPENSHIFT_INSTALL; then | |
echo "Extracting installer binary from OpenShift baremetal-installer image" | |
echo ${OPENSHIFT_PULL_SECRET} > pull-secret | |
baremetal_installer_image=$(oc adm release -a pull-secret info ${OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE} --image-for=baremetal-installer) | |
oc image -a pull-secret extract ${baremetal_installer_image} --confirm --path /usr/bin/openshift-install:. | |
chmod +x openshift-install | |
rm pull-secret | |
OPENSHIFT_INSTALL=./openshift-install | |
fi | |
# Destroy an existing cluster and resources | |
${OPENSHIFT_INSTALL} --dir $INSTALL_DIR destroy cluster --log-level debug || echo "failed to destroy previous cluster. Continuing anyway" | |
# Generate a new ssh keypair for this cluster | |
rm id_rsa_crc* || true | |
ssh-keygen -N "" -f id_rsa_crc -C "core" | |
# Set NetworkManager DNS overlay file | |
cat << EOF | sudo tee /etc/NetworkManager/dnsmasq.d/openshift.conf | |
server=/${CRC_VM_NAME}.${BASE_DOMAIN}/192.168.126.1 | |
address=/apps-${CRC_VM_NAME}.${BASE_DOMAIN}/192.168.126.11 | |
EOF | |
# Set dnsmasq for NetworkManager | |
cat << EOF | sudo tee /etc/NetworkManager/conf.d/openshift.conf | |
[main] | |
dns=dnsmasq | |
EOF | |
# Reload the NetworkManager to make DNS overlay effective | |
sudo systemctl reload NetworkManager | |
# Create the INSTALL_DIR for the installer and copy the install-config | |
rm -fr $INSTALL_DIR && mkdir $INSTALL_DIR && cp install-config.yaml $INSTALL_DIR | |
${YQ} write --inplace $INSTALL_DIR/install-config.yaml baseDomain $BASE_DOMAIN | |
${YQ} write --inplace $INSTALL_DIR/install-config.yaml metadata.name $CRC_VM_NAME | |
${YQ} write --inplace $INSTALL_DIR/install-config.yaml compute[0].replicas 0 | |
${YQ} write --inplace $INSTALL_DIR/install-config.yaml pullSecret "${OPENSHIFT_PULL_SECRET}" | |
${YQ} write --inplace $INSTALL_DIR/install-config.yaml sshKey "$(cat id_rsa_crc.pub)" | |
# Create the manifests using the INSTALL_DIR | |
${OPENSHIFT_INSTALL} --dir $INSTALL_DIR create manifests || exit 1 | |
# Add custom domain to cluster-ingress | |
${YQ} write --inplace $INSTALL_DIR/manifests/cluster-ingress-02-config.yml spec[domain] apps-${CRC_VM_NAME}.${BASE_DOMAIN} | |
# Add master memory to 12 GB and 6 cpus | |
# This is only valid for openshift 4.3 onwards | |
${YQ} write --inplace $INSTALL_DIR/openshift/99_openshift-cluster-api_master-machines-0.yaml spec.providerSpec.value[domainMemory] 15288 | |
${YQ} write --inplace $INSTALL_DIR/openshift/99_openshift-cluster-api_master-machines-0.yaml spec.providerSpec.value[domainVcpu] 6 | |
# Add codeReadyContainer as invoker to identify it with telemeter | |
export OPENSHIFT_INSTALL_INVOKER="codeReadyContainers" | |
${OPENSHIFT_INSTALL} --dir $INSTALL_DIR create cluster --log-level debug | |
# Set the VM static hostname to crc-xxxxx-master-0 instead of localhost.localdomain | |
HOSTNAME=$(${SSH} core@api.${CRC_VM_NAME}.${BASE_DOMAIN} hostnamectl status --transient) | |
${SSH} core@api.${CRC_VM_NAME}.${BASE_DOMAIN} sudo hostnamectl set-hostname ${HOSTNAME} |
Author
praveenkumar
commented
Mar 13, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment