Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,49 @@ path: "/usr/local/bin/etcd-member-recover.sh"
contents:
inline: |
#!/usr/bin/env bash

# example
# export SETUP_ETCD_ENVIRONMENT=$(oc adm release info --image-for setup-etcd-environment --registry-config=./config.json)
# export KUBE_CLIENT_AGENT=$(oc adm release info --image-for kube-client-agent --registry-config=./config.json)
# sudo -E ./etcd-member-recover.sh 192.168.1.100

if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi

: ${SETUP_ETCD_ENVIRONMENT:?"Need to set SETUP_ETCD_ENVIRONMENT"}
: ${KUBE_CLIENT_AGENT:?"Need to set KUBE_CLIENT_AGENT"}

usage () {
echo 'Recovery server IP address required: ./etcd-member-recover.sh 192.168.1.100'
exit
}

if [ "$1" == "" ]; then
usage
fi

RECOVERY_SERVER_IP=$1

ASSET_DIR=./assets
ASSET_DIR_TMP="$ASSET_DIR/tmp"
CONFIG_FILE_DIR=/etc/kubernetes
MANIFEST_DIR="${CONFIG_FILE_DIR}/manifests"
MANIFEST_STOPPED_DIR=/etc/kubernetes/manifests-stopped

ETCD_MANIFEST="${MANIFEST_DIR}/etcd-member.yaml"
ETCD_CONFIG=/etc/etcd/etcd.conf
ETCDCTL=$ASSET_DIR/bin/etcdctl
ETCD_VERSION=v3.3.10
ETCD_DATA_DIR=/var/lib/etcd
ETCD_STATIC_RESOURCES="${CONFIG_FILE_DIR}/static-pod-resources/etcd-member"

SHARED=/usr/local/share/openshift-recovery
TEMPLATE="$SHARED/template/etcd-generate-certs.yaml.template"

source "/usr/local/bin/openshift-recovery-tools"

function run {
init
dl_etcdctl
Expand All @@ -58,7 +58,6 @@ contents:
backup_certs
remove_certs
gen_config
download_cert_recover_template
DISCOVERY_DOMAIN=$(grep -oP '(?<=discovery-srv=).*[^"]' $ASSET_DIR/backup/etcd-member.yaml )
if [ -z "$DISCOVERY_DOMAIN" ]; then
echo "Discovery domain can not be extracted from $ASSET_DIR/backup/etcd-member.yaml"
Expand All @@ -75,5 +74,5 @@ contents:
etcd_member_add
start_etcd
}

run
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,13 @@ contents:
HOSTNAME=$(hostname)
HOSTDOMAIN=$(hostname -d)
ETCD_NAME=etcd-member-${HOSTNAME}.${HOSTDOMAIN}

source /run/etcd/environment

if [ -z "${ETCD_CONNSTRING}" ]; then
ETCD_CONNSTRING="${ETCD_NAME}=https://${ETCD_DNS_NAME}:2380"
fi

source /run/etcd/environment

if [ ! -f "$SNAPSHOT_FILE" ]; then
echo "Snapshot file not found, restore failed: $SNAPSHOT_FILE."
exit 1
Expand Down Expand Up @@ -231,10 +232,6 @@ contents:
mv ${MANIFEST_STOPPED_DIR}/etcd-member.yaml $MANIFEST_DIR
}

download_cert_recover_template() {
curl -s https://raw.githubusercontent.com/hexfusion/openshift-recovery/master/manifests/etcd-generate-certs.yaml.template -o $ASSET_DIR/templates/etcd-generate-certs.yaml.template
}

populate_template() {
FIND="$1"
REPLACE="$2"
Expand Down