Skip to content

Commit 39dba37

Browse files
committed
Try a different approach at running the services
1 parent d1bee47 commit 39dba37

8 files changed

Lines changed: 585 additions & 780 deletions

.tekton/README-INTEGRATION-TESTS.md

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ This directory contains integration test scenarios for the Compose Tracking Serv
44

55
## Overview
66

7-
The integration test scenario validates that the built CTS container image works correctly by:
8-
9-
1. **Deploying a test environment** - Creates a PostgreSQL database and deploys the CTS service
10-
2. **Running integration tests** - Validates API endpoints and service functionality
11-
3. **Cleaning up** - Removes all test resources
7+
The integration test scenario validates that the built CTS container image works correctly by running tests within the Konflux CI environment's permission constraints.
128

139
## Files
1410

@@ -21,25 +17,29 @@ The integration test scenario validates that the built CTS container image works
2117

2218
### Test Pipelines
2319

24-
- **`integration-test-k8s.yaml`** - Main integration test pipeline (recommended)
25-
- Deploys PostgreSQL database
26-
- Deploys CTS service with the built image
27-
- Runs comprehensive API tests
28-
- Automatically cleans up resources
20+
**Note:** Konflux CI service accounts have limited permissions and cannot create Deployments or Services. The test pipelines below work within these constraints.
21+
22+
- **`integration-test-container.yaml`** - Full integration test (recommended, currently in use)
23+
- Uses podman within test container to run CTS + PostgreSQL
24+
- Tests actual API functionality with database
25+
- Validates all major endpoints
26+
- Most comprehensive testing approach
2927

30-
- **`integration-test-simple.yaml`** - Simplified validation pipeline
31-
- Only validates image structure and metadata
32-
- Faster but less comprehensive
33-
- Useful for quick smoke tests
28+
- **`integration-test-pod.yaml`** - Sidecar-based approach (alternative)
29+
- Uses Tekton sidecars to run CTS and PostgreSQL together
30+
- Cleaner than podman approach
31+
- May require sidecar support in your Konflux environment
3432

35-
- **`integration-test-pipeline.yaml`** - Alternative podman-based approach
36-
- Uses podman-in-podman for testing
37-
- More complex, kept for reference
33+
- **`integration-test-basic.yaml`** - Minimal validation (fallback)
34+
- Only validates image metadata and structure using skopeo
35+
- No service deployment needed
36+
- Fast and guaranteed to work, but doesn't test functionality
37+
- Use as fallback if podman/sidecars don't work
3838

3939
### Test Scripts
4040

4141
- **`../tests/integration_test.py`** - Standalone integration test script
42-
- Can be run locally or in CI
42+
- Can be run locally for development
4343
- Tests all major API endpoints
4444
- Usage: `CTS_URL=http://localhost:5005 python3 tests/integration_test.py`
4545

@@ -67,27 +67,27 @@ The integration tests validate:
6767
4. Test pipeline deploys and validates the image
6868
5. Results are reported back to the PR/commit
6969

70-
### Pipeline Execution Flow
70+
### Pipeline Execution Flow (container approach)
7171

7272
```
7373
┌─────────────────────────────┐
7474
│ 1. Parse Snapshot │ Extract image URL from Konflux snapshot
7575
└─────────────┬───────────────┘
7676
7777
┌─────────────▼───────────────┐
78-
│ 2. Deploy PostgreSQL DBCreate database for testing
78+
│ 2. Start PostgreSQL Launch postgres container with podman
7979
└─────────────┬───────────────┘
8080
8181
┌─────────────▼───────────────┐
82-
│ 3. Deploy CTS Service │ Deploy CTS with test image
82+
│ 3. Start CTS Service Launch CTS container with podman
8383
└─────────────┬───────────────┘
8484
8585
┌─────────────▼───────────────┐
86-
│ 4. Run Integration Tests │ Execute API validation tests
86+
│ 4. Run Integration Tests │ Test API endpoints with Python
8787
└─────────────┬───────────────┘
8888
8989
┌─────────────▼───────────────┐
90-
│ 5. Cleanup (always runs)Remove test resources
90+
│ 5. Cleanup Stop and remove containers
9191
└─────────────────────────────┘
9292
```
9393

@@ -121,6 +121,9 @@ python3 tests/integration_test.py --url http://localhost:5005 --timeout 120
121121
If you have a Kubernetes cluster with Tekton installed:
122122

123123
```bash
124+
# First, apply the pipeline definition
125+
kubectl apply -f .tekton/integration-test-container.yaml
126+
124127
# Create a test snapshot (adjust IMAGE_URL)
125128
cat <<EOF | kubectl apply -f -
126129
apiVersion: tekton.dev/v1
@@ -129,7 +132,7 @@ metadata:
129132
name: cts-integration-test-manual
130133
spec:
131134
pipelineRef:
132-
name: cts-integration-test-k8s
135+
name: cts-integration-test-container
133136
params:
134137
- name: SNAPSHOT
135138
value: |
@@ -169,43 +172,57 @@ self._run_test("My new feature", self.test_my_new_feature)
169172

170173
### Modifying the Test Environment
171174

172-
Edit `.tekton/integration-test-k8s.yaml` to change:
175+
Edit `.tekton/integration-test-container.yaml` to change:
173176

174-
- Database configuration (in `deploy-test-database` task)
175-
- CTS environment variables (in `deploy-cts-service` task)
176-
- Test execution logic (in `run-integration-tests` task)
177+
- Database configuration (in the PostgreSQL podman run command)
178+
- CTS environment variables (in the CTS podman run command)
179+
- Test execution logic (in the Python test script)
177180

178181
## Troubleshooting
179182

180183
### Tests Failing in Konflux
181184

182185
1. Check PipelineRun logs:
183186
```bash
184-
kubectl logs -n team-sp-rhelcmp-tenant -l tekton.dev/pipeline=cts-integration-test-k8s
187+
kubectl get pipelinerun -n team-sp-rhelcmp-tenant -l test.appstudio.openshift.io/scenario=cts-integration-test
188+
kubectl logs -n team-sp-rhelcmp-tenant <pipelinerun-name> --all-containers
185189
```
186190

187191
2. Check if image is accessible:
188192
```bash
189193
skopeo inspect docker://YOUR_IMAGE_URL
190194
```
191195

192-
3. Check pod logs:
193-
```bash
194-
kubectl logs -n team-sp-rhelcmp-tenant -l app=cts-test
195-
```
196+
3. Look for podman errors in the test logs - the pipeline includes container logs on failure
196197

197198
### Tests Timing Out
198199

199-
- Increase timeout in IntegrationTestScenario
200-
- Check pod events: `kubectl describe pod -l app=cts-test`
201-
- Verify image pull is not failing
202-
- Check database readiness probe
200+
- Check if podman is available in the test container
201+
- Increase wait times in the pipeline script
202+
- Verify image pull is not failing (check for registry authentication)
203+
- Check if PostgreSQL container starts successfully
203204

204205
### Database Connection Issues
205206

206-
- Verify PostgreSQL deployment is ready
207-
- Check service DNS resolution
208-
- Review CTS logs for connection errors
207+
- Review the PostgreSQL podman logs in the test output
208+
- Verify the connection string is correct
209+
- Check if the database is accepting connections on localhost:5432
210+
- Ensure CTS waits long enough for database to be ready
211+
212+
### Podman Not Available
213+
214+
If podman doesn't work in your Konflux environment:
215+
216+
1. Switch to the basic validation approach:
217+
```yaml
218+
# In cts-integration-test.yaml
219+
pathInRepo: .tekton/integration-test-basic.yaml
220+
```
221+
222+
2. Or try the sidecar approach:
223+
```yaml
224+
pathInRepo: .tekton/integration-test-pod.yaml
225+
```
209226
210227
## Best Practices
211228

.tekton/cts-integration-test.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ spec:
1313
- name: url
1414
value: https://github.com/release-engineering/cts
1515
- name: revision
16-
value: main
16+
value: main # Change to your branch for testing, then back to main before merge
1717
- name: pathInRepo
18-
value: .tekton/integration-test-k8s.yaml
18+
value: .tekton/integration-test-container.yaml
1919
contexts:
2020
- name: service-validation
2121
description: |
22-
Deploys CTS with PostgreSQL database and validates that:
23-
- Service starts correctly
24-
- Database migrations run successfully
25-
- API endpoints respond correctly
26-
- OpenAPI specification is accessible
22+
Tests the CTS container image by:
23+
- Starting CTS service with PostgreSQL database using podman
24+
- Validating API endpoints respond correctly
25+
- Testing OpenAPI specification availability
26+
- Verifying database connectivity
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
apiVersion: tekton.dev/v1
2+
kind: Pipeline
3+
metadata:
4+
name: cts-integration-test-basic
5+
spec:
6+
description: |
7+
Basic integration test for CTS that works within Konflux permissions.
8+
Tests image structure and validates the built image without requiring
9+
additional Kubernetes resources or privileged containers.
10+
11+
params:
12+
- name: SNAPSHOT
13+
description: JSON string representing the snapshot under test
14+
type: string
15+
16+
tasks:
17+
- name: validate-and-test
18+
taskSpec:
19+
params:
20+
- name: SNAPSHOT
21+
type: string
22+
results:
23+
- name: test-result
24+
description: Overall test result
25+
steps:
26+
- name: test-image
27+
image: quay.io/konflux-ci/appstudio-utils:5bd0d6efcc7c828b0c6f5667630e36a580801fe9
28+
script: |
29+
#!/usr/bin/env bash
30+
set -euo pipefail
31+
32+
echo "=========================================="
33+
echo "CTS Image Integration Test"
34+
echo "=========================================="
35+
echo ""
36+
37+
# Parse snapshot
38+
IMAGE_URL=$(echo '$(params.SNAPSHOT)' | jq -r '.components[] | select(.name=="cts") | .containerImage')
39+
echo "Image: $IMAGE_URL"
40+
echo ""
41+
42+
# Install tools
43+
dnf install -y skopeo jq
44+
45+
# Test 1: Image is accessible
46+
echo "Test 1: Image Accessibility"
47+
echo "----------------------------"
48+
if skopeo inspect "docker://$IMAGE_URL" > /tmp/inspect.json; then
49+
echo "✓ Image exists and is accessible"
50+
else
51+
echo "✗ Failed to access image"
52+
exit 1
53+
fi
54+
echo ""
55+
56+
# Test 2: Image metadata
57+
echo "Test 2: Image Metadata"
58+
echo "----------------------"
59+
NAME=$(jq -r '.Name' /tmp/inspect.json)
60+
DIGEST=$(jq -r '.Digest' /tmp/inspect.json)
61+
echo " Name: $NAME"
62+
echo " Digest: $DIGEST"
63+
echo "✓ Image metadata valid"
64+
echo ""
65+
66+
# Test 3: Image labels
67+
echo "Test 3: Image Labels"
68+
echo "--------------------"
69+
LABELS=$(jq -r '.Labels' /tmp/inspect.json)
70+
if echo "$LABELS" | jq -e '.description' >/dev/null; then
71+
DESC=$(echo "$LABELS" | jq -r '.description')
72+
echo " Description: $DESC"
73+
echo "✓ Expected labels present"
74+
else
75+
echo "⚠ Warning: Some labels missing (non-fatal)"
76+
fi
77+
echo ""
78+
79+
# Test 4: Image layers
80+
echo "Test 4: Image Structure"
81+
echo "-----------------------"
82+
LAYERS=$(jq -r '.LayersData | length' /tmp/inspect.json)
83+
SIZE=$(jq -r '.Size' /tmp/inspect.json)
84+
echo " Layers: $LAYERS"
85+
echo " Size: $(($SIZE / 1024 / 1024)) MB"
86+
if [ "$LAYERS" -gt 0 ]; then
87+
echo "✓ Image has valid layer structure"
88+
else
89+
echo "✗ Invalid image structure"
90+
exit 1
91+
fi
92+
echo ""
93+
94+
# Test 5: Image can be pulled and files inspected
95+
echo "Test 5: Image Contents"
96+
echo "----------------------"
97+
if skopeo copy "docker://$IMAGE_URL" "dir:/tmp/image-contents" >/dev/null 2>&1; then
98+
echo "✓ Image can be extracted"
99+
100+
# Check for expected files in the image manifest
101+
if [ -f /tmp/image-contents/manifest.json ]; then
102+
echo "✓ Image manifest valid"
103+
fi
104+
else
105+
echo "⚠ Warning: Could not extract image (non-fatal)"
106+
fi
107+
echo ""
108+
109+
# Summary
110+
echo "=========================================="
111+
echo "All Tests Passed!"
112+
echo "=========================================="
113+
echo ""
114+
echo "Image Details:"
115+
echo " URL: $IMAGE_URL"
116+
echo " Digest: $DIGEST"
117+
echo " Size: $(($SIZE / 1024 / 1024)) MB"
118+
echo " Layers: $LAYERS"
119+
echo ""
120+
echo "✓ Image is ready for deployment"
121+
122+
# Save result
123+
echo "passed" | tee $(results.test-result.path)
124+
params:
125+
- name: SNAPSHOT
126+
value: $(params.SNAPSHOT)
127+
128+
results:
129+
- name: TEST_OUTPUT
130+
value: $(tasks.validate-and-test.results.test-result)

0 commit comments

Comments
 (0)