Skip to content

Commit 6c48650

Browse files
Merge pull request #228 from tkong-redhat/mnmo-boilerplate-update
Mnmo boilerplate update
2 parents c5bc662 + 9f6939a commit 6c48650

21 files changed

Lines changed: 2152 additions & 189 deletions

.ci-operator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
build_root_image:
22
name: boilerplate
33
namespace: openshift
4-
tag: image-v8.3.1
4+
tag: image-v8.3.4

OWNERS_ALIASES

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ aliases:
4343
- rolandmkunkel
4444
- petrkotas
4545
- zmird-r
46-
- hectorakemp
46+
- gvnnn
4747
srep-functional-team-rocket:
4848
- aliceh
4949
- anispate
@@ -84,9 +84,7 @@ aliases:
8484
srep-team-leads:
8585
- rafael-azevedo
8686
- iamkirkbater
87-
- rogbas
8887
- dustman9000
89-
- bng0y
9088
- bmeng
9189
- typeid
9290
sre-group-leads:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
image-v8.3.1
1+
image-v8.3.4
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2d33d0d7e46900852f04714d1ba676a10ecbb0ce
1+
0613e5c5f79aec861fd0afe53b6a9373b8d169d7

boilerplate/openshift/golang-osd-e2e/e2e-template.yml

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,10 @@ parameters:
88
required: true
99
- name: TEST_IMAGE
1010
required: true
11-
- name: OCM_CLIENT_ID
12-
required: false
13-
- name: OCM_CLIENT_SECRET
14-
required: false
1511
- name: OCM_CCS
1612
required: false
17-
- name: AWS_ACCESS_KEY_ID
18-
required: false
19-
- name: AWS_SECRET_ACCESS_KEY
20-
required: false
2113
- name: CLOUD_PROVIDER_REGION
2214
required: false
23-
- name: GCP_CREDS_JSON
24-
required: false
2515
- name: JOBID
2616
generate: expression
2717
from: "[0-9a-z]{7}"
@@ -32,7 +22,9 @@ parameters:
3222
value: 'osde2e-logs'
3323
- name: USE_EXISTING_CLUSTER
3424
value: 'TRUE'
35-
- name: CAD_PAGERDUTY_ROUTING_KEY
25+
- name: SLACK_NOTIFY
26+
required: false
27+
- name: SLACK_CHANNEL
3628
required: false
3729
objects:
3830
- apiVersion: batch/v1
@@ -44,6 +36,22 @@ objects:
4436
template:
4537
spec:
4638
restartPolicy: Never
39+
volumes:
40+
- name: ${OPERATOR_NAME}-sc
41+
secret:
42+
secretName: ${OPERATOR_NAME}-sc
43+
optional: true
44+
- name: osde2e-ocm-sc
45+
secret:
46+
secretName: osde2e-ocm-credentials
47+
- name: osde2e-aws-sc
48+
secret:
49+
secretName: osde2e-aws-credentials
50+
optional: true
51+
- name: osde2e-gcp-sc
52+
secret:
53+
secretName: osde2e-gcp-credentials
54+
optional: true
4755
containers:
4856
- name: osde2e
4957
image: quay.io/redhat-services-prod/osde2e-cicada-tenant/osde2e:latest
@@ -54,8 +62,24 @@ objects:
5462
- --only-health-check-nodes
5563
- --skip-destroy-cluster
5664
- --skip-must-gather
65+
- --log-analysis-enable
5766
- --configs
5867
- ${OSDE2E_CONFIGS}
68+
- --secret-locations
69+
- "/etc/external-secrets,/etc/osde2e-ocm-sc,/etc/osde2e-aws-sc,/etc/osde2e-gcp-sc"
70+
volumeMounts:
71+
- name: ${OPERATOR_NAME}-sc
72+
readOnly: true
73+
mountPath: "/etc/external-secrets"
74+
- name: osde2e-ocm-sc
75+
readOnly: true
76+
mountPath: "/etc/osde2e-ocm-sc"
77+
- name: osde2e-aws-sc
78+
readOnly: true
79+
mountPath: "/etc/osde2e-aws-sc"
80+
- name: osde2e-gcp-sc
81+
readOnly: true
82+
mountPath: "/etc/osde2e-gcp-sc"
5983
resources:
6084
requests:
6185
cpu: "300m"
@@ -67,29 +91,21 @@ objects:
6791
runAsNonRoot: true
6892
allowPrivilegeEscalation: false
6993
capabilities:
70-
drop: ["ALL"]
94+
drop: [ "ALL" ]
7195
seccompProfile:
7296
type: RuntimeDefault
7397
env:
74-
- name: AD_HOC_TEST_IMAGES
75-
value: ${TEST_IMAGE}:${IMAGE_TAG}
76-
- name: OCM_CLIENT_ID
77-
value: ${OCM_CLIENT_ID}
78-
- name: OCM_CLIENT_SECRET
79-
value: ${OCM_CLIENT_SECRET}
98+
- name: TEST_SUITES_YAML
99+
value: |-
100+
- image: ${TEST_IMAGE}:${IMAGE_TAG}
101+
slackChannel: ${SLACK_CHANNEL}
80102
- name: OCM_CCS
81103
value: ${OCM_CCS}
82-
- name: AWS_ACCESS_KEY_ID
83-
value: ${AWS_ACCESS_KEY_ID}
84-
- name: AWS_SECRET_ACCESS_KEY
85-
value: ${AWS_SECRET_ACCESS_KEY}
86104
- name: CLOUD_PROVIDER_REGION
87105
value: ${CLOUD_PROVIDER_REGION}
88-
- name: GCP_CREDS_JSON
89-
value: ${GCP_CREDS_JSON}
90106
- name: LOG_BUCKET
91107
value: ${LOG_BUCKET}
92108
- name: USE_EXISTING_CLUSTER
93109
value: ${USE_EXISTING_CLUSTER}
94-
- name: CAD_PAGERDUTY_ROUTING_KEY
95-
value: ${CAD_PAGERDUTY_ROUTING_KEY}
110+
- name: SLACK_NOTIFY
111+
value: ${SLACK_NOTIFY}

boilerplate/openshift/golang-osd-operator/Dockerfile.olm-registry

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM registry.redhat.io/openshift4/ose-operator-registry-rhel9:v4.19 AS builder
1+
FROM registry.redhat.io/openshift4/ose-operator-registry-rhel9:v4.21 AS builder
22
ARG SAAS_OPERATOR_DIR
33
COPY ${SAAS_OPERATOR_DIR} manifests
44
RUN initializer --permissive

boilerplate/openshift/golang-osd-operator/OWNERS_ALIASES

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ aliases:
4343
- rolandmkunkel
4444
- petrkotas
4545
- zmird-r
46-
- hectorakemp
46+
- gvnnn
4747
srep-functional-team-rocket:
4848
- aliceh
4949
- anispate
@@ -84,9 +84,7 @@ aliases:
8484
srep-team-leads:
8585
- rafael-azevedo
8686
- iamkirkbater
87-
- rogbas
8887
- dustman9000
89-
- bng0y
9088
- bmeng
9189
- typeid
9290
sre-group-leads:
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
# PKO Migration Script Tests
2+
3+
This directory contains comprehensive tests for the `olm_pko_migration.py` script.
4+
5+
## Test Files
6+
7+
### 1. `test_olm_pko_migration.py` - Python Unit Tests
8+
9+
Comprehensive unit tests for the migration script using Python's `unittest` framework.
10+
11+
**Test Coverage:**
12+
13+
- **Git Operations** (`TestGitOperations`)
14+
- Parsing git remotes from various formats (SSH, HTTPS)
15+
- Extracting GitHub URLs
16+
- Deriving operator names from repository URLs
17+
- Error handling for non-git repositories
18+
19+
- **Manifest Annotation** (`TestManifestAnnotation`)
20+
- Adding PKO phase annotations to manifests
21+
- Preserving existing annotations
22+
- Replacing container images with template variables
23+
- Handling edge cases (missing fields, etc.)
24+
25+
- **Manifest Processing** (`TestManifestProcessing`)
26+
- Phase assignment based on resource kind:
27+
- CRDs → `crds` phase
28+
- RBAC resources → `rbac` phase
29+
- Deployments → `deploy` phase with image templating
30+
- Services → `deploy` phase
31+
- Handling invalid YAML gracefully
32+
33+
- **File Discovery** (`TestFileDiscovery`)
34+
- Recursive and non-recursive file scanning
35+
- YAML file filtering (.yaml and .yml)
36+
- Handling nonexistent paths
37+
38+
- **PKO Manifest Generation** (`TestPKOManifestGeneration`)
39+
- PackageManifest structure validation
40+
- Phase definitions
41+
- Availability probes
42+
- Config schema
43+
44+
- **File Writing** (`TestFileWriting`)
45+
- Creating manifest files with correct names
46+
- Using `.gotmpl` extension for Deployments
47+
- Custom filename support
48+
- Skipping/forcing package kinds
49+
50+
- **Template Generation** (`TestTemplateGeneration`)
51+
- Dockerfile.pko generation
52+
- Tekton pipeline manifests (push and PR)
53+
- ClusterPackage template
54+
- Error handling (missing directories)
55+
56+
- **Integration Tests** (`TestIntegration`)
57+
- End-to-end conversion process
58+
- Verifying complete output structure
59+
- Checking all generated files
60+
61+
**Running the Python tests:**
62+
63+
```bash
64+
# Install dependencies (if not already installed)
65+
pip install pyyaml pytest
66+
67+
# Run all tests with verbose output
68+
python3 -m pytest boilerplate/openshift/golang-osd-operator/test_olm_pko_migration.py -v
69+
70+
# Run specific test class
71+
python3 -m pytest boilerplate/openshift/golang-osd-operator/test_olm_pko_migration.py::TestGitOperations -v
72+
73+
# Run specific test method
74+
python3 -m pytest boilerplate/openshift/golang-osd-operator/test_olm_pko_migration.py::TestManifestAnnotation::test_annotate_adds_phase_annotation -v
75+
76+
# Run with coverage report
77+
python3 -m pytest boilerplate/openshift/golang-osd-operator/test_olm_pko_migration.py --cov=olm_pko_migration --cov-report=html
78+
```
79+
80+
### 2. `test/case/convention/openshift/golang-osd-operator/08-pko-migration` - Bash Integration Test
81+
82+
Integration test following the boilerplate repository's test framework conventions.
83+
84+
**Test Coverage:**
85+
86+
- **Complete Migration Workflow**
87+
- Creating test operator structure
88+
- Running migration script
89+
- Verifying all generated files
90+
91+
- **PKO Manifest Validation**
92+
- PackageManifest structure and phases
93+
- Correct phase annotations on all resources
94+
- Collision protection annotations
95+
96+
- **Resource Type Handling**
97+
- CRDs annotated with `crds` phase
98+
- RBAC resources (ServiceAccount, ClusterRole) with `rbac` phase
99+
- Deployments with `deploy` phase and `.gotmpl` extension
100+
- Image templating in Deployments
101+
- Services with `deploy` phase
102+
103+
- **Cleanup Job Template**
104+
- Generated cleanup Job with proper structure
105+
- ServiceAccount, Role, RoleBinding, and Job resources
106+
- Correct phase annotations (`cleanup-rbac`, `cleanup-deploy`)
107+
108+
- **Recursive vs Non-Recursive Mode**
109+
- `--no-recursive` flag skips subdirectories
110+
- Default recursive mode includes all nested YAML files
111+
112+
- **Optional Component Generation**
113+
- Tekton pipeline generation (push and PR variants)
114+
- Dockerfile.pko generation
115+
- ClusterPackage template generation
116+
- Flag handling (`--no-tekton`, `--no-dockerfile`)
117+
118+
**Running the bash test:**
119+
120+
```bash
121+
# Run the specific PKO migration test
122+
./test/case/convention/openshift/golang-osd-operator/08-pko-migration
123+
124+
# Run all tests in the repository
125+
make test
126+
127+
# Run with preserved temp directories for debugging
128+
PRESERVE_TEMP_DIRS=1 ./test/case/convention/openshift/golang-osd-operator/08-pko-migration
129+
130+
# Run tests matching a pattern
131+
make test CASE_GLOB="*pko*"
132+
```
133+
134+
## Test Strategy
135+
136+
The test suite uses a two-tiered approach:
137+
138+
1. **Unit Tests (Python)**: Fast, isolated tests for individual functions and edge cases
139+
2. **Integration Tests (Bash)**: End-to-end validation of the complete migration workflow
140+
141+
This combination ensures:
142+
- Individual components work correctly in isolation
143+
- The complete system works as expected in realistic scenarios
144+
- Edge cases and error conditions are handled properly
145+
- The script integrates well with the boilerplate repository conventions
146+
147+
## Adding New Tests
148+
149+
### Adding Python Unit Tests
150+
151+
Add new test methods to the appropriate test class in `test_olm_pko_migration.py`:
152+
153+
```python
154+
class TestManifestProcessing(unittest.TestCase):
155+
def test_new_feature(self):
156+
"""Test description."""
157+
# Arrange
158+
manifest_str = "..."
159+
160+
# Act
161+
result = migration.some_function(manifest_str)
162+
163+
# Assert
164+
self.assertEqual(result, expected_value)
165+
```
166+
167+
### Adding Bash Integration Tests
168+
169+
Add new test sections to the `08-pko-migration` script:
170+
171+
```bash
172+
echo "Testing new feature"
173+
174+
# Setup
175+
# ... preparation ...
176+
177+
# Test
178+
python3 "${REPO_ROOT}/boilerplate/openshift/golang-osd-operator/olm_pko_migration.py" \
179+
... args ...
180+
181+
# Verify
182+
if [[ ! -f expected_file ]]; then
183+
err "Expected file was not created"
184+
fi
185+
```
186+
187+
## CI/CD Integration
188+
189+
The bash test is automatically run as part of the boilerplate repository's CI pipeline:
190+
- Triggered on pull requests
191+
- Runs in containerized environment
192+
- Must pass for PR approval
193+
194+
To run the same checks locally:
195+
```bash
196+
make container-pr-check
197+
```
198+
199+
## Troubleshooting
200+
201+
### Tests Failing Locally
202+
203+
1. **Check Python dependencies**: Ensure `pyyaml` is installed
204+
2. **Git configuration**: Tests require a git repository with configured user
205+
3. **File permissions**: Ensure test files are executable (`chmod +x`)
206+
207+
### Debugging Test Failures
208+
209+
```bash
210+
# For bash tests, preserve temp directories
211+
PRESERVE_TEMP_DIRS=1 ./test/case/convention/openshift/golang-osd-operator/08-pko-migration
212+
213+
# For Python tests, use verbose mode
214+
python3 -m pytest test_olm_pko_migration.py -vv -s
215+
```
216+
217+
### Common Issues
218+
219+
**ImportError: No module named 'yaml'**
220+
- Solution: `pip install pyyaml`
221+
222+
**Git errors in tests**
223+
- Solution: Ensure you're in a git repository or the test creates one properly
224+
225+
**Permission denied**
226+
- Solution: `chmod +x test/case/convention/openshift/golang-osd-operator/08-pko-migration`

0 commit comments

Comments
 (0)