Skip to content

Commit 4a00e99

Browse files
committed
Add CRD size tracking workflow and badge
Adds a new GitHub Actions workflow (.github/workflows/crd-size-badge.yaml) that monitors the JSON size of the OpenStackControlPlane CRD (core.openstack.org_openstackcontrolplanes.yaml) to help guard against approaching the 1.5MB etcd object size limit. Workflow behavior: - Runs on pushes and pull requests to main and release (fr) branches. - Converts the CRD YAML to compact JSON and measures its byte size. - Classifies the size into thresholds: green (< 300KB) — comfortable yellow (300-400KB) — growing orange (400-750KB) — concerning red (> 750KB) — approaching etcd limit - On pull requests: posts (or updates) a comment with a size report showing the current size, base branch size, and percentage change. - On push to main/release branches: updates a dynamic badge via a GitHub gist using schneegans/dynamic-badges-action. Also adds the corresponding CRD Size badge to README.md alongside the existing CI badges. Jira: OSPRH-27160
1 parent ace3aed commit 4a00e99

2 files changed

Lines changed: 116 additions & 0 deletions

File tree

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: CRD Size Badge
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- '[0-9]+.[0-9]+-fr[0-9]+'
8+
pull_request:
9+
branches:
10+
- main
11+
- '[0-9]+.[0-9]+-fr[0-9]+'
12+
13+
permissions:
14+
pull-requests: write
15+
16+
jobs:
17+
crd-size:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Install yq
24+
uses: mikefarah/yq@v4
25+
26+
- name: Compute CRD JSON size
27+
id: size
28+
run: |
29+
CRD_FILE="config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml"
30+
SIZE=$(yq eval -o=json "$CRD_FILE" | jq -c . | wc -c)
31+
echo "bytes=$SIZE" >> "$GITHUB_OUTPUT"
32+
33+
if [ "$SIZE" -lt 307200 ]; then
34+
echo "color=green" >> "$GITHUB_OUTPUT"
35+
echo "status=comfortable" >> "$GITHUB_OUTPUT"
36+
elif [ "$SIZE" -lt 409600 ]; then
37+
echo "color=yellow" >> "$GITHUB_OUTPUT"
38+
echo "status=growing" >> "$GITHUB_OUTPUT"
39+
elif [ "$SIZE" -lt 768000 ]; then
40+
echo "color=orange" >> "$GITHUB_OUTPUT"
41+
echo "status=concerning" >> "$GITHUB_OUTPUT"
42+
else
43+
echo "color=red" >> "$GITHUB_OUTPUT"
44+
echo "status=approaching etcd limit" >> "$GITHUB_OUTPUT"
45+
fi
46+
47+
# Human-readable size
48+
if [ "$SIZE" -ge 1048576 ]; then
49+
HUMAN="$(awk "BEGIN {printf \"%.1f\", $SIZE/1048576}")MB"
50+
else
51+
HUMAN="$(awk "BEGIN {printf \"%.0f\", $SIZE/1024}")KB"
52+
fi
53+
echo "human=$HUMAN" >> "$GITHUB_OUTPUT"
54+
55+
- name: Compute base branch size
56+
if: github.event_name == 'pull_request'
57+
id: base_size
58+
run: |
59+
CRD_FILE="config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml"
60+
git fetch origin "${{ github.base_ref }}" --depth=1
61+
BASE_SIZE=$(git show "origin/${{ github.base_ref }}:${CRD_FILE}" | yq eval -o=json - | jq -c . | wc -c)
62+
echo "bytes=$BASE_SIZE" >> "$GITHUB_OUTPUT"
63+
64+
CHANGE=$(awk "BEGIN {if ($BASE_SIZE == 0) printf \"N/A\"; else printf \"%+.2f\", ((${{ steps.size.outputs.bytes }} - $BASE_SIZE) / $BASE_SIZE) * 100}")
65+
echo "change=$CHANGE" >> "$GITHUB_OUTPUT"
66+
67+
- name: Find existing comment
68+
if: github.event_name == 'pull_request'
69+
uses: peter-evans/find-comment@v3
70+
id: find_comment
71+
with:
72+
issue-number: ${{ github.event.pull_request.number }}
73+
comment-author: 'github-actions[bot]'
74+
body-includes: '<!-- crd-size-badge -->'
75+
76+
- name: Post or update PR comment
77+
if: github.event_name == 'pull_request'
78+
uses: peter-evans/create-or-update-comment@v4
79+
with:
80+
comment-id: ${{ steps.find_comment.outputs.comment-id }}
81+
issue-number: ${{ github.event.pull_request.number }}
82+
edit-mode: replace
83+
body: |
84+
<!-- crd-size-badge -->
85+
## OpenStackControlPlane CRD Size Report
86+
87+
| Metric | Value |
88+
|--------|-------|
89+
| **CRD JSON size** | ${{ steps.size.outputs.bytes }} bytes (${{ steps.size.outputs.human }}) |
90+
| **Base branch size** | ${{ steps.base_size.outputs.bytes }} bytes |
91+
| **Change** | ${{ steps.base_size.outputs.change }}% |
92+
| **Status** | ${{ steps.size.outputs.color }} — ${{ steps.size.outputs.status }} |
93+
94+
<details>
95+
<summary>Threshold reference</summary>
96+
97+
| Color | Range | Meaning |
98+
|-------|-------|---------|
99+
| :green_circle: green | < 300KB | Comfortable |
100+
| :yellow_circle: yellow | 300–400KB | Growing |
101+
| :orange_circle: orange | 400–750KB | Concerning |
102+
| :red_circle: red | > 750KB | Approaching 1.5MB etcd limit (cut in half to allow space for update) |
103+
104+
</details>
105+
106+
- name: Update badge gist
107+
if: github.event_name == 'push'
108+
uses: schneegans/dynamic-badges-action@v1.7.0
109+
with:
110+
auth: ${{ secrets.GIST_SECRET }}
111+
gistID: ${{ vars.GIST_ID }}
112+
filename: crd-size-${{ github.ref_name }}.json
113+
label: CRD Size
114+
message: ${{ steps.size.outputs.human }}
115+
color: ${{ steps.size.outputs.color }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![CodeQL](https://github.com/openstack-k8s-operators/openstack-operator/actions/workflows/codeql.yml/badge.svg)](https://github.com/openstack-k8s-operators/openstack-operator/actions/workflows/codeql.yml)
44
[![CRD sync check main](https://github.com/openstack-k8s-operators/openstack-operator/actions/workflows/crd-sync-check.yaml/badge.svg)](https://github.com/openstack-k8s-operators/openstack-operator/actions/workflows/crd-sync-check.yaml)
55
[![CRD sync check latest fr](https://github.com/openstack-k8s-operators/openstack-operator/actions/workflows/crd-sync-check-fr.yaml/badge.svg)](https://github.com/openstack-k8s-operators/openstack-operator/actions/workflows/crd-sync-check-fr.yaml)
6+
[![CtrlPlane CRD Size](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/openstack-k8s-ci-robot/cb95c1626e1946e428bed7ee50a73348/raw/crd-size-main.json)](https://github.com/openstack-k8s-ci-robot/openstack-operator/actions/workflows/crd-size-badge.yaml)
67

78
This is the primary operator for OpenStack. It is a "meta" operator, meaning it
89
serves to coordinate the other operators for OpenStack by watching and configuring

0 commit comments

Comments
 (0)