Skip to content

Commit 3540cad

Browse files
committed
Try multi-node kind cluster for testing
1 parent cde2aac commit 3540cad

File tree

3 files changed

+132
-12
lines changed

3 files changed

+132
-12
lines changed

.github/kind/multi-node.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
nodes:
4+
- role: control-plane
5+
- role: worker
6+
- role: worker

.github/workflows/helm-chart-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ jobs:
6767
version: ${{ env.KIND_VERSION }}
6868
node_image: kindest/node:${{ matrix.kubernetes-version }}
6969
cluster_name: stac-fastapi-${{ matrix.kubernetes-version }}
70+
config: .github/kind/multi-node.yaml
7071

7172
- name: Setup Helm repositories
7273
uses: ./.github/actions/setup-helm-repos
@@ -110,6 +111,7 @@ jobs:
110111
with:
111112
version: ${{ env.KIND_VERSION }}
112113
cluster_name: stac-fastapi-integration
114+
config: .github/kind/multi-node.yaml
113115

114116
- name: Setup Helm repositories
115117
uses: ./.github/actions/setup-helm-repos

helm-chart/test-chart.sh

Lines changed: 124 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,20 @@ collect_backend_logs() {
4747

4848
kubectl get pods -n "$NAMESPACE" -o wide || log_warning "Failed to list pods in namespace $NAMESPACE"
4949

50-
local pod_resources
51-
pod_resources=$(kubectl get pods -n "$NAMESPACE" -l "release=$RELEASE_NAME" -o name 2>/dev/null | grep "$backend" || true)
50+
local pod_resources=""
51+
local selectors=(
52+
"release=$RELEASE_NAME"
53+
"app.kubernetes.io/instance=$RELEASE_NAME"
54+
)
55+
56+
for selector in "${selectors[@]}"; do
57+
pod_resources=$(kubectl get pods -n "$NAMESPACE" -l "$selector" -o name 2>/dev/null | grep "$backend" || true)
58+
[[ -n "$pod_resources" ]] && break
59+
done
60+
61+
if [[ -z "$pod_resources" ]]; then
62+
pod_resources=$(kubectl get pods -n "$NAMESPACE" -o name 2>/dev/null | grep "$backend" || true)
63+
fi
5264

5365
if [[ -z "$pod_resources" ]]; then
5466
log_warning "No pods matching backend '$backend' found for log collection"
@@ -82,6 +94,80 @@ maybe_collect_backend_logs() {
8294
fi
8395
}
8496

97+
get_desired_app_replicas() {
98+
local values_path="$1"
99+
local default_count="${APP_REPLICA_COUNT:-}"
100+
101+
if [[ -n "$default_count" ]]; then
102+
echo "$default_count"
103+
return
104+
fi
105+
106+
default_count=2
107+
108+
if command -v python3 >/dev/null 2>&1; then
109+
set +e
110+
local parsed
111+
parsed=$(python3 <<'PY' "$values_path" 2>/dev/null)
112+
import sys
113+
from pathlib import Path
114+
115+
try:
116+
import yaml
117+
except Exception:
118+
raise SystemExit(1)
119+
120+
values_path = Path(sys.argv[1])
121+
if not values_path.exists():
122+
raise SystemExit(1)
123+
124+
with values_path.open('r', encoding='utf-8') as fh:
125+
data = yaml.safe_load(fh) or {}
126+
127+
replicas = data
128+
for key in ("app",):
129+
replicas = replicas.get(key, {}) if isinstance(replicas, dict) else {}
130+
131+
if isinstance(replicas, dict):
132+
replicas = replicas.get("replicaCount")
133+
134+
if isinstance(replicas, int) and replicas >= 0:
135+
print(replicas)
136+
else:
137+
raise SystemExit(1)
138+
PY
139+
)
140+
local status=$?
141+
set -e
142+
if [[ $status -eq 0 && "$parsed" =~ ^[0-9]+$ ]]; then
143+
echo "$parsed"
144+
return
145+
fi
146+
fi
147+
148+
echo "$default_count"
149+
}
150+
151+
wait_for_backend_ready() {
152+
local backend="$1"
153+
local timeout="${BACKEND_READY_TIMEOUT:-600}"
154+
155+
log_info "Waiting for $backend backend statefulsets to become ready..."
156+
157+
local sts_list
158+
sts_list=$(kubectl get statefulset -n "$NAMESPACE" -o name 2>/dev/null | grep "$backend" || true)
159+
160+
if [[ -z "$sts_list" ]]; then
161+
log_warning "No statefulsets found for backend '$backend' while waiting"
162+
return
163+
fi
164+
165+
for sts in $sts_list; do
166+
log_info "Waiting for rollout of $sts..."
167+
kubectl rollout status "$sts" -n "$NAMESPACE" --timeout="${timeout}s"
168+
done
169+
}
170+
85171
# Help function
86172
show_help() {
87173
cat << EOF
@@ -261,21 +347,47 @@ install_chart() {
261347
;;
262348
esac
263349

350+
local values_path="$CHART_PATH/$values_file"
351+
local desired_replicas
352+
desired_replicas=$(get_desired_app_replicas "$values_path")
353+
264354
log_info "Using values file: $values_file"
265-
266-
# Install the chart with appropriate values
355+
log_info "Target STAC FastAPI replica count: $desired_replicas"
356+
357+
local -a common_flags=(
358+
--namespace "$NAMESPACE"
359+
--values "$values_path"
360+
--set backend="$BACKEND"
361+
--set "${BACKEND}.enabled=true"
362+
--set "app.image.tag=latest"
363+
--set "app.service.type=ClusterIP"
364+
)
365+
366+
log_info "Installing chart with STAC FastAPI scaled to 0 replicas while $BACKEND initializes..."
267367
helm install "$RELEASE_NAME" "$CHART_PATH" \
268-
--namespace "$NAMESPACE" \
269-
--values "$CHART_PATH/$values_file" \
270-
--set backend="$BACKEND" \
271-
--set "${BACKEND}.enabled=true" \
272-
--set "app.image.tag=latest" \
273-
--set "app.service.type=ClusterIP" \
368+
--create-namespace \
369+
"${common_flags[@]}" \
370+
--set "app.replicaCount=0" \
274371
--wait \
275372
--timeout=10m
276-
373+
374+
wait_for_backend_ready "$BACKEND"
375+
376+
if [[ "$desired_replicas" -gt 0 ]]; then
377+
log_info "Scaling STAC FastAPI deployment to $desired_replicas replicas..."
378+
helm upgrade "$RELEASE_NAME" "$CHART_PATH" \
379+
"${common_flags[@]}" \
380+
--set "app.replicaCount=$desired_replicas" \
381+
--wait \
382+
--timeout=10m
383+
384+
kubectl rollout status deployment/"$RELEASE_NAME" -n "$NAMESPACE" --timeout=300s
385+
else
386+
log_info "Desired STAC FastAPI replica count is 0; leaving deployment scaled down."
387+
fi
388+
277389
log_success "Chart installed successfully"
278-
390+
279391
# Show installation status
280392
helm status "$RELEASE_NAME" -n "$NAMESPACE"
281393
}

0 commit comments

Comments
 (0)