|
| 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 |
0 commit comments