From b00e1073ba67754646d4b9ff36f85726869b9bca Mon Sep 17 00:00:00 2001 From: Mauricio Ferrari Date: Thu, 7 May 2026 08:00:16 -0400 Subject: [PATCH 1/2] dns scripts: add --existing-n offset and on-disk manifest Setup scripts now accept --existing-n (default 0) so additional batches can be appended without colliding with existing resource names. Manifests are written to a single file on disk and applied in one kubectl call instead of being held in memory, avoiding RAM blowup at large counts. Cleanup scripts remove that local manifest file as part of teardown. --- scripts/cleanup/dns-httproutes.sh | 6 ++++++ scripts/cleanup/dns-ingresses.sh | 6 ++++++ scripts/setup/dns-httproutes.sh | 36 ++++++++++++++++++++----------- scripts/setup/dns-ingresses.sh | 36 ++++++++++++++++++++----------- 4 files changed, 60 insertions(+), 24 deletions(-) diff --git a/scripts/cleanup/dns-httproutes.sh b/scripts/cleanup/dns-httproutes.sh index 5f1d34e..e44403e 100755 --- a/scripts/cleanup/dns-httproutes.sh +++ b/scripts/cleanup/dns-httproutes.sh @@ -37,4 +37,10 @@ LABEL="dns-test=true" echo "Deleting dns-test HTTPRoutes in namespace $NAMESPACE..." kubectl delete httproute.gateway.networking.k8s.io -n "$NAMESPACE" -l "$LABEL" --wait=false --ignore-not-found +MANIFEST_FILE="$(pwd)/dns-httproutes.yaml" +if [ -f "$MANIFEST_FILE" ]; then + echo "Removing local manifest file $MANIFEST_FILE..." + rm -f "$MANIFEST_FILE" +fi + echo "Delete request submitted (--wait=false). Gateway left intact." diff --git a/scripts/cleanup/dns-ingresses.sh b/scripts/cleanup/dns-ingresses.sh index 37e13c9..d04b611 100755 --- a/scripts/cleanup/dns-ingresses.sh +++ b/scripts/cleanup/dns-ingresses.sh @@ -36,4 +36,10 @@ LABEL="dns-test=true" echo "Deleting dns-test ingresses in namespace $NAMESPACE..." kubectl delete ingress -n "$NAMESPACE" -l "$LABEL" --wait=false --ignore-not-found +MANIFEST_FILE="$(pwd)/dns-ingresses.yaml" +if [ -f "$MANIFEST_FILE" ]; then + echo "Removing local manifest file $MANIFEST_FILE..." + rm -f "$MANIFEST_FILE" +fi + echo "Delete request submitted (--wait=false)." diff --git a/scripts/setup/dns-httproutes.sh b/scripts/setup/dns-httproutes.sh index 60b5451..6de5755 100755 --- a/scripts/setup/dns-httproutes.sh +++ b/scripts/setup/dns-httproutes.sh @@ -17,6 +17,7 @@ show_usage() { echo "Options:" echo " --count (required) Number of HTTPRoutes to create" echo " --domain (required) DNS zone domain (e.g. extdns.telescope.test)" + echo " --existing-n Index offset; objects will be numbered (existing-n+1)..(existing-n+count) (default: 0)" echo " --namespace Kubernetes namespace (default: default)" echo " --gateway Parent Gateway name (default: server)" echo " --gateway-section-name Parent Gateway listener section name (default: http)" @@ -28,6 +29,7 @@ show_usage() { COUNT="" DOMAIN="" +EXISTING_N="0" NAMESPACE="default" GATEWAY="server" GATEWAY_SECTION_NAME="http" @@ -38,6 +40,7 @@ while [[ $# -gt 0 ]]; do case "$1" in --count) COUNT="$2"; shift 2 ;; --domain) DOMAIN="$2"; shift 2 ;; + --existing-n) EXISTING_N="$2"; shift 2 ;; --namespace) NAMESPACE="$2"; shift 2 ;; --gateway) GATEWAY="$2"; shift 2 ;; --gateway-section-name) GATEWAY_SECTION_NAME="$2"; shift 2 ;; @@ -61,6 +64,11 @@ if ! [[ "$COUNT" =~ ^[1-9][0-9]*$ ]]; then exit 1 fi +if ! [[ "$EXISTING_N" =~ ^(0|[1-9][0-9]*)$ ]]; then + echo "Error: --existing-n must be a non-negative integer (>= 0)" + exit 1 +fi + DNS_LABEL='[a-z0-9]([-a-z0-9]*[a-z0-9])?' if ! [[ "$DOMAIN" =~ ^${DNS_LABEL}(\.${DNS_LABEL})*$ ]]; then echo "Error: --domain '$DOMAIN' is not a valid DNS subdomain (RFC 1123)" @@ -77,18 +85,23 @@ if ! kubectl get service "$SERVICE_NAME" -n "$NAMESPACE" >/dev/null 2>&1; then exit 1 fi -echo "Creating $COUNT dns-test HTTPRoutes:" +START=$((EXISTING_N + 1)) +END=$((EXISTING_N + COUNT)) +MANIFEST_FILE="$(pwd)/dns-httproutes.yaml" + +echo "Creating $COUNT dns-test HTTPRoutes (indices ${START}..${END}):" echo " Domain: $DOMAIN" echo " Namespace: $NAMESPACE" echo " Gateway: $GATEWAY (section: $GATEWAY_SECTION_NAME)" echo " Service: $SERVICE_NAME:$SERVICE_PORT" +echo " Manifest file: $MANIFEST_FILE" -MANIFEST=$( - for i in $(seq 1 "$COUNT"); do - if [ "$i" -gt 1 ]; then - printf '%s\n' '---' - fi - cat < "$MANIFEST_FILE" +for i in $(seq "$START" "$END"); do + if [ "$i" -gt "$START" ]; then + printf '%s\n' '---' >> "$MANIFEST_FILE" + fi + cat <> "$MANIFEST_FILE" apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: @@ -111,10 +124,9 @@ spec: - name: ${SERVICE_NAME} port: ${SERVICE_PORT} EOF - done -) +done -echo "Applying $COUNT HTTPRoutes in a single bulk request..." -echo "$MANIFEST" | kubectl apply --server-side -f - +echo "Applying $COUNT HTTPRoutes from $MANIFEST_FILE in a single bulk request..." +kubectl apply --server-side -f "$MANIFEST_FILE" -echo "Created $COUNT HTTPRoutes with hostnames test-1.${DOMAIN} through test-${COUNT}.${DOMAIN}" +echo "Created $COUNT HTTPRoutes with hostnames test-${START}.${DOMAIN} through test-${END}.${DOMAIN}" diff --git a/scripts/setup/dns-ingresses.sh b/scripts/setup/dns-ingresses.sh index 2b9a584..c4688f9 100755 --- a/scripts/setup/dns-ingresses.sh +++ b/scripts/setup/dns-ingresses.sh @@ -17,6 +17,7 @@ show_usage() { echo "Options:" echo " --count (required) Number of ingresses to create" echo " --domain (required) DNS zone domain (e.g. extdns.telescope.test)" + echo " --existing-n Index offset; objects will be numbered (existing-n+1)..(existing-n+count) (default: 0)" echo " --namespace Kubernetes namespace (default: default)" echo " --ingress-class Ingress class (default: webapprouting.kubernetes.azure.com)" echo " --service-name Backend service name (default: server)" @@ -27,6 +28,7 @@ show_usage() { COUNT="" DOMAIN="" +EXISTING_N="0" NAMESPACE="default" INGRESS_CLASS="webapprouting.kubernetes.azure.com" SERVICE_NAME="server" @@ -36,6 +38,7 @@ while [[ $# -gt 0 ]]; do case "$1" in --count) COUNT="$2"; shift 2 ;; --domain) DOMAIN="$2"; shift 2 ;; + --existing-n) EXISTING_N="$2"; shift 2 ;; --namespace) NAMESPACE="$2"; shift 2 ;; --ingress-class) INGRESS_CLASS="$2"; shift 2 ;; --service-name) SERVICE_NAME="$2"; shift 2 ;; @@ -58,6 +61,11 @@ if ! [[ "$COUNT" =~ ^[1-9][0-9]*$ ]]; then exit 1 fi +if ! [[ "$EXISTING_N" =~ ^(0|[1-9][0-9]*)$ ]]; then + echo "Error: --existing-n must be a non-negative integer (>= 0)" + exit 1 +fi + # RFC 1123 DNS subdomain: labels of [a-z0-9]([a-z0-9-]*[a-z0-9])?, separated by dots. DNS_LABEL='[a-z0-9]([-a-z0-9]*[a-z0-9])?' if ! [[ "$DOMAIN" =~ ^${DNS_LABEL}(\.${DNS_LABEL})*$ ]]; then @@ -70,18 +78,23 @@ if ! kubectl get service "$SERVICE_NAME" -n "$NAMESPACE" >/dev/null 2>&1; then exit 1 fi -echo "Creating $COUNT dns-test ingresses:" +START=$((EXISTING_N + 1)) +END=$((EXISTING_N + COUNT)) +MANIFEST_FILE="$(pwd)/dns-ingresses.yaml" + +echo "Creating $COUNT dns-test ingresses (indices ${START}..${END}):" echo " Domain: $DOMAIN" echo " Namespace: $NAMESPACE" echo " Ingress Class: $INGRESS_CLASS" echo " Service: $SERVICE_NAME:$SERVICE_PORT" +echo " Manifest file: $MANIFEST_FILE" -MANIFEST=$( - for i in $(seq 1 "$COUNT"); do - if [ "$i" -gt 1 ]; then - printf '%s\n' '---' - fi - cat < "$MANIFEST_FILE" +for i in $(seq "$START" "$END"); do + if [ "$i" -gt "$START" ]; then + printf '%s\n' '---' >> "$MANIFEST_FILE" + fi + cat <> "$MANIFEST_FILE" apiVersion: networking.k8s.io/v1 kind: Ingress metadata: @@ -103,10 +116,9 @@ spec: port: number: ${SERVICE_PORT} EOF - done -) +done -echo "Applying $COUNT ingresses in a single bulk request..." -echo "$MANIFEST" | kubectl apply --server-side -f - +echo "Applying $COUNT ingresses from $MANIFEST_FILE in a single bulk request..." +kubectl apply --server-side -f "$MANIFEST_FILE" -echo "Created $COUNT ingresses with hostnames test-1.${DOMAIN} through test-${COUNT}.${DOMAIN}" +echo "Created $COUNT ingresses with hostnames test-${START}.${DOMAIN} through test-${END}.${DOMAIN}" From b6bc43339fa79f568ba6d45c292fa9ef4af828a0 Mon Sep 17 00:00:00 2001 From: Mauricio Ferrari Date: Thu, 7 May 2026 11:35:44 -0400 Subject: [PATCH 2/2] dns scripts: write manifest to mktemp path, drop cleanup-side rm Decouples setup from caller CWD and removes the implicit cross-script file handoff. The manifest file lives under /tmp and is OS-managed, so cleanup no longer needs to know about it (deletion is label-driven). --- scripts/cleanup/dns-httproutes.sh | 6 ------ scripts/cleanup/dns-ingresses.sh | 6 ------ scripts/setup/dns-httproutes.sh | 2 +- scripts/setup/dns-ingresses.sh | 2 +- 4 files changed, 2 insertions(+), 14 deletions(-) diff --git a/scripts/cleanup/dns-httproutes.sh b/scripts/cleanup/dns-httproutes.sh index e44403e..5f1d34e 100755 --- a/scripts/cleanup/dns-httproutes.sh +++ b/scripts/cleanup/dns-httproutes.sh @@ -37,10 +37,4 @@ LABEL="dns-test=true" echo "Deleting dns-test HTTPRoutes in namespace $NAMESPACE..." kubectl delete httproute.gateway.networking.k8s.io -n "$NAMESPACE" -l "$LABEL" --wait=false --ignore-not-found -MANIFEST_FILE="$(pwd)/dns-httproutes.yaml" -if [ -f "$MANIFEST_FILE" ]; then - echo "Removing local manifest file $MANIFEST_FILE..." - rm -f "$MANIFEST_FILE" -fi - echo "Delete request submitted (--wait=false). Gateway left intact." diff --git a/scripts/cleanup/dns-ingresses.sh b/scripts/cleanup/dns-ingresses.sh index d04b611..37e13c9 100755 --- a/scripts/cleanup/dns-ingresses.sh +++ b/scripts/cleanup/dns-ingresses.sh @@ -36,10 +36,4 @@ LABEL="dns-test=true" echo "Deleting dns-test ingresses in namespace $NAMESPACE..." kubectl delete ingress -n "$NAMESPACE" -l "$LABEL" --wait=false --ignore-not-found -MANIFEST_FILE="$(pwd)/dns-ingresses.yaml" -if [ -f "$MANIFEST_FILE" ]; then - echo "Removing local manifest file $MANIFEST_FILE..." - rm -f "$MANIFEST_FILE" -fi - echo "Delete request submitted (--wait=false)." diff --git a/scripts/setup/dns-httproutes.sh b/scripts/setup/dns-httproutes.sh index 6de5755..cf6335b 100755 --- a/scripts/setup/dns-httproutes.sh +++ b/scripts/setup/dns-httproutes.sh @@ -87,7 +87,7 @@ fi START=$((EXISTING_N + 1)) END=$((EXISTING_N + COUNT)) -MANIFEST_FILE="$(pwd)/dns-httproutes.yaml" +MANIFEST_FILE="$(mktemp -t dns-httproutes.XXXXXX.yaml)" echo "Creating $COUNT dns-test HTTPRoutes (indices ${START}..${END}):" echo " Domain: $DOMAIN" diff --git a/scripts/setup/dns-ingresses.sh b/scripts/setup/dns-ingresses.sh index c4688f9..c54a262 100755 --- a/scripts/setup/dns-ingresses.sh +++ b/scripts/setup/dns-ingresses.sh @@ -80,7 +80,7 @@ fi START=$((EXISTING_N + 1)) END=$((EXISTING_N + COUNT)) -MANIFEST_FILE="$(pwd)/dns-ingresses.yaml" +MANIFEST_FILE="$(mktemp -t dns-ingresses.XXXXXX.yaml)" echo "Creating $COUNT dns-test ingresses (indices ${START}..${END}):" echo " Domain: $DOMAIN"