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
35 changes: 23 additions & 12 deletions scripts/dev/evg_host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,24 @@ kubeconfig_path="${HOME}/.operator-dev/evg-host.kubeconfig"

configure() {
shift 1
arch=${1-"amd64"}
auto_recreate="false"

# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--auto-recreate)
auto_recreate="true"
shift
;;
*)
echo "Unknown argument: $1"
echo "Usage: configure [--auto-recreate]"
exit 1
;;
esac
done

echo "Configuring EVG host ${EVG_HOST_NAME} (${host_url}) with architecture ${arch}"

if [[ "${cmd}" == "configure" && "${arch}" != "amd64" && "${arch}" != "arm64" ]]; then
echo "'configure' command supports the following architectures: 'amd64', 'arm64'"
exit 1
fi
echo "Configuring EVG host ${EVG_HOST_NAME} (${host_url}) (auto_recreate: ${auto_recreate})"

ssh -T -q "${host_url}" "sudo chown ubuntu:ubuntu ~/.docker || true; mkdir -p ~/.docker"
if [[ -f "${HOME}/.docker/config.json" ]]; then
Expand All @@ -56,7 +66,7 @@ configure() {

sync

ssh -T -q "${host_url}" "cd ~/mongodb-kubernetes; scripts/dev/switch_context.sh root-context; scripts/dev/setup_evg_host.sh ${arch}"
ssh -T -q "${host_url}" "cd ~/mongodb-kubernetes; scripts/dev/switch_context.sh root-context; scripts/dev/setup_evg_host.sh ${auto_recreate}"
}

sync() {
Expand Down Expand Up @@ -100,7 +110,7 @@ get-kubeconfig() {

recreate-kind-clusters() {
DELETE_KIND_NETWORK=${DELETE_KIND_NETWORK:-"false"}
configure "${1-"amd64"}" 2>&1| prepend "evg_host.sh configure"
configure 2>&1| prepend "evg_host.sh configure"
echo "Recreating kind clusters on ${EVG_HOST_NAME} (${host_url})..."
# shellcheck disable=SC2088
ssh -T "${host_url}" "cd ~/mongodb-kubernetes; DELETE_KIND_NETWORK=${DELETE_KIND_NETWORK} scripts/dev/recreate_kind_clusters.sh"
Expand All @@ -111,7 +121,7 @@ recreate-kind-clusters() {
recreate-kind-cluster() {
shift 1
cluster_name=$1
configure "${1-"amd64"}" 2>&1| prepend "evg_host.sh configure"
configure 2>&1| prepend "evg_host.sh configure"
echo "Recreating kind cluster ${cluster_name} on ${EVG_HOST_NAME} (${host_url})..."
# shellcheck disable=SC2088
ssh -T "${host_url}" "cd ~/mongodb-kubernetes; scripts/dev/recreate_kind_cluster.sh ${cluster_name}"
Expand All @@ -121,6 +131,7 @@ recreate-kind-cluster() {

tunnel() {
shift 1
get-kubeconfig
# shellcheck disable=SC2016
api_servers=$(yq '.contexts[].context.cluster as $cluster | .clusters[] | select(.name == $cluster).cluster.server' < "${kubeconfig_path}" | sed 's/https:\/\///g')
echo "Extracted the following API server urls from ${kubeconfig_path}: ${api_servers}"
Expand Down Expand Up @@ -187,7 +198,7 @@ PREREQUISITES:

COMMANDS:
recreate-kind-clusters all-you-need to configure host and kind clusters; deletes and recreates all kind clusters (for single and multi runs)
configure <architecture> installs on a host: calls sync, switches context, installs necessary software
configure [--auto-recreate] installs on a host: calls sync, switches context, installs necessary software
sync rsync of project directory
recreate-kind-cluster test-cluster executes scripts/dev/recreate_kind_cluster.sh test-cluster and executes get-kubeconfig
remote-prepare-local-e2e-run executes prepare-local-e2e on the remote evg host
Expand All @@ -202,7 +213,7 @@ COMMANDS:

case ${cmd} in
configure) configure "$@" ;;
recreate-kind-clusters) recreate-kind-clusters "${1-"amd64"}";;
recreate-kind-clusters) recreate-kind-clusters "$@" ;;
recreate-kind-cluster) recreate-kind-cluster "$@" ;;
get-kubeconfig) get-kubeconfig ;;
remote-prepare-local-e2e-run) remote-prepare-local-e2e-run ;;
Expand Down
14 changes: 14 additions & 0 deletions scripts/dev/kindclusters.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Recreate kind clusters at boot
After=docker.service
Requires=docker.service

[Service]
Type=oneshot
WorkingDirectory=/home/ubuntu/mongodb-kubernetes
Environment=HOME=/home/ubuntu
ExecStart=/home/ubuntu/mongodb-kubernetes/scripts/dev/recreate_kind_clusters.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
29 changes: 23 additions & 6 deletions scripts/dev/setup_evg_host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

set -Eeou pipefail

source scripts/funcs/install

set_limits() {
echo "Increasing fs.inotify.max_user_instances"
sudo sysctl -w fs.inotify.max_user_instances=8192
Expand All @@ -26,16 +28,26 @@ set_limits() {
EOF
}

# retrieve arch variable off the shell command line
ARCH=${1-"amd64"}
set_auto_recreate() {
echo "Creating systemd service for recreating kind clusters on reboot"

sudo cp /home/ubuntu/mongodb-kubernetes/scripts/dev/kindclusters.service /etc/systemd/system/kindclusters.service
sudo systemctl enable kindclusters.service
}

# Detect architecture from the environment
ARCH=$(detect_architecture)
echo "Detected architecture: ${ARCH}"

download_kind() {
scripts/evergreen/setup_kind.sh /usr/local
}

download_curl() {
echo "Downloading curl..."
curl -s -o kubectl -L https://dl.k8s.io/release/"$(curl -L -s https://dl.k8s.io/release/stable.txt)"/bin/linux/"${ARCH}"/kubectl
download_kubectl() {
kubectl_version=$(curl --retry 5 -Ls https://dl.k8s.io/release/stable.txt)
echo "Downloading kubectl ${kubectl_version}..."

curl --retry 5 -LOs "https://dl.k8s.io/release/${kubectl_version}/bin/linux/${ARCH}/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/kubectl
}
Expand All @@ -51,7 +63,12 @@ download_helm() {

set_limits
download_kind &
download_curl &
download_kubectl &
download_helm &

AUTO_RECREATE=${1:-false}
if [[ "${AUTO_RECREATE}" == "true" ]]; then
set_auto_recreate &
fi

wait
2 changes: 1 addition & 1 deletion scripts/evergreen/setup_kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ latest_version="v0.29.0"
if [[ "${arch_suffix}" == "amd64" || "${arch_suffix}" == "arm64" ]]; then
mkdir -p "${PROJECT_DIR}/bin/"
echo "Saving kind to ${PROJECT_DIR}/bin"
curl --retry 3 --silent -L "https://github.com/kubernetes-sigs/kind/releases/download/${latest_version}/kind-${os}-${arch_suffix}" -o kind
curl --retry 5 -L "https://github.com/kubernetes-sigs/kind/releases/download/${latest_version}/kind-${os}-${arch_suffix}" -o kind

chmod +x kind
sudo mv kind "${PROJECT_DIR}/bin"
Expand Down
6 changes: 4 additions & 2 deletions scripts/evergreen/setup_kubectl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ bindir="${PROJECT_DIR}/bin"
tmpdir="${PROJECT_DIR}/tmp"
mkdir -p "${bindir}" "${tmpdir}"

echo "Downloading latest kubectl for ${ARCH}"
curl -s --retry 3 -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${ARCH}/kubectl"
kubectl_version=$(curl --retry 5 -Ls https://dl.k8s.io/release/stable.txt)
echo "Downloading kubectl ${kubectl_version} for ${ARCH}"

curl --retry 5 -LOs "https://dl.k8s.io/release/${kubectl_version}/bin/linux/${ARCH}/kubectl"
chmod +x kubectl
echo "kubectl version --client"
./kubectl version --client
Expand Down