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
10 changes: 1 addition & 9 deletions monitoring/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,7 @@ source $(git rev-parse --show-toplevel)/scripts/common.sh

# --- Main Logic ---
# Determine regions from arguments, or auto-detect if none are provided
REGIONS=()
if [ $# -gt 0 ]; then
REGIONS=("$@")
echo "🎯 Targeting specified regions for monitoring setup: ${REGIONS[*]}"
else
echo "🔎 Auto-detecting all active playground regions for monitoring setup..."
# The '|| true' prevents the script from exiting if grep finds no matches.
REGIONS=($(kind get clusters | grep "^${K8S_BASE_NAME}-" | sed "s/^${K8S_BASE_NAME}-//" || true))
fi
detect_running_regions "$@"

# Add a target port for the port-forward, the port will be incremeted by 1 for each region
port=3000
Expand Down
3 changes: 3 additions & 0 deletions scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ fi
# Determine project root and kubeconfig path
GIT_REPO_ROOT=$(git rev-parse --show-toplevel)
KUBE_CONFIG_PATH="${GIT_REPO_ROOT}/k8s/kube-config.yaml"

# source funcs_regions.sh
source $(git rev-parse --show-toplevel)/scripts/funcs_regions.sh
55 changes: 55 additions & 0 deletions scripts/funcs_regions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
#
# This script contains the functions used to set the ${REGIONS} variable.
# set_regions() --> if called without an argument, EU and US are set
# otherwise the arguments.
#
# detect_running_regions() --> if called without an argument, the running
# CNPG-Playground Kind clusters regions are set
# otherwise the arguments.
#
#
# Copyright The CloudNativePG Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

set -euo pipefail

# --- Set regions ---
set_regions() {
if [ $# -eq 0 ]; then
REGIONS=("eu" "us")
echo "❌ No region provided, using the default regions "eu" "us"..."
else
REGIONS=("$@")
echo "🔎 Using the provided regions: ${REGIONS[*]}"
fi
}

# --- detect regions ---
detect_running_regions() {
if [ $# -gt 0 ]; then
REGIONS=("$@")
echo "🎯 Targeting specified regions: ${REGIONS[*]}"
else
echo "🔎 Auto-detecting all active playground regions..."
# The '|| true' prevents the script from exiting if grep finds no matches.
REGIONS=($(kind get clusters | grep "^${K8S_BASE_NAME}-" | sed "s/^${K8S_BASE_NAME}-//" || true))
if [ ${#REGIONS[@]} -gt 0 ]; then
echo "✅ Found regions: ${REGIONS[*]}"
else
echo "✅ No region detected"
fi
fi
}
9 changes: 1 addition & 8 deletions scripts/info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ fi
export KUBECONFIG="${KUBE_CONFIG_PATH}"

# --- Auto-detect Regions ---
echo "🔎 Detecting active playground clusters..."
REGIONS=($(kind get clusters | grep "^${K8S_BASE_NAME}-" | sed "s/^${K8S_BASE_NAME}-//" || true))

if [ ${#REGIONS[@]} -eq 0 ]; then
echo "🤷 No active playground clusters found with the prefix '${K8S_BASE_NAME}-'."
exit 0
fi
echo "✅ Found regions: ${REGIONS[*]}"
detect_running_regions

# --- Access Instructions ---
echo
Expand Down
5 changes: 1 addition & 4 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ echo

# --- Script Setup ---
# Determine regions from arguments, or use defaults
REGIONS=("$@")
if [ ${#REGIONS[@]} -eq 0 ]; then
REGIONS=("eu" "us")
fi
set_regions "$@"

# Setup a single, shared Kubeconfig for all clusters
export KUBECONFIG="${KUBE_CONFIG_PATH}"
Expand Down
17 changes: 1 addition & 16 deletions scripts/teardown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,7 @@ source "$(dirname "$0")/common.sh"

# --- Main Logic ---
# Determine regions from arguments, or auto-detect if none are provided
REGIONS=()
if [ $# -gt 0 ]; then
REGIONS=("$@")
echo "🎯 Targeting specified regions for teardown: ${REGIONS[*]}"
else
echo "🔎 Auto-detecting all active playground regions for teardown..."
# The '|| true' prevents the script from exiting if grep finds no matches.
REGIONS=($(kind get clusters | grep "^${K8S_BASE_NAME}-" | sed "s/^${K8S_BASE_NAME}-//" || true))
fi

if [ ${#REGIONS[@]} -eq 0 ]; then
echo "🤷 No regions found to tear down. Exiting."
exit 0
fi

echo "🔥 Tearing down regions: ${REGIONS[*]}"
detect_running_regions "$@"

for region in "${REGIONS[@]}"; do
K8S_CLUSTER_NAME="${K8S_BASE_NAME}-${region}"
Expand Down