Skip to content

Commit 32c8b6d

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.
1 parent ace3aed commit 32c8b6d

2 files changed

Lines changed: 113 additions & 0 deletions

File tree

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