2026-07-18 16:16:24 +09:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
|
|
|
source "$ROOT/tests/kind/lib.sh"
|
|
|
|
|
|
|
|
|
|
USER_KUBECONFIG_BEFORE="$(user_kubeconfig_digest)"
|
|
|
|
|
SUCCEEDED=false
|
|
|
|
|
OWNS_FIXTURE=false
|
|
|
|
|
APP_IMAGE=nuthatch-wp05:local
|
|
|
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
|
local status=$?
|
|
|
|
|
trap - EXIT INT TERM
|
|
|
|
|
if [[ "${NUTHATCH_TESTBED_RETAIN:-0}" = 1 ]] && [[ "$SUCCEEDED" != true ]]; then
|
|
|
|
|
printf 'retained kubeconfig: %s\n' "$KUBECONFIG_PATH"
|
|
|
|
|
printf 'retained context: %s\n' "$CONTEXT"
|
|
|
|
|
exit "$status"
|
|
|
|
|
fi
|
|
|
|
|
if [[ "$OWNS_FIXTURE" = true ]]; then
|
|
|
|
|
destroy_fixture || status=1
|
|
|
|
|
fi
|
|
|
|
|
if [[ "$(user_kubeconfig_digest)" != "$USER_KUBECONFIG_BEFORE" ]]; then
|
|
|
|
|
printf 'user kubeconfig changed unexpectedly\n' >&2
|
|
|
|
|
status=1
|
|
|
|
|
fi
|
|
|
|
|
exit "$status"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
trap 'exit 130' INT
|
|
|
|
|
trap 'exit 143' TERM
|
|
|
|
|
|
|
|
|
|
render_application() {
|
|
|
|
|
local lane="$1"
|
|
|
|
|
local profile_file="$2"
|
|
|
|
|
local pg_conn
|
|
|
|
|
local redis_url
|
2026-07-18 18:08:41 +09:00
|
|
|
local oidc_issuer
|
|
|
|
|
local oidc_client_id
|
|
|
|
|
local oidc_additional_audiences
|
|
|
|
|
local oidc_client_secret
|
2026-07-18 16:16:24 +09:00
|
|
|
local s3_endpoint
|
|
|
|
|
local s3_region
|
|
|
|
|
local s3_bucket
|
|
|
|
|
local s3_access_key
|
|
|
|
|
local s3_secret_key
|
|
|
|
|
pg_conn="$(sed -n 's/^NUTHATCH_PG_CONN=//p' "$profile_file")"
|
|
|
|
|
redis_url="$(sed -n 's/^NUTHATCH_REDIS_URL=//p' "$profile_file")"
|
2026-07-18 18:08:41 +09:00
|
|
|
oidc_issuer="$(sed -n 's/^NUTHATCH_OIDC_ISSUER=//p' "$profile_file")"
|
|
|
|
|
oidc_client_id="$(sed -n 's/^NUTHATCH_OIDC_CLIENT_ID=//p' "$profile_file")"
|
|
|
|
|
oidc_additional_audiences="$(
|
|
|
|
|
sed -n 's/^NUTHATCH_OIDC_ADDITIONAL_AUDIENCES=//p' "$profile_file"
|
|
|
|
|
)"
|
|
|
|
|
oidc_client_secret="$(<"$profile_file.oidc-secret")"
|
2026-07-18 16:16:24 +09:00
|
|
|
s3_endpoint="$(sed -n 's/^NUTHATCH_S3_ENDPOINT=//p' "$profile_file")"
|
|
|
|
|
s3_region="$(sed -n 's/^NUTHATCH_S3_REGION=//p' "$profile_file")"
|
|
|
|
|
s3_bucket="$(sed -n 's/^NUTHATCH_S3_BUCKET=//p' "$profile_file")"
|
|
|
|
|
s3_access_key="$(sed -n 's/^NUTHATCH_S3_ACCESS_KEY=//p' "$profile_file")"
|
|
|
|
|
s3_secret_key="$(sed -n 's/^NUTHATCH_S3_SECRET_KEY=//p' "$profile_file")"
|
|
|
|
|
sed \
|
|
|
|
|
-e "s|@@LANE@@|$lane|g" \
|
|
|
|
|
-e "s|@@APP_IMAGE@@|$APP_IMAGE|g" \
|
|
|
|
|
-e "s|@@PG_CONN@@|$pg_conn|g" \
|
|
|
|
|
-e "s|@@REDIS_URL@@|$redis_url|g" \
|
2026-07-18 18:08:41 +09:00
|
|
|
-e "s|@@OIDC_ISSUER@@|$oidc_issuer|g" \
|
|
|
|
|
-e "s|@@OIDC_CLIENT_ID@@|$oidc_client_id|g" \
|
|
|
|
|
-e "s|@@OIDC_ADDITIONAL_AUDIENCES@@|$oidc_additional_audiences|g" \
|
|
|
|
|
-e "s|@@OIDC_CLIENT_SECRET@@|$oidc_client_secret|g" \
|
2026-07-18 16:16:24 +09:00
|
|
|
-e "s|@@S3_ENDPOINT@@|$s3_endpoint|g" \
|
|
|
|
|
-e "s|@@S3_REGION@@|$s3_region|g" \
|
|
|
|
|
-e "s|@@S3_BUCKET@@|$s3_bucket|g" \
|
|
|
|
|
-e "s|@@S3_ACCESS_KEY@@|$s3_access_key|g" \
|
|
|
|
|
-e "s|@@S3_SECRET_KEY@@|$s3_secret_key|g" \
|
|
|
|
|
"$ROOT/deploy/kubernetes/nuthatch.yaml.in" > "$RUNTIME/wp05-app-$lane.yaml"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cleanup_application() {
|
|
|
|
|
local lane="$1"
|
|
|
|
|
kube --namespace "$FIXTURE_NAMESPACE" delete \
|
|
|
|
|
"deployment/nuthatch-$lane" \
|
|
|
|
|
"service/nuthatch-$lane" \
|
|
|
|
|
"configmap/nuthatch-$lane" \
|
|
|
|
|
"secret/nuthatch-$lane" \
|
|
|
|
|
--ignore-not-found >/dev/null
|
|
|
|
|
rm -f "$RUNTIME/wp05-app-$lane.yaml"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
acquire_fixture_lock
|
|
|
|
|
OWNS_FIXTURE=true
|
2026-07-18 18:08:41 +09:00
|
|
|
setup_fixture durable coordination oidc target
|
2026-07-18 16:16:24 +09:00
|
|
|
source "$RUNTIME/fixture.env"
|
|
|
|
|
"$NUTHATCH_REAL_NERDCTL" --namespace "$NERDCTL_NAMESPACE" build \
|
|
|
|
|
--file "$ROOT/Dockerfile" \
|
|
|
|
|
--tag "$APP_IMAGE" \
|
|
|
|
|
"$ROOT"
|
|
|
|
|
load_local_image "$APP_IMAGE" "$NERDCTL_NAMESPACE"
|
|
|
|
|
|
|
|
|
|
while IFS=$'\t' read -r lane coordination oidc target; do
|
|
|
|
|
profile="$(write_lane_profile "$lane" "$coordination" "$oidc" "$target")"
|
|
|
|
|
render_application "$lane" "$RUNTIME/$profile.env"
|
|
|
|
|
kube apply --filename "$RUNTIME/wp05-app-$lane.yaml" >/dev/null
|
|
|
|
|
kube --namespace "$FIXTURE_NAMESPACE" rollout status \
|
|
|
|
|
"deployment/nuthatch-$lane" --timeout=180s
|
|
|
|
|
if [[ "${NUTHATCH_APP_INTERACTIVE:-0}" = 1 ]]; then
|
|
|
|
|
SUCCEEDED=true
|
|
|
|
|
OWNS_FIXTURE=false
|
|
|
|
|
printf 'interactive kubeconfig: %s\n' "$KUBECONFIG_PATH"
|
|
|
|
|
printf 'interactive context: %s\n' "$CONTEXT"
|
|
|
|
|
printf 'interactive namespace: %s\n' "$FIXTURE_NAMESPACE"
|
|
|
|
|
printf 'interactive service: nuthatch-%s:8080\n' "$lane"
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
job="wp05-app-$lane"
|
|
|
|
|
render_lane_job \
|
|
|
|
|
"$job" \
|
|
|
|
|
"$TESTBED/wp05-job.yaml.in" \
|
|
|
|
|
"$CURL_LOCAL_IMAGE" \
|
|
|
|
|
"$profile"
|
|
|
|
|
sed -i "s|@@LANE@@|$lane|g" "$RUNTIME/$job.yaml"
|
2026-07-18 18:08:41 +09:00
|
|
|
printf 'Running lane %s: coordination=%s oidc=%s target=%s\n' \
|
|
|
|
|
"$lane" "$coordination" "$oidc" "$target"
|
2026-07-18 16:16:24 +09:00
|
|
|
run_job_manifest "$job" "$RUNTIME/$job.yaml"
|
|
|
|
|
cleanup_application "$lane"
|
|
|
|
|
cleanup_lane_state "$lane" "$coordination" "$oidc" "$target"
|
|
|
|
|
cleanup_lane_resources "$job" "$profile"
|
2026-07-18 18:08:41 +09:00
|
|
|
done < <(expand_fixture_matrix coordination oidc target)
|
2026-07-18 16:16:24 +09:00
|
|
|
|
|
|
|
|
SUCCEEDED=true
|
2026-07-18 18:08:41 +09:00
|
|
|
printf 'Nuthatch OIDC app gate passed\n'
|