Skip to content

Commit 50ff4e0

Browse files
Merge pull request #787 from irinamihai/extend-openapi-schema
CNF-23534: Add automated OpenAPI schema generation for PolicyGenerator list merging
2 parents 58b632e + 3cb1a09 commit 50ff4e0

10 files changed

Lines changed: 1360 additions & 317 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: OpenAPI Schema Check
2+
3+
on:
4+
schedule:
5+
# Run daily at 7:00 AM UTC
6+
- cron: '0 7 * * *'
7+
workflow_dispatch: # Allow manual trigger
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
check-schemas:
15+
name: Check OpenAPI Schemas
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
20+
with:
21+
persist-credentials: false
22+
23+
- name: Install dependencies
24+
run: |
25+
YQ_VERSION="v4.53.2"
26+
YQ_SHA256="d56bf5c6819e8e696340c312bd70f849dc1678a7cda9c2ad63eebd906371d56b"
27+
curl -sL "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" -o /usr/local/bin/yq
28+
echo "${YQ_SHA256} /usr/local/bin/yq" | sha256sum -c -
29+
chmod +x /usr/local/bin/yq
30+
pip install PyYAML==6.0.2
31+
32+
- name: Regenerate OpenAPI schemas
33+
run: make generate-openapi-schemas
34+
35+
- name: Create Pull Request
36+
uses: peter-evans/create-pull-request@22a9089034f40e5a961c8808d113e2c98fb63676 # v7.0.11
37+
with:
38+
token: ${{ secrets.GITHUB_TOKEN }}
39+
commit-message: 'chore: Update OpenAPI schemas for PolicyGenerator'
40+
committer: GitHub Actions Bot <actions@github.com>
41+
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
42+
branch: update-openapi-schemas
43+
delete-branch: true
44+
title: 'Update OpenAPI schemas for PolicyGenerator list merging'
45+
body: |
46+
## Automated OpenAPI Schema Update
47+
48+
The `schema.openapi` files used by ACM PolicyGenerator for strategic
49+
list merging are out of date with respect to the current Subscription
50+
channels and upstream CRDs.
51+
52+
### Changed files
53+
- `hack/crd-schema-config.json` — updated channels / refs
54+
- `telco-ran/.../acmpolicygenerator/schema.openapi`
55+
- `telco-core/configuration/schema.openapi`
56+
57+
### How to Review
58+
- Verify the updated refs match the expected operator release branches
59+
- Check that merge keys are still correct for the new CRD versions
60+
61+
---
62+
*This PR was automatically generated by `make generate-openapi-schemas`.*
63+
labels: |
64+
automated

Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,31 @@ test-kustomize: ## Validate all kustomization.yaml files can build
119119
test-shellcheck: ## Validate shell scripts with shellcheck
120120
./hack/test-shellcheck.sh
121121

122+
.PHONY: generate-schema-config
123+
generate-schema-config: ## Regenerate hack/crd-schema-config.json from Subscription CRs
124+
python3 hack/generate-schema-config.py
125+
126+
.PHONY: generate-openapi-schemas
127+
generate-openapi-schemas: generate-schema-config ## Regenerate schema.openapi files from CRDs for ACM PolicyGenerator
128+
python3 hack/extract-schema.py --config hack/crd-schema-config.json --component ran \
129+
-o telco-ran/configuration/argocd/example/acmpolicygenerator/schema.openapi
130+
cp telco-ran/configuration/argocd/example/acmpolicygenerator/schema.openapi \
131+
telco-ran/configuration/argocd/example/acmpolicygenerator/hub-side-templating/schema.openapi
132+
python3 hack/extract-schema.py --config hack/crd-schema-config.json --component core \
133+
-o telco-core/configuration/schema.openapi
134+
135+
.PHONY: check-openapi-schemas
136+
check-openapi-schemas: generate-openapi-schemas ## Verify schema.openapi files are up-to-date
137+
@if ! git diff --exit-code hack/crd-schema-config.json \
138+
telco-ran/configuration/argocd/example/acmpolicygenerator/schema.openapi \
139+
telco-ran/configuration/argocd/example/acmpolicygenerator/hub-side-templating/schema.openapi \
140+
telco-core/configuration/schema.openapi; then \
141+
echo ""; \
142+
echo "ERROR: OpenAPI schema files are out of date."; \
143+
echo "Run 'make generate-openapi-schemas' and commit the result."; \
144+
exit 1; \
145+
fi
146+
122147
ci-validate: lintCheck check-reference-core check-reference-ran check-reference-hub
123148

124149
.PHONY: check-reference-core

VERSION_UPDATE_GUIDE.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,29 @@ patches:
7777
- Update PolicyGenerator placement specifications which use version
7878
- Policy generator policy names MUST use version numbers which match the OpenShift version number (e.g., `core-cluster-config-4.23`)
7979

80-
### 3. Image references
80+
### 3. OpenAPI Schema for PolicyGenerator List Merging
81+
82+
Regenerate the OpenAPI schemas for PolicyGenerator list merging:
83+
84+
```bash
85+
make generate-openapi-schemas
86+
```
87+
88+
This first regenerates `hack/crd-schema-config.json` from the Subscription CRs
89+
(picking up updated channels and refs), then regenerates the `schema.openapi`
90+
files in `telco-ran` and `telco-core` from upstream CRDs. If an operator's
91+
GitHub branch naming convention does not match its Subscription channel (e.g.,
92+
the branch is `v6.5` instead of `release-6.5`), manually update the `ref` field
93+
for that CRD entry in `hack/crd-schema-config.json`.
94+
95+
### 4. Image references
8196
The reference configuration includes image pullspecs in several places which use version specific tags for the image. These must be updated. These pullspecs may be in the reference-crs or in PolicyGenerator patches. Common places where image tags are used include:
8297
- CatalogSource images -- Update both the reference-cr and the PolicyGenerator overlay patch to align with the OpenShift version
8398
- Numa Resources Operator (NROP) -- Update image spec in the Scheduler (sched.yaml) and PolicyGenerator overlay patch to align with the OpenShift version
8499
- Upgrade policy -- Update the version and image pull spec in the PolicyGenerator overlay patch to align with the OpenShift version
85100
- The telco-hub reference includes a plugins Policy CR with image pullspec references which must be updated to the correct versions. The ztp-site-generate image aligns with OpenShift. The multicluster-operator image aligns with MCE.
86101

87-
### 4. ACM AgentServiceConfig
102+
### 5. ACM AgentServiceConfig
88103

89104
Add new OpenShift version osImages entries and remove the oldest version to maintain only 3 versions:
90105

@@ -115,15 +130,15 @@ osImages:
115130

116131
**Note**: The kube-compare variant uses templating and doesn't require manual entry removal - it renders from the actual config.
117132

118-
### 5. Mirror Registry Configuration
133+
### 6. Mirror Registry Configuration
119134

120135
**File**: `telco-hub/install/mirror-registry/imageset-config.yaml`
121136

122137
The versions of each component in the mirror configuration must be updated. These versions must align with the changes made in corresponding Subscription updates.
123138
- Mirroring versions MUST match the Subscription versions for each operator
124139
- The additional images MUST include the images specified in the Hub reference plugins Policy
125140

126-
### 6. Installation Examples (ClusterInstance)
141+
### 7. Installation Examples (ClusterInstance)
127142

128143
Find all ClusterInstance CRs (`kind: ClusterInstance`) and update clusterImageSetNameRef to align with the OpenShift version:
129144

@@ -138,7 +153,7 @@ Find all ClusterInstance CRs (`kind: ClusterInstance`) and update clusterImageSe
138153
Change: `clusterImageSetNameRef: "openshift-4.22"` → `"openshift-4.23"`
139154

140155

141-
### 7. Other locations
156+
### 8. Other locations
142157
Other versioning information to be reviewed and updated
143158
- Annotations added in PolicyGenerator overlay patches to trigger non-compliance, eg `noop-for-triggering-noncompliance: "22"`
144159
- Descriptive text in metadata.yaml, eg `This reference was designed for OpenShift 4.22`

hack/crd-schema-config.json

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
{
2+
"_comment": [
3+
"Single source of truth for OpenAPI schema generation.",
4+
"Static fields (source, merge_keys, version, package_name, ref_rule)",
5+
"are manually maintained.",
6+
"Dynamic fields (subscription_channel, components, source.github.ref)",
7+
"are updated by: python3 hack/generate-schema-config.py",
8+
"To regenerate schemas: make generate-openapi-schemas"
9+
],
10+
"crds": [
11+
{
12+
"name": "PtpConfig",
13+
"package_name": "ptp-operator",
14+
"ref_rule": "release-ocp",
15+
"components": [
16+
"ran"
17+
],
18+
"subscription_channel": "stable",
19+
"source": {
20+
"github": {
21+
"owner": "openshift",
22+
"repo": "ptp-operator",
23+
"ref": "release-4.22",
24+
"path": "config/crd/bases/ptp.openshift.io_ptpconfigs.yaml"
25+
}
26+
},
27+
"merge_keys": {
28+
"spec.profile": "name",
29+
"spec.recommend": "profile",
30+
"status.matchList": "nodeName"
31+
}
32+
},
33+
{
34+
"name": "ClusterLogForwarder",
35+
"package_name": "cluster-logging",
36+
"ref_rule": "release-channel",
37+
"components": [
38+
"core",
39+
"ran"
40+
],
41+
"subscription_channel": "stable-6.5",
42+
"source": {
43+
"github": {
44+
"owner": "openshift",
45+
"repo": "cluster-logging-operator",
46+
"ref": "release-6.5",
47+
"path": "config/crd/bases/observability.openshift.io_clusterlogforwarders.yaml"
48+
}
49+
},
50+
"merge_keys": {
51+
"spec.filters": "name",
52+
"spec.inputs": "name",
53+
"spec.outputs": "name",
54+
"spec.pipelines": "name"
55+
}
56+
},
57+
{
58+
"name": "Tuned",
59+
"ref_rule": "release-ocp",
60+
"components": [
61+
"core",
62+
"ran"
63+
],
64+
"subscription_channel": "built-in (NTO)",
65+
"source": {
66+
"github": {
67+
"owner": "openshift",
68+
"repo": "cluster-node-tuning-operator",
69+
"ref": "release-4.22",
70+
"path": "manifests/20-tuned.crd.yaml"
71+
}
72+
},
73+
"merge_keys": {
74+
"spec.profile": "name",
75+
"spec.recommend": "profile"
76+
}
77+
},
78+
{
79+
"name": "PerformanceProfile",
80+
"version": "v2",
81+
"ref_rule": "release-ocp",
82+
"components": [
83+
"core",
84+
"ran"
85+
],
86+
"subscription_channel": "built-in (NTO)",
87+
"source": {
88+
"github": {
89+
"owner": "openshift",
90+
"repo": "cluster-node-tuning-operator",
91+
"ref": "release-4.22",
92+
"path": "manifests/20-performance-profile.crd.yaml"
93+
}
94+
},
95+
"merge_keys": {}
96+
},
97+
{
98+
"name": "NUMAResourcesOperator",
99+
"package_name": "numaresources-operator",
100+
"ref_rule": "release-ocp",
101+
"components": [
102+
"core"
103+
],
104+
"subscription_channel": "4.22",
105+
"source": {
106+
"github": {
107+
"owner": "openshift-kni",
108+
"repo": "numaresources-operator",
109+
"ref": "release-4.22",
110+
"path": "config/crd/bases/nodetopology.openshift.io_numaresourcesoperators.yaml"
111+
}
112+
},
113+
"merge_keys": {
114+
"spec.nodeGroups": "poolName"
115+
}
116+
},
117+
{
118+
"name": "ImageDigestMirrorSet",
119+
"ref_rule": "release-ocp",
120+
"components": [
121+
"core",
122+
"ran"
123+
],
124+
"subscription_channel": "built-in (OCP)",
125+
"source": {
126+
"github": {
127+
"owner": "openshift",
128+
"repo": "api",
129+
"ref": "release-4.22",
130+
"path": "config/v1/zz_generated.crd-manifests/0000_10_config-operator_01_imagedigestmirrorsets.crd.yaml"
131+
}
132+
},
133+
"merge_keys": {
134+
"spec.imageDigestMirrors": "source"
135+
}
136+
}
137+
]
138+
}

0 commit comments

Comments
 (0)