Skip to content

Replace generated byte array with go:embed for templates#3597

Draft
cardil wants to merge 1 commit intoknative:mainfrom
cardil:refactor/go-embed-templates
Draft

Replace generated byte array with go:embed for templates#3597
cardil wants to merge 1 commit intoknative:mainfrom
cardil:refactor/go-embed-templates

Conversation

@cardil
Copy link
Copy Markdown
Contributor

@cardil cardil commented Apr 9, 2026

Summary

Replace the ~17K-line generated Go source file (generate/zz_filesystem_generated.go) containing a hex byte array literal with a gitignored binary zip file + //go:embed.

Changes

  • generate/templates/main.go: Router dispatching on check subcommand
  • generate/templates/gen.go: Writes binary templates.zip directly (with .gitignore filtering from PR feat: WASI target support for func (build + deploy) #3560)
  • generate/templates/check.go: 3-tier verification (existence, staleness, content hash)
  • generate/embed.go: //go:embed templates.zip exposes TemplatesZip []byte
  • Deleted generate/zz_filesystem_generated.go
  • .gitignore: Added generate/templates.zip
  • .gitattributes: Removed zz_filesystem_generated.go entry
  • Makefile: Updated targets to use generate/templates.zip, added rm -f generate/templates.zip to clean
  • hack/verify-codegen.sh: Uses Go checker instead of bash diff
  • pkg/functions/templates_embedded.go: //go:generate go run ../../generate/templates (whole package)
  • pkg/filesystem/filesystem_test.go: Updated stale error message

Why

The generated Go source file changed in almost every PR that touched templates, causing constant merge conflicts. A binary zip + //go:embed eliminates this entirely since templates.zip is gitignored.

Testing

  • make generate/templates.zip
  • make test ✅ (all tests pass)
  • make check ✅ (lint, imports, spelling, whitespace, EOF)
  • go run ./generate/templates check ✅ (3-tier verification)
  • Staleness detection ✅ (touch a template → check fails)
  • Missing zip detection ✅ (remove zip → check fails)

Assisted-by: 🤖 Claude Opus/Sonnet 4.6

- generate/templates/main.go: write binary templates.zip instead of Go source
- generate/templates/gen.go: extract zip-writing logic (with .gitignore filtering)
- generate/templates/check.go: 3-tier verification (exist/stale/hash)
- generate/embed.go: //go:embed templates.zip exposes TemplatesZip []byte
- delete generate/zz_filesystem_generated.go
- .gitignore: add generate/templates.zip
- .gitattributes: remove zz_filesystem_generated.go entry
- Makefile: update targets/clean to use generate/templates.zip
- hack/verify-codegen.sh: use Go checker for templates.zip verification
- pkg/functions/templates_embedded.go: run whole package instead of single file
- pkg/filesystem/filesystem_test.go: update stale error message

Assisted-by: 🤖 Claude Sonnet 4.6
@knative-prow knative-prow bot requested review from dsimansk and jrangelramos April 9, 2026 12:04
@knative-prow
Copy link
Copy Markdown

knative-prow bot commented Apr 9, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: cardil
Once this PR has been reviewed and has the lgtm label, please assign jrangelramos for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot added the size/L 🤖 PR changes 100-499 lines, ignoring generated files. label Apr 9, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow bot commented Apr 9, 2026

@cardil: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
unit-tests_func_main a5a0ad5 link true /test unit-tests

Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@matejvasek matejvasek requested a review from lkingland April 9, 2026 12:27
@matejvasek
Copy link
Copy Markdown
Contributor

Would this work even if I imported function as a library (We doing that now in Functions OCP dynamic plugin)?

@lkingland
Copy link
Copy Markdown
Member

lkingland commented Apr 10, 2026

Sorry, but we tried go:embed as soon as it was available, but it doesn't work for our use-case for multiple reasons.

EDIT: Ah, I see we have a Slack thread about this.

**The generated Go source file changed in almost every PR that touched templates, causing constant merge conflicts. A binary zip + //go:embed eliminates this entirely since templates.zip is gitignored.

tl;dr, This could perhaps be minimized by splitting the monolithic generated file into a per-language, per-template set of generated files.

@cardil
Copy link
Copy Markdown
Contributor Author

cardil commented Apr 10, 2026

I think I have a solution. Will keep you posted...

/hold

@knative-prow knative-prow bot added the do-not-merge/hold 🤖 PR should not merge because someone has issued a /hold command. label Apr 10, 2026
@cardil cardil marked this pull request as draft April 10, 2026 11:05
@knative-prow knative-prow bot added the do-not-merge/work-in-progress 🤖 PR should not merge because it is a work in progress. label Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/hold 🤖 PR should not merge because someone has issued a /hold command. do-not-merge/work-in-progress 🤖 PR should not merge because it is a work in progress. size/L 🤖 PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants