fix: rewrite Tekton integration tests for X-Service routing
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:
Admin Bot
2026-09-13 21:12:15 +09:00
parent ba6958e6f3
commit 6eb53a4d1c
8 changed files with 265 additions and 319 deletions
+28 -100
View File
@@ -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)
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
CI pushes image:sha → creates PipelineRun → Tekton spins up gateway sidecar
→ runs curl tests → reports pass/fail → CI promotes to :latest if pass
```
## 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`
- **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
## Files
### Pipeline: `integration-test-pipeline`
- **File**: `pipeline-integration-test.yaml`
- **Purpose**: Orchestrate integration test execution
- **Tasks**: Runs the integration-test task
- **Results**: Aggregates task results for CI consumption
| File | Purpose |
|------|---------|
| `task-integration-test.yaml` | Task: sidecar gateway + curl test step |
| `pipeline-integration-test.yaml` | Pipeline: wraps the Task |
| `scripts/integration-test.sh` | Test script (mounted as ConfigMap) |
| `kustomization.yaml` | Generates ConfigMap from script |
## Usage
### Manual Trigger
## Manual Run
```bash
# Create a PipelineRun to test an image
kubectl create -f - << 'YAML'
kubectl apply -k k8s/tekton/
kubectl create -f - <<'EOF'
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
@@ -54,77 +37,22 @@ spec:
name: integration-test-pipeline
params:
- name: image
value: forgejo.riotpiao.com/rock/api-gateway:abc123
- name: test-timeout
value: "5m"
YAML
value: forgejo.riotpiao.com/rock/api-gateway:latest
EOF
# Watch test progress
kubectl logs -f -n api pipelinerun/integration-test-manual
# Check results
kubectl get pipelinerun -n api integration-test-manual -o yaml
# Watch
kubectl logs -f -n api pipelinerun/integration-test-manual -c step-run-tests
```
### CI Trigger
## Updating Tests
CI automatically creates PipelineRun with:
- 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
Edit `scripts/integration-test.sh`, then:
```bash
# List all PipelineRuns
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>
kubectl apply -k k8s/tekton/ # recreates ConfigMap
```
## Results
## Tekton Infrastructure
PipelineRun status contains:
- `status.conditions[0].reason`: Succeeded | Failed | Unknown
- `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
Tekton Pipelines is installed in `~/workplace/homelab` via ArgoCD
(`k8s/argocd/apps/06-ci-cd.yaml` → vendored `k8s/infra/tekton/release.yaml`).