Test the script
This commit is contained in:
parent
e0607be858
commit
56a850ca50
@ -20,15 +20,13 @@ ORIGINAL_FILE="$INFRA_CLONE/manifests/cloudflared/values.yaml"
|
|||||||
MERGED_FILE="$INFRA_CLONE/manifests/cloudflared/values.yaml"
|
MERGED_FILE="$INFRA_CLONE/manifests/cloudflared/values.yaml"
|
||||||
|
|
||||||
# === STEP 1: Clone Repos ===
|
# === STEP 1: Clone Repos ===
|
||||||
echo "📦 Cloning sandbox-apps..."
|
echo "📦 Cloning sandbox..."
|
||||||
git clone --depth=1 "$SANDBOX_REPO_URL" "$SANDBOX_CLONE"
|
git clone --depth=1 "$SANDBOX_REPO_URL" "$SANDBOX_CLONE"
|
||||||
|
|
||||||
echo "📦 Cloning infra..."
|
echo "📦 Cloning infra..."
|
||||||
git clone --depth=1 "$INFRA_REPO_URL" "$INFRA_CLONE"
|
git clone --depth=1 "$INFRA_REPO_URL" "$INFRA_CLONE"
|
||||||
|
|
||||||
ls -l .tmp-repos/
|
# === STEP 2: Generate new ingress entries ===
|
||||||
|
|
||||||
# === STEP 2: Extract Generated CNAMEs from sandbox ===
|
|
||||||
echo "⚙️ Generating sandbox ingress list..."
|
echo "⚙️ Generating sandbox ingress list..."
|
||||||
cat <<EOF > "$GENERATED_FILE"
|
cat <<EOF > "$GENERATED_FILE"
|
||||||
ingress: []
|
ingress: []
|
||||||
@ -40,10 +38,12 @@ find "$SANDBOX_CLONE/manifests" -name cname.yaml | while read -r cname_file; do
|
|||||||
|
|
||||||
if [[ "$enabled" == "true" ]]; then
|
if [[ "$enabled" == "true" ]]; then
|
||||||
hostname=$(yq '.hostname' "$cname_file")
|
hostname=$(yq '.hostname' "$cname_file")
|
||||||
service="http://${app_name}.sandbox.svc.cluster.local:80"
|
port=$(yq '.port // 80' "$cname_file") # default to 80 if not set
|
||||||
|
service="http://${app_name}.sandbox.svc.cluster.local:$port"
|
||||||
|
|
||||||
echo "✅ Found $hostname → $service"
|
echo "✅ Found $hostname → $service"
|
||||||
|
|
||||||
|
# Append to ingress list
|
||||||
yq eval ".ingress += [{\"hostname\": \"$hostname\", \"service\": \"$service\"}]" -i "$GENERATED_FILE"
|
yq eval ".ingress += [{\"hostname\": \"$hostname\", \"service\": \"$service\"}]" -i "$GENERATED_FILE"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -51,8 +51,8 @@ done
|
|||||||
echo "📄 Generated Ingress:"
|
echo "📄 Generated Ingress:"
|
||||||
cat "$GENERATED_FILE"
|
cat "$GENERATED_FILE"
|
||||||
|
|
||||||
# === STEP 3: Merge into original ingress ===
|
# === STEP 3: Merge ingress only ===
|
||||||
echo "🔁 Merging new entries into: $ORIGINAL_FILE"
|
echo "🔁 Merging ingress into: $ORIGINAL_FILE"
|
||||||
|
|
||||||
TEMP_FILE=$(mktemp)
|
TEMP_FILE=$(mktemp)
|
||||||
yq eval '.cloudflare.ingress' "$ORIGINAL_FILE" > "$TEMP_FILE"
|
yq eval '.cloudflare.ingress' "$ORIGINAL_FILE" > "$TEMP_FILE"
|
||||||
@ -62,6 +62,7 @@ yq eval '.ingress' "$GENERATED_FILE" | yq eval -o=json '.' - | jq -c '.[]' | whi
|
|||||||
service=$(echo "$new_entry" | jq -r '.service')
|
service=$(echo "$new_entry" | jq -r '.service')
|
||||||
|
|
||||||
exists=$(yq e ".cloudflare.ingress[] | select(.hostname == \"$hostname\")" "$ORIGINAL_FILE")
|
exists=$(yq e ".cloudflare.ingress[] | select(.hostname == \"$hostname\")" "$ORIGINAL_FILE")
|
||||||
|
|
||||||
if [ -z "$exists" ]; then
|
if [ -z "$exists" ]; then
|
||||||
echo "➕ Adding $hostname → $service"
|
echo "➕ Adding $hostname → $service"
|
||||||
yq eval ". += [{\"hostname\": \"$hostname\", \"service\": \"$service\"}]" -i "$TEMP_FILE"
|
yq eval ". += [{\"hostname\": \"$hostname\", \"service\": \"$service\"}]" -i "$TEMP_FILE"
|
||||||
@ -70,19 +71,23 @@ yq eval '.ingress' "$GENERATED_FILE" | yq eval -o=json '.' - | jq -c '.[]' | whi
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# === STEP 4: Write final merged values file (safe merge) ===
|
|
||||||
echo "📝 Writing merged file to $MERGED_FILE"
|
echo "📝 Writing merged file to $MERGED_FILE"
|
||||||
|
|
||||||
|
# Merge ingress back into full file, preserving all existing fields
|
||||||
yq eval-all '
|
yq eval-all '
|
||||||
select(fileIndex == 0) as $orig |
|
select(fileIndex == 0) as $orig |
|
||||||
select(fileIndex == 1) as $newIngress |
|
select(fileIndex == 1) as $newIngress |
|
||||||
$orig * {
|
$orig * {
|
||||||
cloudflare: {
|
cloudflare: $orig.cloudflare * {
|
||||||
ingress: $newIngress
|
ingress: $newIngress
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
' "$ORIGINAL_FILE" "$TEMP_FILE" > "$MERGED_FILE"
|
' "$ORIGINAL_FILE" "$TEMP_FILE" > "$MERGED_FILE"
|
||||||
|
|
||||||
# === STEP 5: Optional push to Git ===
|
echo "✅ Final merged values.yaml:"
|
||||||
|
cat "$MERGED_FILE"
|
||||||
|
|
||||||
|
# === STEP 4: Git Push ===
|
||||||
echo "📤 Pushing updated values.yaml to infra repo..."
|
echo "📤 Pushing updated values.yaml to infra repo..."
|
||||||
|
|
||||||
cd "$INFRA_CLONE"
|
cd "$INFRA_CLONE"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user