micro--go-micro
aaa03f89e3
goreleaser / goreleaser (push) Has been cancelled
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). Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL Co-authored-by: Claude <noreply@anthropic.com>
33 行
1.0 KiB
Go
33 行
1.0 KiB
Go
package kubernetes
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
)
|
|
|
|
// crdFS holds the canonical CRD manifests. They live as real YAML under
|
|
// config/crd/ so they can be applied directly (`kubectl apply -f
|
|
// deploy/kubernetes/config/crd/`) and are embedded here so the Go API serves
|
|
// the exact same bytes — one source of truth, no drift.
|
|
//
|
|
//go:embed config/crd/agent.yaml config/crd/service.yaml config/crd/flow.yaml
|
|
var crdFS embed.FS
|
|
|
|
// CRDManifests contains the alpha CRDs for Go Micro lifecycle resources, loaded
|
|
// from the embedded config/crd/ YAML.
|
|
var CRDManifests = map[Kind]string{
|
|
KindAgent: mustCRD("agent"),
|
|
KindService: mustCRD("service"),
|
|
KindFlow: mustCRD("flow"),
|
|
}
|
|
|
|
// mustCRD reads an embedded CRD manifest. The files are embedded at compile
|
|
// time, so a read error means a build/packaging bug, not a runtime condition.
|
|
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))
|
|
}
|
|
return string(b)
|
|
}
|