fix: rewrite Tekton integration tests for X-Service routing
CI / CI (pull_request) Failing after 50s
CI / CI (pull_request) Failing after 50s
FIXES: - Remove stale files: k8s/argocd-apps/, k8s/tekton/base/, overlays/ (Tekton infra is in homelab repo, not here) - Fix step.resources → step.computeResources (Tekton v1 API) - Fix Task: use curl sidecar pattern instead of distroless image (distroless has no shell/curl/go) - Fix routing: use X-Service + X-Resource headers, not path-based - Extract test script to scripts/integration-test.sh (ConfigMap mount) - Install kubectl in CI runner (was missing) - Prune README to essentials TASK ARCHITECTURE: sidecar: gateway image (mounts config secret, runs on localhost) step: curlimages/curl (runs integration-test.sh from ConfigMap) TEST COVERAGE: health, header validation, memory, s3, sqs, workflow, iam
This commit is contained in:
+54
-60
@@ -17,10 +17,13 @@ jobs:
|
|||||||
name: CI
|
name: CI
|
||||||
runs-on: golang
|
runs-on: golang
|
||||||
steps:
|
steps:
|
||||||
- name: Install Node.js and Docker
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
apt-get update
|
apt-get update
|
||||||
apt-get install -y nodejs docker.io
|
apt-get install -y docker.io curl
|
||||||
|
curl -sLO "https://dl.k8s.io/release/$(curl -sL https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
|
||||||
|
chmod +x kubectl && mv kubectl /usr/local/bin/
|
||||||
|
kubectl version --client
|
||||||
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -48,90 +51,81 @@ jobs:
|
|||||||
docker build --no-cache \
|
docker build --no-cache \
|
||||||
-t "${IMAGE}:${{ steps.sha.outputs.short_sha }}" \
|
-t "${IMAGE}:${{ steps.sha.outputs.short_sha }}" \
|
||||||
-f Dockerfile .
|
-f Dockerfile .
|
||||||
echo "Built image: ${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
|
||||||
|
|
||||||
- name: Push test image (SHA tag only, not latest yet)
|
- name: Push image (SHA tag)
|
||||||
run: |
|
run: docker push "${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
||||||
docker push "${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
|
||||||
echo "✓ Pushed test image: ${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
|
||||||
|
|
||||||
- name: Setup kubeconfig for Tekton trigger
|
# ── Tekton integration tests ─────────────────────────────
|
||||||
|
- name: Setup kubeconfig
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.kube
|
mkdir -p ~/.kube
|
||||||
echo "${KUBECONFIG_B64}" | base64 -d > ~/.kube/config
|
echo "${KUBECONFIG_B64}" | base64 -d > ~/.kube/config
|
||||||
|
kubectl cluster-info
|
||||||
env:
|
env:
|
||||||
KUBECONFIG_B64: ${{ secrets.KUBECONFIG_B64 }}
|
KUBECONFIG_B64: ${{ secrets.KUBECONFIG_B64 }}
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Trigger integration tests via Tekton PipelineRun
|
- name: Trigger Tekton PipelineRun
|
||||||
|
id: tekton
|
||||||
run: |
|
run: |
|
||||||
echo "Triggering integration tests via Tekton..."
|
SHA="${{ steps.sha.outputs.short_sha }}"
|
||||||
|
RUN_NAME="integration-test-${SHA}"
|
||||||
# Create PipelineRun to run integration tests
|
|
||||||
kubectl create -f - << 'YAML'
|
# Clean up any previous run with the same name
|
||||||
|
kubectl delete pipelinerun "${RUN_NAME}" -n api --ignore-not-found
|
||||||
|
|
||||||
|
# Create PipelineRun — spins up gateway sidecar + curl tests
|
||||||
|
cat <<YAML | kubectl create -f -
|
||||||
apiVersion: tekton.dev/v1
|
apiVersion: tekton.dev/v1
|
||||||
kind: PipelineRun
|
kind: PipelineRun
|
||||||
metadata:
|
metadata:
|
||||||
name: integration-test-${{ steps.sha.outputs.short_sha }}
|
name: ${RUN_NAME}
|
||||||
namespace: api
|
namespace: api
|
||||||
labels:
|
labels:
|
||||||
pr-id: "${{ github.event.pull_request.number || 'main' }}"
|
commit-sha: "${SHA}"
|
||||||
commit-sha: "${{ steps.sha.outputs.short_sha }}"
|
|
||||||
spec:
|
spec:
|
||||||
pipelineRef:
|
pipelineRef:
|
||||||
name: integration-test-pipeline
|
name: integration-test-pipeline
|
||||||
params:
|
params:
|
||||||
- name: image
|
- name: image
|
||||||
value: ${IMAGE}:${{ steps.sha.outputs.short_sha }}
|
value: "${IMAGE}:${SHA}"
|
||||||
- name: test-timeout
|
|
||||||
value: "5m"
|
|
||||||
YAML
|
YAML
|
||||||
|
|
||||||
echo "✓ PipelineRun created: integration-test-${{ steps.sha.outputs.short_sha }}"
|
echo "✓ PipelineRun created: ${RUN_NAME}"
|
||||||
|
|
||||||
# Wait for PipelineRun completion
|
# Wait for completion (Succeeded or Failed)
|
||||||
echo "Waiting for tests to complete (max 10 minutes)..."
|
echo "Waiting for tests (timeout 5m)..."
|
||||||
kubectl wait --for=condition=Succeeded \
|
if kubectl wait pipelinerun/"${RUN_NAME}" -n api \
|
||||||
pipelineruns/integration-test-${{ steps.sha.outputs.short_sha }} \
|
--for=condition=Succeeded --timeout=5m 2>/dev/null; then
|
||||||
-n api --timeout=10m 2>/dev/null || \
|
echo "result=pass" >> $GITHUB_OUTPUT
|
||||||
kubectl wait --for=condition=Failed \
|
else
|
||||||
pipelineruns/integration-test-${{ steps.sha.outputs.short_sha }} \
|
echo "result=fail" >> $GITHUB_OUTPUT
|
||||||
-n api --timeout=1s 2>/dev/null || true
|
fi
|
||||||
|
|
||||||
# Get test results
|
# Print logs + results
|
||||||
echo ""
|
|
||||||
echo "=== Test Results ==="
|
|
||||||
RESULT=$(kubectl get pipelinerun integration-test-${{ steps.sha.outputs.short_sha }} \
|
|
||||||
-n api -o jsonpath='{.status.conditions[0].reason}')
|
|
||||||
TEST_MESSAGE=$(kubectl get pipelinerun integration-test-${{ steps.sha.outputs.short_sha }} \
|
|
||||||
-n api -o jsonpath='{.status.taskRuns[*].status.taskResults[?(@.name=="result")].value}')
|
|
||||||
|
|
||||||
echo "PipelineRun Status: $RESULT"
|
|
||||||
echo "Test Result: $TEST_MESSAGE"
|
|
||||||
|
|
||||||
# Get logs
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "=== Test Logs ==="
|
echo "=== Test Logs ==="
|
||||||
kubectl logs -n api pipelinerun/integration-test-${{ steps.sha.outputs.short_sha }} || true
|
kubectl logs -n api "pipelinerun/${RUN_NAME}" --all-containers 2>/dev/null || true
|
||||||
|
echo ""
|
||||||
# Determine if tests passed
|
REASON=$(kubectl get pipelinerun "${RUN_NAME}" -n api \
|
||||||
if [ "$RESULT" = "Succeeded" ]; then
|
-o jsonpath='{.status.conditions[0].reason}')
|
||||||
echo "✓ Integration tests PASSED"
|
SUMMARY=$(kubectl get pipelinerun "${RUN_NAME}" -n api \
|
||||||
exit 0
|
-o jsonpath='{.status.results[?(@.name=="test-summary")].value}')
|
||||||
else
|
echo "Status: ${REASON}"
|
||||||
echo "✗ Integration tests FAILED"
|
echo "Summary: ${SUMMARY}"
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
continue-on-error: false
|
|
||||||
|
|
||||||
- name: Promote image to latest (only if tests passed)
|
- name: Gate on test result
|
||||||
if: success()
|
if: steps.tekton.outputs.result != 'pass'
|
||||||
|
run: |
|
||||||
|
echo "✗ Integration tests FAILED — image NOT promoted"
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
# ── Promote only after tests pass ────────────────────────
|
||||||
|
- name: Promote image to latest
|
||||||
run: |
|
run: |
|
||||||
docker pull "${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
|
||||||
docker tag "${IMAGE}:${{ steps.sha.outputs.short_sha }}" "${IMAGE}:latest"
|
docker tag "${IMAGE}:${{ steps.sha.outputs.short_sha }}" "${IMAGE}:latest"
|
||||||
docker push "${IMAGE}:latest"
|
docker push "${IMAGE}:latest"
|
||||||
echo "✓ Promoted ${IMAGE}:${{ steps.sha.outputs.short_sha }} to latest"
|
echo "✓ Promoted to latest"
|
||||||
|
|
||||||
- name: Cleanup
|
- name: Cleanup
|
||||||
if: always()
|
if: always()
|
||||||
run: docker image prune -a --force 2>&1 | tail -3 || true
|
run: docker image prune -af 2>&1 | tail -3 || true
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
apiVersion: argoproj.io/v1alpha1
|
|
||||||
kind: Application
|
|
||||||
metadata:
|
|
||||||
name: tekton-pipelines
|
|
||||||
namespace: argocd
|
|
||||||
labels:
|
|
||||||
app.kubernetes.io/name: tekton
|
|
||||||
app.kubernetes.io/part-of: homelab
|
|
||||||
spec:
|
|
||||||
project: default
|
|
||||||
|
|
||||||
source:
|
|
||||||
repoURL: https://github.com/tektoncd/operator.git
|
|
||||||
targetRevision: main
|
|
||||||
path: config/release
|
|
||||||
|
|
||||||
destination:
|
|
||||||
server: https://kubernetes.default.svc
|
|
||||||
namespace: tekton-pipelines
|
|
||||||
|
|
||||||
syncPolicy:
|
|
||||||
automated:
|
|
||||||
prune: true
|
|
||||||
selfHeal: true
|
|
||||||
syncOptions:
|
|
||||||
- CreateNamespace=true
|
|
||||||
- Validate=false
|
|
||||||
retry:
|
|
||||||
limit: 5
|
|
||||||
backoff:
|
|
||||||
duration: 5s
|
|
||||||
factor: 2
|
|
||||||
maxDuration: 3m
|
|
||||||
+28
-100
@@ -1,49 +1,32 @@
|
|||||||
# Tekton Integration Testing
|
# Tekton Integration Tests
|
||||||
|
|
||||||
Tekton Pipelines for running integration tests on API Gateway changes before merging to main.
|
Curl-based integration tests for the API gateway, orchestrated by Tekton.
|
||||||
|
|
||||||
## Architecture
|
## How It Works
|
||||||
|
|
||||||
```
|
```
|
||||||
Gitea CI (builds image:sha)
|
CI pushes image:sha → creates PipelineRun → Tekton spins up gateway sidecar
|
||||||
↓
|
→ runs curl tests → reports pass/fail → CI promotes to :latest if pass
|
||||||
Creates PipelineRun
|
|
||||||
↓
|
|
||||||
Tekton Controller (watches PipelineRun)
|
|
||||||
↓
|
|
||||||
Runs Task: integration-test
|
|
||||||
↓
|
|
||||||
Task runs tests in container
|
|
||||||
↓
|
|
||||||
Reports pass/fail to PipelineRun status
|
|
||||||
↓
|
|
||||||
CI reads status and promotes image (if pass)
|
|
||||||
↓
|
|
||||||
ArgoCD deploys new image
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Components
|
The Task runs the gateway image as a **sidecar** (same pod, localhost),
|
||||||
|
then executes `scripts/integration-test.sh` which tests every adapter
|
||||||
|
via `X-Service` + `X-Resource` header routing.
|
||||||
|
|
||||||
### Task: `integration-test`
|
## Files
|
||||||
- **File**: `task-integration-test.yaml`
|
|
||||||
- **Purpose**: Run integration tests in a container
|
|
||||||
- **Inputs**: Image to test, timeout
|
|
||||||
- **Outputs**: pass/fail result, message
|
|
||||||
- **Security**: Non-root user, resource limits
|
|
||||||
|
|
||||||
### Pipeline: `integration-test-pipeline`
|
| File | Purpose |
|
||||||
- **File**: `pipeline-integration-test.yaml`
|
|------|---------|
|
||||||
- **Purpose**: Orchestrate integration test execution
|
| `task-integration-test.yaml` | Task: sidecar gateway + curl test step |
|
||||||
- **Tasks**: Runs the integration-test task
|
| `pipeline-integration-test.yaml` | Pipeline: wraps the Task |
|
||||||
- **Results**: Aggregates task results for CI consumption
|
| `scripts/integration-test.sh` | Test script (mounted as ConfigMap) |
|
||||||
|
| `kustomization.yaml` | Generates ConfigMap from script |
|
||||||
|
|
||||||
## Usage
|
## Manual Run
|
||||||
|
|
||||||
### Manual Trigger
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Create a PipelineRun to test an image
|
kubectl apply -k k8s/tekton/
|
||||||
kubectl create -f - << 'YAML'
|
kubectl create -f - <<'EOF'
|
||||||
apiVersion: tekton.dev/v1
|
apiVersion: tekton.dev/v1
|
||||||
kind: PipelineRun
|
kind: PipelineRun
|
||||||
metadata:
|
metadata:
|
||||||
@@ -54,77 +37,22 @@ spec:
|
|||||||
name: integration-test-pipeline
|
name: integration-test-pipeline
|
||||||
params:
|
params:
|
||||||
- name: image
|
- name: image
|
||||||
value: forgejo.riotpiao.com/rock/api-gateway:abc123
|
value: forgejo.riotpiao.com/rock/api-gateway:latest
|
||||||
- name: test-timeout
|
EOF
|
||||||
value: "5m"
|
|
||||||
YAML
|
|
||||||
|
|
||||||
# Watch test progress
|
# Watch
|
||||||
kubectl logs -f -n api pipelinerun/integration-test-manual
|
kubectl logs -f -n api pipelinerun/integration-test-manual -c step-run-tests
|
||||||
|
|
||||||
# Check results
|
|
||||||
kubectl get pipelinerun -n api integration-test-manual -o yaml
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### CI Trigger
|
## Updating Tests
|
||||||
|
|
||||||
CI automatically creates PipelineRun with:
|
Edit `scripts/integration-test.sh`, then:
|
||||||
- Image tag: current commit SHA
|
|
||||||
- Timeout: 5 minutes
|
|
||||||
- Labels: PR ID, commit SHA for traceability
|
|
||||||
|
|
||||||
## Management
|
|
||||||
|
|
||||||
Tekton is managed by ArgoCD Application: `tekton-pipelines` (in `k8s/argocd-apps/tekton.yaml`)
|
|
||||||
|
|
||||||
To update:
|
|
||||||
1. Edit manifest files
|
|
||||||
2. Commit to git
|
|
||||||
3. ArgoCD syncs automatically
|
|
||||||
|
|
||||||
Do NOT manually apply manifests - let ArgoCD manage everything.
|
|
||||||
|
|
||||||
## Monitoring
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# List all PipelineRuns
|
kubectl apply -k k8s/tekton/ # recreates ConfigMap
|
||||||
kubectl get pipelineruns -n api
|
|
||||||
|
|
||||||
# Watch a specific run
|
|
||||||
kubectl logs -f -n api pipelinerun/integration-test-<sha>
|
|
||||||
|
|
||||||
# Get detailed status
|
|
||||||
kubectl describe pipelinerun -n api integration-test-<sha>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Results
|
## Tekton Infrastructure
|
||||||
|
|
||||||
PipelineRun status contains:
|
Tekton Pipelines is installed in `~/workplace/homelab` via ArgoCD
|
||||||
- `status.conditions[0].reason`: Succeeded | Failed | Unknown
|
(`k8s/argocd/apps/06-ci-cd.yaml` → vendored `k8s/infra/tekton/release.yaml`).
|
||||||
- `status.taskRuns[*].status.taskResults`: Test outputs
|
|
||||||
- Pod logs: Detailed test output
|
|
||||||
|
|
||||||
## Best Practices
|
|
||||||
|
|
||||||
1. **DRY**: Task and Pipeline are parameterized, reusable
|
|
||||||
2. **SOLID**: Single responsibility (Task runs tests, Pipeline orchestrates)
|
|
||||||
3. **GitOps**: Everything in git, managed by ArgoCD
|
|
||||||
4. **Security**: Non-root containers, resource limits, no hardcoded values
|
|
||||||
5. **Observability**: Clear logging, status tracking, result aggregation
|
|
||||||
|
|
||||||
## Troubleshooting
|
|
||||||
|
|
||||||
**PipelineRun stuck in Running**
|
|
||||||
- Check pod logs: `kubectl logs -n api pod/<task-pod>`
|
|
||||||
- Check gateway availability: `kubectl get pods -n api -l app=api-gateway`
|
|
||||||
- Increase timeout in pipeline params
|
|
||||||
|
|
||||||
**Tests failing**
|
|
||||||
- Check test logs: `kubectl logs -n api pipelinerun/<run-name>`
|
|
||||||
- Verify gateway is ready and accessible
|
|
||||||
- Check downstream services (memory, S3, etc.)
|
|
||||||
|
|
||||||
**Image not promoted**
|
|
||||||
- CI only promotes if PipelineRun succeeds
|
|
||||||
- Check PipelineRun status: `kubectl get pipelinerun <name> -n api -o yaml`
|
|
||||||
- Review CI logs in Gitea for error details
|
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
# Tekton Pipelines Release manifest
|
|
||||||
# Source: https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml
|
|
||||||
# This is managed by ArgoCD - do NOT manually apply
|
|
||||||
# ArgoCD syncs this from git
|
|
||||||
|
|
||||||
apiVersion: v1
|
|
||||||
kind: Namespace
|
|
||||||
metadata:
|
|
||||||
name: tekton-pipelines
|
|
||||||
labels:
|
|
||||||
managed-by: argocd
|
|
||||||
|
|
||||||
---
|
|
||||||
# CRDs and RBAC are part of the full release manifest
|
|
||||||
# Using a reference approach for cleaner GitOps
|
|
||||||
apiVersion: argoproj.io/v1alpha1
|
|
||||||
kind: ApplicationSet
|
|
||||||
metadata:
|
|
||||||
name: tekton-pipelines
|
|
||||||
namespace: argocd
|
|
||||||
spec:
|
|
||||||
generators:
|
|
||||||
- list:
|
|
||||||
elements:
|
|
||||||
- name: tekton-pipelines
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
name: tekton-pipelines
|
|
||||||
namespace: argocd
|
|
||||||
spec:
|
|
||||||
project: default
|
|
||||||
source:
|
|
||||||
repoURL: https://github.com/tektoncd/operator
|
|
||||||
targetRevision: main
|
|
||||||
path: config/release
|
|
||||||
destination:
|
|
||||||
server: https://kubernetes.default.svc
|
|
||||||
namespace: tekton-pipelines
|
|
||||||
syncPolicy:
|
|
||||||
automated:
|
|
||||||
prune: true
|
|
||||||
selfHeal: true
|
|
||||||
syncOptions:
|
|
||||||
- CreateNamespace=true
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
metadata:
|
|
||||||
name: api-gateway-tekton
|
|
||||||
|
|
||||||
namespace: api
|
namespace: api
|
||||||
|
|
||||||
@@ -9,7 +7,10 @@ resources:
|
|||||||
- task-integration-test.yaml
|
- task-integration-test.yaml
|
||||||
- pipeline-integration-test.yaml
|
- pipeline-integration-test.yaml
|
||||||
|
|
||||||
commonLabels:
|
generatorOptions:
|
||||||
app: api-gateway
|
disableNameSuffixHash: true
|
||||||
component: testing
|
|
||||||
managed-by: argocd
|
configMapGenerator:
|
||||||
|
- name: integration-test-script
|
||||||
|
files:
|
||||||
|
- scripts/integration-test.sh
|
||||||
|
|||||||
@@ -7,29 +7,24 @@ metadata:
|
|||||||
app: api-gateway
|
app: api-gateway
|
||||||
component: testing
|
component: testing
|
||||||
spec:
|
spec:
|
||||||
description: Pipeline to run integration tests for API gateway
|
description: >
|
||||||
|
Run integration tests against a gateway image.
|
||||||
|
Spins up the image as a sidecar, tests via curl, reports pass/fail.
|
||||||
params:
|
params:
|
||||||
- name: image
|
- name: image
|
||||||
type: string
|
type: string
|
||||||
description: Container image to test (repo:tag)
|
description: "Container image to test (repo:sha)"
|
||||||
default: "forgejo.riotpiao.com/rock/api-gateway:latest"
|
|
||||||
- name: test-timeout
|
|
||||||
type: string
|
|
||||||
default: "5m"
|
|
||||||
description: Test execution timeout
|
|
||||||
results:
|
results:
|
||||||
- name: test-result
|
- name: test-result
|
||||||
description: Overall test result (pass/fail)
|
description: "pass or fail"
|
||||||
value: $(tasks.run-integration-tests.results.result)
|
value: $(tasks.integration-test.results.result)
|
||||||
- name: test-message
|
- name: test-summary
|
||||||
description: Test summary message
|
description: "e.g. 8/8 passed"
|
||||||
value: $(tasks.run-integration-tests.results.message)
|
value: $(tasks.integration-test.results.summary)
|
||||||
tasks:
|
tasks:
|
||||||
- name: run-integration-tests
|
- name: integration-test
|
||||||
taskRef:
|
taskRef:
|
||||||
name: integration-test
|
name: integration-test
|
||||||
params:
|
params:
|
||||||
- name: image
|
- name: image
|
||||||
value: $(params.image)
|
value: $(params.image)
|
||||||
- name: timeout
|
|
||||||
value: $(params.test-timeout)
|
|
||||||
|
|||||||
Executable
+115
@@ -0,0 +1,115 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Integration test runner for API gateway.
|
||||||
|
# Tests X-Service + X-Resource header routing against a gateway on localhost.
|
||||||
|
#
|
||||||
|
# Required env:
|
||||||
|
# GW — gateway base URL (e.g. http://localhost:8080)
|
||||||
|
# RESULTS_DIR — directory to write Tekton results
|
||||||
|
|
||||||
|
PASS=0; FAIL=0; TOTAL=0
|
||||||
|
|
||||||
|
assert() {
|
||||||
|
NAME="$1"; EXPECT="$2"
|
||||||
|
shift 2
|
||||||
|
# remaining args are the full curl flags
|
||||||
|
TOTAL=$((TOTAL + 1))
|
||||||
|
CODE=$(curl -s -o /dev/null -w '%{http_code}' "$@" 2>/dev/null || echo "000")
|
||||||
|
|
||||||
|
if [ "$CODE" = "$EXPECT" ]; then
|
||||||
|
echo " ✓ ${NAME} (${CODE})"
|
||||||
|
PASS=$((PASS + 1))
|
||||||
|
else
|
||||||
|
echo " ✗ ${NAME} — expected ${EXPECT}, got ${CODE}"
|
||||||
|
FAIL=$((FAIL + 1))
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# ── Wait for sidecar gateway to be fully ready ──
|
||||||
|
echo "⏳ Waiting for gateway sidecar..."
|
||||||
|
READY=false
|
||||||
|
for i in $(seq 1 60); do
|
||||||
|
CODE=$(curl -s -o /dev/null -w '%{http_code}' "${GW}/healthz" 2>/dev/null || echo "000")
|
||||||
|
if [ "$CODE" = "200" ]; then
|
||||||
|
sleep 1
|
||||||
|
C2=$(curl -s -o /dev/null -w '%{http_code}' "${GW}/healthz" 2>/dev/null || echo "000")
|
||||||
|
C3=$(curl -s -o /dev/null -w '%{http_code}' "${GW}/healthz" 2>/dev/null || echo "000")
|
||||||
|
if [ "$C2" = "200" ] && [ "$C3" = "200" ]; then
|
||||||
|
READY=true
|
||||||
|
echo "✓ Gateway ready (stable after 3 checks)"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$READY" = "false" ]; then
|
||||||
|
echo "✗ Gateway never became ready"
|
||||||
|
echo "fail" > "${RESULTS_DIR}/result"
|
||||||
|
echo "0/0 gateway timeout" > "${RESULTS_DIR}/summary"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "═══ Integration Tests ═══"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# ── Health (path-based, no headers) ──
|
||||||
|
echo "▸ Health"
|
||||||
|
assert "GET /healthz" 200 \
|
||||||
|
-X GET "${GW}/healthz"
|
||||||
|
assert "GET /readyz" 200 \
|
||||||
|
-X GET "${GW}/readyz"
|
||||||
|
|
||||||
|
# ── Routing: missing headers → 400 ──
|
||||||
|
echo "▸ Header validation"
|
||||||
|
assert "no X-Service → 400" 400 \
|
||||||
|
-X GET "${GW}/"
|
||||||
|
assert "X-Service without X-Resource → 400" 400 \
|
||||||
|
-X GET -H "X-Service: memory" "${GW}/"
|
||||||
|
assert "unknown service → 404" 404 \
|
||||||
|
-X GET -H "X-Service: nonexistent" -H "X-Resource: foo" "${GW}/"
|
||||||
|
|
||||||
|
# ── Memory service (POST, no auth) ──
|
||||||
|
echo "▸ Memory service"
|
||||||
|
assert "memory/query (POST)" 200 \
|
||||||
|
-X POST -H "X-Service: memory" -H "X-Resource: query" \
|
||||||
|
-H "Content-Type: application/json" -d '{"query":"test"}' "${GW}/"
|
||||||
|
assert "memory/ingest (POST)" 200 \
|
||||||
|
-X POST -H "X-Service: memory" -H "X-Resource: ingest" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"content":"integration test","metadata":{"source":"tekton"}}' "${GW}/"
|
||||||
|
|
||||||
|
# ── S3 service (GET, no auth → MinIO 403) ──
|
||||||
|
echo "▸ S3 service"
|
||||||
|
assert "s3/list-objects (GET → 403)" 403 \
|
||||||
|
-X GET -H "X-Service: s3" -H "X-Resource: list-objects" "${GW}/"
|
||||||
|
|
||||||
|
# ── SQS service (GET, auth required → 401) ──
|
||||||
|
echo "▸ SQS service"
|
||||||
|
assert "sqs/list-queues (GET → 401)" 401 \
|
||||||
|
-X GET -H "X-Service: sqs" -H "X-Resource: list-queues" "${GW}/"
|
||||||
|
|
||||||
|
# ── Workflow service (gRPC, GET) ──
|
||||||
|
echo "▸ Workflow service"
|
||||||
|
assert "workflow/list (GET → upstream err)" 502 \
|
||||||
|
-X GET -H "X-Service: workflow" -H "X-Resource: list" "${GW}/"
|
||||||
|
|
||||||
|
# ── IAM service (GET, Authentik) ──
|
||||||
|
echo "▸ IAM service"
|
||||||
|
assert "iam/list-users (GET → Authentik redirect)" 302 \
|
||||||
|
-X GET -H "X-Service: iam" -H "X-Resource: list-users" "${GW}/"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "═══ Results: ${PASS}/${TOTAL} passed, ${FAIL} failed ═══"
|
||||||
|
|
||||||
|
# Write Tekton results
|
||||||
|
if [ "$FAIL" -eq 0 ]; then
|
||||||
|
echo "pass" > "${RESULTS_DIR}/result"
|
||||||
|
else
|
||||||
|
echo "fail" > "${RESULTS_DIR}/result"
|
||||||
|
fi
|
||||||
|
echo "${PASS}/${TOTAL} passed, ${FAIL} failed" > "${RESULTS_DIR}/summary"
|
||||||
|
|
||||||
|
[ "$FAIL" -eq 0 ]
|
||||||
@@ -7,79 +7,69 @@ metadata:
|
|||||||
app: api-gateway
|
app: api-gateway
|
||||||
component: testing
|
component: testing
|
||||||
spec:
|
spec:
|
||||||
description: Run integration tests for API gateway
|
description: >
|
||||||
|
Spin up a gateway pod from the given image as a sidecar,
|
||||||
|
run curl-based integration tests, report pass/fail.
|
||||||
params:
|
params:
|
||||||
- name: image
|
- name: image
|
||||||
type: string
|
type: string
|
||||||
description: Container image to test (including tag)
|
description: "Container image to test (repo:tag)"
|
||||||
- name: timeout
|
- name: gateway-port
|
||||||
type: string
|
type: string
|
||||||
default: "5m"
|
default: "8080"
|
||||||
description: Test timeout
|
|
||||||
results:
|
results:
|
||||||
- name: result
|
- name: result
|
||||||
description: Test result (pass/fail)
|
|
||||||
type: string
|
type: string
|
||||||
- name: message
|
- name: summary
|
||||||
description: Test summary message
|
|
||||||
type: string
|
type: string
|
||||||
|
|
||||||
|
sidecars:
|
||||||
|
- name: gateway
|
||||||
|
image: $(params.image)
|
||||||
|
env:
|
||||||
|
- name: LISTEN_ADDR
|
||||||
|
value: "0.0.0.0:$(params.gateway-port)"
|
||||||
|
- name: CONFIG_PATH
|
||||||
|
value: /etc/gateway/config.yaml
|
||||||
|
- name: LOG_LEVEL
|
||||||
|
value: info
|
||||||
|
- name: AUTH_CLIENT_SECRET
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: api-gw-client-secret
|
||||||
|
key: client-secret
|
||||||
|
optional: true
|
||||||
|
volumeMounts:
|
||||||
|
- name: gateway-config
|
||||||
|
mountPath: /etc/gateway
|
||||||
|
readOnly: true
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: run-tests
|
- name: run-tests
|
||||||
image: $(params.image)
|
image: curlimages/curl:8.13.0
|
||||||
securityContext:
|
|
||||||
runAsNonRoot: true
|
|
||||||
runAsUser: 65532
|
|
||||||
allowPrivilegeEscalation: false
|
|
||||||
env:
|
env:
|
||||||
- name: GATEWAY_URL
|
- name: GW
|
||||||
value: "http://api-gateway:8080"
|
value: "http://localhost:$(params.gateway-port)"
|
||||||
- name: CI
|
- name: RESULTS_DIR
|
||||||
value: "true"
|
value: /tekton/results
|
||||||
script: |
|
command: ["sh", "/scripts/integration-test.sh"]
|
||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
|
|
||||||
echo "🧪 Starting integration tests..."
|
|
||||||
echo "Image: $(params.image)"
|
|
||||||
echo "Gateway: $GATEWAY_URL"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# Wait for gateway to be ready
|
|
||||||
echo "Waiting for gateway service..."
|
|
||||||
for i in $(seq 1 30); do
|
|
||||||
if curl -s $GATEWAY_URL/healthz > /dev/null 2>&1; then
|
|
||||||
echo "✓ Gateway is ready"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
echo "Attempt $i/30: Waiting for gateway..."
|
|
||||||
sleep 2
|
|
||||||
done
|
|
||||||
|
|
||||||
# Run integration tests
|
|
||||||
echo "Running integration tests..."
|
|
||||||
if go test -v -tags=integration -timeout=$(params.timeout) ./internal/integration/...; then
|
|
||||||
echo "pass" | tee $(results.result.path)
|
|
||||||
echo "✓ All integration tests passed" | tee $(results.message.path)
|
|
||||||
exit 0
|
|
||||||
else
|
|
||||||
echo "fail" | tee $(results.result.path)
|
|
||||||
echo "✗ Some integration tests failed" | tee $(results.message.path)
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: tmp
|
- name: test-script
|
||||||
mountPath: /tmp
|
mountPath: /scripts
|
||||||
- name: home
|
readOnly: true
|
||||||
mountPath: /home/nonroot
|
computeResources:
|
||||||
resources:
|
|
||||||
requests:
|
requests:
|
||||||
cpu: 250m
|
cpu: 100m
|
||||||
memory: 512Mi
|
memory: 64Mi
|
||||||
limits:
|
limits:
|
||||||
cpu: 500m
|
cpu: 200m
|
||||||
memory: 1Gi
|
memory: 128Mi
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
- name: tmp
|
- name: gateway-config
|
||||||
emptyDir: {}
|
secret:
|
||||||
- name: home
|
secretName: api-gateway-config
|
||||||
emptyDir: {}
|
- name: test-script
|
||||||
|
configMap:
|
||||||
|
name: integration-test-script
|
||||||
|
defaultMode: 0755
|
||||||
|
|||||||
Reference in New Issue
Block a user