Skip to content

Commit f9ff6ce

Browse files
committed
WIP test image build
1 parent b3c8f6d commit f9ff6ce

13 files changed

Lines changed: 1951 additions & 6 deletions

.tekton/MIGRATION_SUMMARY.md

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
# Migration to Containerized Test Scripts
2+
3+
## What Was Changed
4+
5+
### 1. Created Test Runner Image (`.tekton/test-image/`)
6+
7+
**New directory structure:**
8+
```
9+
.tekton/test-image/
10+
├── Dockerfile # Container image with all dependencies
11+
├── scripts/ # All test logic lives here
12+
│ ├── install-operator-bundle.sh # Migrated from inline YAML script
13+
│ ├── install-operator-subscription.sh # For catalog testing
14+
│ ├── run-e2e-tests.sh # Migrated from run-gitops-operator-e2e-minimal
15+
│ └── run-dast-scan.sh # For DAST security scans
16+
├── config/
17+
│ └── image-mirrors.yaml # Centralized mirror configuration
18+
└── README.md # Local testing guide
19+
```
20+
21+
**Key benefits:**
22+
- All scripts are now executable bash files (not YAML heredocs)
23+
- Scripts configured via environment variables only
24+
- Can be tested locally with `docker run`
25+
- Version controlled with the code
26+
27+
### 2. Created Kaniko Build Task (`.tekton/tasks/build-test-image-kaniko.yaml`)
28+
29+
Based on proven GitLab CI pattern:
30+
- Uses Kaniko (unprivileged, no daemon required)
31+
- Quay caching enabled for fast rebuilds
32+
- Tags images with commit SHA for traceability
33+
- Images expire after 7 days
34+
35+
### 3. Created Thin Wrapper StepActions
36+
37+
**`.tekton/steps/install-operator.yaml`:**
38+
- Replaces `install-gitops-operator-bundle.yaml`
39+
- Thin wrapper that just calls `/scripts/install-operator-bundle.sh`
40+
- Uses test image built from PR code
41+
42+
**`.tekton/steps/run-tests.yaml`:**
43+
- Replaces `run-gitops-operator-e2e-minimal.yaml`
44+
- Routes to appropriate test script based on `testType` parameter
45+
- Supports: e2e, dast (extensible for more)
46+
47+
### 4. Updated Release Pipeline
48+
49+
**Changes to `gitops-bundle-lowest-integration-test-pipeline.yaml`:**
50+
51+
1. **Added workspace:**
52+
```yaml
53+
workspaces:
54+
- name: shared-workspace
55+
```
56+
57+
2. **Added build-test-image task:**
58+
```yaml
59+
- name: build-test-image
60+
runAfter: [extract-step-actions-ref]
61+
# Builds test image from PR commit
62+
# Result: IMAGE_URL used by all subsequent steps
63+
```
64+
65+
3. **Updated install-operator task:**
66+
- Now depends on `build-test-image`
67+
- Uses new `.tekton/steps/install-operator.yaml` wrapper
68+
- Passes `testImage` parameter
69+
70+
4. **Updated test-operator task:**
71+
- Uses new `.tekton/steps/run-tests.yaml` wrapper
72+
- Passes `testImage` and `testType: e2e`
73+
74+
## Self-Testability Preserved
75+
76+
The pipeline still tests with PR code:
77+
78+
```
79+
SNAPSHOT → extract-step-actions-ref → SOURCE_URL + SOURCE_REVISION
80+
81+
build-test-image
82+
83+
Image tagged: abc12345
84+
85+
All steps use this image
86+
```
87+
88+
**Result:** Scripts from the PR are baked into the image and used for testing.
89+
90+
## Migration Impact
91+
92+
### What Still Works ✅
93+
- Self-testability (tests use PR code)
94+
- Extract-step-actions-ref pattern
95+
- Parallel execution (cluster provision + image build)
96+
- All existing functionality preserved
97+
98+
### What's Better ✅
99+
- Scripts testable locally (`docker run`)
100+
- Faster iteration (edit bash, not YAML)
101+
- Easier debugging (pull exact image, run interactively)
102+
- No inline heredocs (proper syntax highlighting)
103+
- No hardcoded values in scripts (env vars only)
104+
105+
### What's New ✅
106+
- Kaniko caching (faster rebuilds)
107+
- Image expiration (auto-cleanup)
108+
- Extensible test framework (easy to add new test types)
109+
110+
## How to Test Locally
111+
112+
### Build Test Image
113+
114+
```bash
115+
cd .tekton/test-image
116+
docker build -t gitops-test-runner:dev .
117+
```
118+
119+
### Test Install Script
120+
121+
```bash
122+
docker run --rm -it \
123+
-e BUNDLE_IMAGE="quay.io/.../bundle:latest" \
124+
-e KUBECONFIG="/kube/config" \
125+
-v ~/.kube/config:/kube/config:ro \
126+
gitops-test-runner:dev \
127+
/scripts/install-operator-bundle.sh
128+
```
129+
130+
### Test E2E Script
131+
132+
```bash
133+
docker run --rm -it \
134+
-e KUBECONFIG="/kube/config" \
135+
-e BRANCH="master" \
136+
-v ~/.kube/config:/kube/config:ro \
137+
-v $(pwd)/workspace:/workspace \
138+
gitops-test-runner:dev \
139+
/scripts/run-e2e-tests.sh
140+
```
141+
142+
See `.tekton/test-image/README.md` for complete local testing guide.
143+
144+
## Required Secret
145+
146+
The pipeline now needs a secret for pushing test images to Quay:
147+
148+
```yaml
149+
apiVersion: v1
150+
kind: Secret
151+
metadata:
152+
name: gitops-test-runner-image-push
153+
namespace: rh-openshift-gitops-tenant
154+
type: kubernetes.io/dockerconfigjson
155+
data:
156+
.dockerconfigjson: <base64-encoded-docker-config>
157+
```
158+
159+
This should have push access to:
160+
`quay.io/redhat-user-workloads/rh-openshift-gitops-tenant/gitops-test-runner`
161+
162+
## Rollback Plan
163+
164+
If issues are found, the backup is at:
165+
```
166+
.tekton/integration-tests/pipelines/gitops-bundle-lowest-integration-test-pipeline.yaml.backup
167+
```
168+
169+
To rollback:
170+
```bash
171+
cd .tekton/integration-tests/pipelines/
172+
mv gitops-bundle-lowest-integration-test-pipeline.yaml gitops-bundle-lowest-integration-test-pipeline.yaml.new
173+
mv gitops-bundle-lowest-integration-test-pipeline.yaml.backup gitops-bundle-lowest-integration-test-pipeline.yaml
174+
```
175+
176+
## Next Steps
177+
178+
### Testing
179+
1. Create the `gitops-test-runner-image-push` secret
180+
2. Trigger a pipeline run
181+
3. Verify image builds successfully
182+
4. Verify tests pass using the built image
183+
184+
### Future Enhancements
185+
1. Add DAST scan to release pipeline (use `testType: dast`)
186+
2. Add smoke tests (`/scripts/run-smoke-tests.sh`)
187+
3. Add performance tests (`/scripts/run-performance-tests.sh`)
188+
4. Migrate catalog repo to use same test image
189+
190+
## Questions?
191+
192+
See:
193+
- `.tekton/test-image/README.md` - Local testing guide
194+
- `.tekton/tasks/build-test-image-kaniko.yaml` - Image build process
195+
- `.tekton/steps/install-operator.yaml` - Thin wrapper pattern
196+
- `.tekton/steps/run-tests.yaml` - Test routing logic

.tekton/integration-tests/pipelines/gitops-bundle-lowest-integration-test-pipeline.yaml

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ spec:
77
description: |
88
An integration test which provisions an ephemeral Hypershift cluster and deploys an Operator
99
bundle from a Konflux snapshot.
10+
workspaces:
11+
- name: shared-workspace
12+
description: Shared workspace for git clone and Kaniko builds
1013
params:
1114
- description: Snapshot of the application
1215
name: SNAPSHOT
@@ -165,6 +168,33 @@ spec:
165168
with open("$(results.STEP_ACTIONS_REVISION.path)", "w") as f:
166169
f.write(rev)
167170
171+
# Build test image using Kaniko - runs early so it's ready when needed
172+
- name: build-test-image
173+
runAfter:
174+
- extract-step-actions-ref
175+
taskRef:
176+
resolver: git
177+
params:
178+
- name: url
179+
value: $(tasks.extract-step-actions-ref.results.STEP_ACTIONS_URL)
180+
- name: revision
181+
value: $(tasks.extract-step-actions-ref.results.STEP_ACTIONS_REVISION)
182+
- name: pathInRepo
183+
value: .tekton/tasks/build-test-image-kaniko.yaml
184+
params:
185+
- name: SOURCE_URL
186+
value: $(tasks.extract-step-actions-ref.results.STEP_ACTIONS_URL)
187+
- name: SOURCE_REVISION
188+
value: $(tasks.extract-step-actions-ref.results.STEP_ACTIONS_REVISION)
189+
- name: IMAGE_EXPIRES_AFTER
190+
value: "7d"
191+
workspaces:
192+
- name: source
193+
workspace: shared-workspace
194+
- name: dockerconfig
195+
secret:
196+
secretName: gitops-test-runner-image-push
197+
168198
- name: parse-metadata
169199
taskRef:
170200
resolver: git
@@ -446,7 +476,10 @@ spec:
446476
runAfter:
447477
- provision-cluster
448478
- patch-bundle-images
479+
- build-test-image
449480
params:
481+
- name: testImage
482+
value: "$(tasks.build-test-image.results.IMAGE_URL)"
450483
- name: bundleImage
451484
value: "$(tasks.patch-bundle-images.results.patchedBundleImage)"
452485
- name: namespace
@@ -463,6 +496,8 @@ spec:
463496
value: $(tasks.extract-step-actions-ref.results.STEP_ACTIONS_REVISION)
464497
taskSpec:
465498
params:
499+
- name: testImage
500+
type: string
466501
- name: bundleImage
467502
type: string
468503
- name: namespace
@@ -507,14 +542,18 @@ spec:
507542
- name: revision
508543
value: $(params.STEP_ACTIONS_REVISION)
509544
- name: pathInRepo
510-
value: .tekton/steps/install-gitops-operator-bundle.yaml
545+
value: .tekton/steps/install-operator.yaml
511546
params:
512-
- name: installTimeout
513-
value: "$(params.INSTALL_TIMEOUT)"
547+
- name: testImage
548+
value: $(params.testImage)
549+
- name: installMethod
550+
value: bundle
514551
- name: bundleImage
515552
value: "$(params.bundleImage)"
516553
- name: namespace
517554
value: "openshift-gitops-operator"
555+
- name: installTimeout
556+
value: "$(params.installTimeout)"
518557
- name: credentials
519558
value: credentials
520559
- name: kubeconfig
@@ -523,6 +562,8 @@ spec:
523562
runAfter:
524563
- install-operator
525564
params:
565+
- name: testImage
566+
value: "$(tasks.build-test-image.results.IMAGE_URL)"
526567
- name: eaasSpaceSecretRef
527568
value: $(tasks.provision-eaas-space.results.secretRef)
528569
- name: clusterName
@@ -533,6 +574,8 @@ spec:
533574
value: $(tasks.extract-step-actions-ref.results.STEP_ACTIONS_REVISION)
534575
taskSpec:
535576
params:
577+
- name: testImage
578+
type: string
536579
- name: eaasSpaceSecretRef
537580
type: string
538581
- name: clusterName
@@ -571,13 +614,17 @@ spec:
571614
- name: revision
572615
value: $(params.STEP_ACTIONS_REVISION)
573616
- name: pathInRepo
574-
value: .tekton/steps/run-gitops-operator-e2e-minimal.yaml
617+
value: .tekton/steps/run-tests.yaml
575618
params:
619+
- name: testImage
620+
value: $(params.testImage)
621+
- name: testType
622+
value: e2e
576623
- name: credentials
577624
value: credentials
578625
- name: kubeconfig
579626
value: "$(steps.get-kubeconfig.results.kubeconfig)"
580-
- name: branch
627+
- name: testBranch
581628
value: master
582-
- name: test_dir
629+
- name: testDir
583630
value: "./test/openshift/e2e/ginkgo/parallel"

0 commit comments

Comments
 (0)