deploy/kubernetes: embed CRDs instead of duplicating them - #4845
Merged
Conversation
The CRD manifests were kept in two places — real YAML under config/crd/ (for kubectl apply) and byte-identical const strings in manifests.go (for the Go CRDManifests map) — which will silently drift. Make config/crd/*.yaml the single source of truth and go:embed it; CRDManifests now reads the embedded bytes. Drops ~120 lines of duplicated YAML, no behavior change (still stdlib-only, tests unchanged). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL
There was a problem hiding this comment.
Pull request overview
This PR removes duplicated Kubernetes CRD YAML embedded as Go string constants and instead embeds the canonical CRD manifests from deploy/kubernetes/config/crd/*.yaml, ensuring the Go-served CRDManifests content matches what users apply with kubectl.
Changes:
- Replaces inlined CRD YAML string constants with
go:embed-backed loading fromconfig/crd/*.yaml. - Adds a small helper to read embedded CRD YAML and populates
CRDManifestsfrom embedded bytes. - Reduces
manifests.gosubstantially by deleting duplicated manifest content.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+26
to
+30
| func mustCRD(name string) string { | ||
| b, err := crdFS.ReadFile("config/crd/" + name + ".yaml") | ||
| if err != nil { | ||
| panic(fmt.Sprintf("kubernetes: embedded CRD %q missing: %v", name, err)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The merged K8s foundation (#4839) kept each CRD manifest in two places:
deploy/kubernetes/config/crd/{agent,service,flow}.yaml(whatkubectl applyuses), andconst agentCRD/serviceCRD/flowCRDstrings inmanifests.go(what the GoCRDManifestsmap returns).Two copies of the same schema will silently drift — edit one, forget the other, and the applied CRD no longer matches what the package serves.
This makes
config/crd/*.yamlthe single source of truth andgo:embeds it;CRDManifestsnow reads the embedded bytes. Drops ~120 lines of duplicated YAML.CRDManifests[kind]returns the same content, still stdlib-only (embed), andTestCRDManifestsAreStructural/TestMapDeployment*pass unchanged.manifests.go: 125 → 31 lines.go build ./...,go test ./deploy/kubernetes/...,go vet, andgolangci-lint run ./deploy/kubernetes/...pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL
Generated by Claude Code