Skip to content

Add check-gen target and fix check-codegen CI to catch stale helm - #130

Open
stefanhipfel wants to merge 1 commit into
mainfrom
add-helm-codegen-check
Open

Add check-gen target and fix check-codegen CI to catch stale helm#130
stefanhipfel wants to merge 1 commit into
mainfrom
add-helm-codegen-check

Conversation

@stefanhipfel

@stefanhipfel stefanhipfel commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Adds a check-gen Makefile target (generate manifests docs helm fmt) and updates check-codegen.yml to use it, so PRs that forget to run make helm are caught in CI.

Depends on #131.

Same setup as in metal-operator!

Signed-off-by: Stefan Hipfel stefan.hipfel@sap.com

Summary by CodeRabbit

  • Chores
    • Improved automated checks to verify generated code and related artifacts.
    • Added a dedicated command for validating generated files, manifests, documentation, Helm assets, and formatting.
    • Renamed workflow labels to clarify that the job performs code-generation checks.
    • Enhanced generated Helm assets to support manager environment settings, namespace configuration, and configurable ports.

@stefanhipfel
stefanhipfel requested a review from a team as a code owner July 29, 2026 11:14
@github-actions github-actions Bot added the bug Something isn't working label Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Makefile patches generated Helm output and adds a check-gen target for generation checks. The codegen workflow invokes make check-gen instead of make generate.

Changes

Code generation checks

Layer / File(s) Summary
Patch generated Helm output
Makefile
The helm recipe adds POD_NAMESPACE, manager environment values, environment overrides, and manager ports. Each patch is verified.
Add code generation check target
Makefile
Adds the phony check-gen target with generate, manifests, docs, helm, and fmt prerequisites.
Run code generation checks in CI
.github/workflows/check-codegen.yml
Keeps Go setup and changes the workflow command from make generate to make check-gen.

Estimated code review effort: 2 (Simple) | ~15 minutes

Suggested reviewers: afritzler

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the new check-gen target and the CI change that detects stale Helm files.
Description check ✅ Passed The description clearly explains the Makefile and CI changes, but it omits the template headings and a Fixes reference.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-helm-codegen-check

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/check-codegen.yml:
- Around line 18-19: Update the failure hint in the code generation check
workflow to recommend `make check-gen`, matching the command executed by the
“Run code gen checks” step. Replace the outdated incomplete command while
preserving the surrounding failure guidance.
- Around line 18-19: Update the workflow’s actions/checkout step to set
persist-credentials to false before the Run code gen checks step, preserving the
existing checkout behavior and avoiding persisted credentials for PR-controlled
code.

In `@Makefile`:
- Around line 120-121: Update the check-gen target so generate, manifests, docs,
helm, and fmt execute in a guaranteed sequential order rather than as
independent parallel prerequisites. Preserve the existing subtargets and
check-gen purpose while encoding the ordering explicitly in the Makefile.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 46c379d3-4953-43ea-8c39-8a20fef369e4

📥 Commits

Reviewing files that changed from the base of the PR and between 585c808 and 9092b86.

📒 Files selected for processing (2)
  • .github/workflows/check-codegen.yml
  • Makefile

Comment on lines +18 to +19
- name: Run code gen checks
run: make check-gen

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Update the failure hint to use make check-gen.

The new target also runs manifests and formatting checks, but the message below still recommends the old incomplete command. Point contributors to the exact command that CI now executes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/check-codegen.yml around lines 18 - 19, Update the failure
hint in the code generation check workflow to recommend `make check-gen`,
matching the command executed by the “Run code gen checks” step. Replace the
outdated incomplete command while preserving the surrounding failure guidance.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Disable persisted checkout credentials before running PR-controlled code.

make check-gen executes the repository’s Makefile. Since this is a pull-request check, a malicious change could read the token persisted by actions/checkout and exfiltrate it. Add persist-credentials: false to the checkout step; no later step appears to require authenticated Git operations.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/check-codegen.yml around lines 18 - 19, Update the
workflow’s actions/checkout step to set persist-credentials to false before the
Run code gen checks step, preserving the existing checkout behavior and avoiding
persisted credentials for PR-controlled code.

Source: Linters/SAST tools

Comment thread Makefile
Comment on lines +120 to +121
.PHONY: check-gen
check-gen: generate manifests docs helm fmt ## Run code generation, manifests, docs, helm, and formatting.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Serialize the generation steps for parallel-safe execution.

These are independent prerequisites, not a guaranteed chain. Under make -j check-gen, fmt can run while generators modify files, producing races or nondeterministic diffs. Run the subtargets sequentially or encode their dependencies explicitly.

Proposed fix
 .PHONY: check-gen
-check-gen: generate manifests docs helm fmt ## Run code generation, manifests, docs, helm, and formatting.
+check-gen: ## Run code generation, manifests, docs, helm, and formatting.
+	$(MAKE) generate
+	$(MAKE) manifests
+	$(MAKE) docs
+	$(MAKE) helm
+	$(MAKE) fmt
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.PHONY: check-gen
check-gen: generate manifests docs helm fmt ## Run code generation, manifests, docs, helm, and formatting.
.PHONY: check-gen
check-gen: ## Run code generation, manifests, docs, helm, and formatting.
$(MAKE) generate
$(MAKE) manifests
$(MAKE) docs
$(MAKE) helm
$(MAKE) fmt
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Makefile` around lines 120 - 121, Update the check-gen target so generate,
manifests, docs, helm, and fmt execute in a guaranteed sequential order rather
than as independent parallel prerequisites. Preserve the existing subtargets and
check-gen purpose while encoding the ordering explicitly in the Makefile.

@stefanhipfel
stefanhipfel requested a review from afritzler July 29, 2026 12:26
@stefanhipfel
stefanhipfel force-pushed the add-helm-codegen-check branch from 9092b86 to 992ab99 Compare August 4, 2026 08:19

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/check-codegen.yml:
- Around line 11-19: Add workflow-level read-only permissions to the code
generation workflow by setting contents access to read near the workflow
metadata, before jobs such as the existing “Run code gen checks” steps. Keep the
checkout, Go setup, and make check-gen behavior unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 75e7be12-0d3f-4a92-a23b-cdd2a44e1f28

📥 Commits

Reviewing files that changed from the base of the PR and between 9092b86 and 992ab99.

📒 Files selected for processing (2)
  • .github/workflows/check-codegen.yml
  • Makefile

Comment on lines +11 to +19
name: Run code generation checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: 'go.mod'
- name: Run make generate
run: make generate
- name: Run code gen checks
run: make check-gen

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== workflow file ==="
cat -n .github/workflows/check-codegen.yml

echo "=== workflow refs to permissions / pull_request / branches ==="
rg -n "permission|workflow_dispatch|pull_request|branches:|pull_request_target|make check-gen|actions/checkout|actions/setup-go" .github/workflows/check-codegen.yml .github/workflows || true

echo "=== other workflows with explicit permissions for reference ==="
python3 - <<'PY'
from pathlib import Path
for p in sorted(Path(".github/workflows").glob("*.yml")) + sorted(Path(".github/workflows").glob("*.yaml")):
    text=p.read_text()
    print("\n---", p)
    for i,line in enumerate(text.splitlines(),1):
        if "permissions:" in line or "pull_request" in line or "workflow_dispatch" in line:
            print(f"{i}: {line}")
PY

Repository: ironcore-dev/metal-maintenance-operator

Length of output: 6467


Security Misconfiguration (CWE-732): Incorrect Permission Assignment for Critical Resource

Reachability: External

Set explicit read-only workflow permissions.

This pull_request workflow runs untrusted branch code, including a run step in the checked-out source. Add permissions: contents: read at workflow scope so the GITHUB_TOKEN does not rely on repository defaults.

🧰 Tools
🪛 GitHub Check: CodeQL

[warning] 11-27: Workflow does not contain permissions
Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {{contents: read}}

🪛 zizmor (1.28.0)

[warning] 14-14: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false

(artipacked)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/check-codegen.yml around lines 11 - 19, Add workflow-level
read-only permissions to the code generation workflow by setting contents access
to read near the workflow metadata, before jobs such as the existing “Run code
gen checks” steps. Keep the checkout, Go setup, and make check-gen behavior
unchanged.

Source: Linters/SAST tools

- Add check-gen Makefile target (generate manifests docs helm fmt)
- Update check-codegen.yml to use check-gen
- Add patches to helm target to re-apply POD_NAMESPACE env and ports
  templating after kubebuilder regenerates manager.yaml
- Sync dist/chart/templates/manager/manager.yaml with make helm output

Signed-off-by: Stefan Hipfel <stefan.hipfel@sap.com>
@stefanhipfel
stefanhipfel force-pushed the add-helm-codegen-check branch from 992ab99 to afec5f5 Compare August 4, 2026 09:46

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
Makefile (1)

120-121: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Serialize check-gen prerequisites; parallel runs remain unsafe.

check-gen still lists generate manifests docs helm fmt as parallel prerequisites. Under make -j check-gen, fmt can run while a generator still modifies files, producing races or nondeterministic diffs. This was flagged in a prior review and is unresolved in this code.

Proposed fix
 .PHONY: check-gen
-check-gen: generate manifests docs helm fmt ## Run code generation, manifests, docs, helm, and formatting.
+check-gen: ## Run code generation, manifests, docs, helm, and formatting.
+	$(MAKE) generate
+	$(MAKE) manifests
+	$(MAKE) docs
+	$(MAKE) helm
+	$(MAKE) fmt
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Makefile` around lines 120 - 121, Update the check-gen target so generate,
manifests, docs, helm, and fmt execute in the required serialized order rather
than as parallel prerequisites, while preserving the target’s existing behavior
and description.
🧹 Nitpick comments (1)
Makefile (1)

285-302: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the embedded python3/sed patches into a dedicated script.

Both patches embed multi-layer escaping directly in the Makefile: Make's $$, the shell's \$, and Python single-quoted strings all interact in the same line (for example \$$k on line 292). Auditing the escaping correctly, as this review had to do, requires tracing all three layers. A dedicated hack/patch-helm-chart.py (or similar) script, invoked from the helm target, would keep the same guarded, fail-loud behavior while being easier to read, lint, and unit test, and would have caught the sed/BSD portability issue directly during review.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Makefile` around lines 285 - 302, Extract the embedded Python and sed logic
from the helm target’s manager environment and ports patch blocks into a
dedicated script such as hack/patch-helm-chart.py. Have the Makefile invoke that
script while preserving the existing idempotent guards, validation failures, and
generated manager.yaml output, including POD_NAMESPACE, env/envOverrides, and
values-driven ports handling. Ensure the script avoids non-portable sed behavior
and keeps the patch logic readable and testable.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Makefile`:
- Around line 296-302: Make the ports patch in the Makefile portable across GNU
and BSD sed by replacing the current multiline sed replacement in the manager
ports patch block with Python, pre-expanded newline handling, or another
portable method. Preserve the existing Values-driven template content and keep
the post-patch validation that reports “ports patch not applied.”

---

Duplicate comments:
In `@Makefile`:
- Around line 120-121: Update the check-gen target so generate, manifests, docs,
helm, and fmt execute in the required serialized order rather than as parallel
prerequisites, while preserving the target’s existing behavior and description.

---

Nitpick comments:
In `@Makefile`:
- Around line 285-302: Extract the embedded Python and sed logic from the helm
target’s manager environment and ports patch blocks into a dedicated script such
as hack/patch-helm-chart.py. Have the Makefile invoke that script while
preserving the existing idempotent guards, validation failures, and generated
manager.yaml output, including POD_NAMESPACE, env/envOverrides, and
values-driven ports handling. Ensure the script avoids non-portable sed behavior
and keeps the patch logic readable and testable.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6703eec2-4ef3-40c4-8f5f-7cd068fc87f7

📥 Commits

Reviewing files that changed from the base of the PR and between 992ab99 and afec5f5.

⛔ Files ignored due to path filters (1)
  • dist/chart/templates/manager/manager.yaml is excluded by !**/dist/**
📒 Files selected for processing (2)
  • .github/workflows/check-codegen.yml
  • Makefile

Comment thread Makefile
Comment on lines +296 to +302
@# Patch manager ports: replace static [] with values-driven template
@grep -qF ' {{- with .Values.manager.ports }}' \
dist/chart/templates/manager/manager.yaml || { \
sed -i.bak 's/^ ports: \[\]$$/ ports:\n {{- with .Values.manager.ports }}\n {{- toYaml . | nindent 8 }}\n {{- else }}\n []\n {{- end }}/' \
dist/chart/templates/manager/manager.yaml && rm -f dist/chart/templates/manager/manager.yaml.bak; \
grep -qF ' {{- with .Values.manager.ports }}' dist/chart/templates/manager/manager.yaml || { echo 'ports patch not applied' >&2; exit 1; }; \
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Makefile context =="
sed -n '280,308p' Makefile | cat -n

echo
echo "== Tooling declarations/available sed versions =="
git ls-files | rg '(^|^/)(Makefile|docker-compose|Dockerfile|Taskfile|\.github/workflows/.*\.ya?ml|README\.)' || true
printf '\nGNU sed -V present? '
(command -v g sed >/dev/null 2>&1 && g sed --version | head -1) || printf 'no\n'
printf 'sed version: '
(command -v sed >/dev/null 2>&1 && sed --version 2>&1 | head -1 || true) || true

echo
echo "== Static sed behavior probe on GNU sed (if present) =="
python3 - <<'PY'
from pathlib import Path
import subprocess, tempfile, textwrap, sys, os

sample = textwrap.dedent("""\
a b
  c: []
  d: []
z
""")

old = subprocess.run(['sed', '--version'], capture_output=True, text=True)
print("sed_version", old.stdout.splitlines()[0] if old.returncode == 0 else "n/a")

cmd = ["sed", "-e", "s/.*c: \\[\\].*/NEWLINE:/", "-e", "s/.*d: \\[\\].*/NEWLINE:/", "-"]
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
out, err = p.communicate(sample)
print("posix_imitation_probe: " + repr(out))

# Actual literal sed expression that the Makefile uses for sed,
# except remove -i.bak and trailing file so the script can see the command.
sed_expr = r"s/^        ports: \[\]$$/        ports:\n        {{- with .Values.manager.ports }}\n        {{- toYaml . | nindent 8 }}\n        {{- else }}\n        []\n        {{- end }}/"
p = subprocess.Popen(['sed', '-e', sed_expr], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
out, err = p.communicate("        ports: []\n")
print("ports_patch_literal_output:")
print(out)
print("contains guard marker:", "        {{- with .Values.manager.ports }}" in out)
PY

Repository: ironcore-dev/metal-maintenance-operator

Length of output: 3415


🌐 Web query:

POSIX sed replacement string newline \n not supported BSD sed

💡 Result:

In POSIX-compliant sed, the behavior of the "\n" sequence within the replacement string of an 's' command is not explicitly defined as a newline character [1][2][3]. While GNU sed supports "\n" as a newline character in replacement strings, BSD sed (including the version on macOS) does not; it treats the literal characters '' and 'n' as such [4][5][6]. To insert a newline in a replacement string using BSD sed, you must use one of the following methods: 1. Literal Newline: Use a backslash followed by a literal newline character [4][7][8]. In a shell command, you can typically hit Enter after the backslash [9][10]: sed 's/pattern/\ replacement/' 2. ANSI C-Quoted String: If your shell supports it (e.g., bash, zsh, ksh), use ANSI C-quoting ($'...') to expand the newline before it reaches sed [4][5][10]: sed 's/pattern/'$'\n''/' These methods are necessary because BSD sed documentation explicitly states that to specify a newline character in the replacement string, it must be preceded by a backslash [7][8]. Note that while "\n" is not supported in the replacement string, it is typically recognized as a newline character within the regular expression portion of the command across both GNU and BSD sed implementations [11][5].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
try:
    text = Path('.github/workflows/check-codegen.yml').read_text()
except Exception as e:
    print(f"could not read .github/workflows/check-codegen.yml: {e}")
    raise SystemExit

for i, line in enumerate(text.splitlines(), 1):
    if 'make helm' in line or 'make check-gen' in line or 'checks:' in line:
        start = max(1, i-8)
        end = min(len(text.splitlines()), i+30)
        lines = text.splitlines()
        print(f"\n-- .github/workflows/check-codegen.yml:{start}-{end} --")
        for n in range(start, end+1):
            print(f"{n:4}: {lines[n-1]}")
PY

Repository: ironcore-dev/metal-maintenance-operator

Length of output: 1500


Make the ports template patch portable to macOS BSD sed.

This sed replacement uses \n to insert multiple lines. CI uses GNU sed, but macOS uses BSD sed, where \n is not interpreted as a newline in replacement strings. Use Python, Python-style \n expansion before sed, or another portable newline method so make helm and make check-gen do not fail on ports patch not applied.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Makefile` around lines 296 - 302, Make the ports patch in the Makefile
portable across GNU and BSD sed by replacing the current multiline sed
replacement in the manager ports patch block with Python, pre-expanded newline
handling, or another portable method. Preserve the existing Values-driven
template content and keep the post-patch validation that reports “ports patch
not applied.”

Comment thread Makefile
.PHONY: helm
helm: manifests kubebuilder
"$(KUBEBUILDER)" edit --plugins=helm/v2-alpha
@# Patch manager env: replace generated env block with POD_NAMESPACE fieldRef + env/envOverrides

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is handled by #133 and could go here, leaving only the check-gen in place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants