Repository navigation
feat: make Kubernetes and JavaScript function groups opt-in - #190
Draft
adityathebe wants to merge 3 commits into
Draft
adityathebe wants to merge 3 commits into
adityathebe wants to merge 3 commits into
Conversation
The root package imported the kubernetes package (is-healthy, gopher-lua, k8s.io/api, apimachinery, kubectl-neat) and otto unconditionally, so every importer linked 336 third-party packages even when it never used those functions. commons-db query exceeded its 500-package dependency budget because of this. gomplate.Register(kubernetes.Extension(), js.Extension()) now enables them. An Extension carries CEL options, Go template functions and a Javascript runner; Register rebuilds the base CEL environment and empties the expression and template caches. Without registration, k8s.isHealthy and the other heavy k8s functions are undeclared and Javascript templates return an error. The root package now links 164 third-party packages. The list, URL, regex and quantity CEL functions need no Kubernetes dependencies and move to kubernetes/library, which stays enabled by default. funcs/k8s.go moves into the kubernetes package so funcs no longer links Kubernetes, and LoadSharedLibrary moves to the js package. The playground, ceval, wasm and genmonarch binaries register both extensions.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
BenchstatBase: 12 regression(s) detected (threshold: >5%)
5 improvement(s)
Full benchstat output |
…oot package kubernetes/library made the core look like it still depended on Kubernetes. These functions need only cel-go, so they now live next to the other core CEL libraries in cel_lists.go, cel_url.go, cel_regex.go and cel_quantity.go, and the CPU and memory quantity parsers move to conv for kubernetes/topology.go. CEL function names and behaviour are unchanged.
Only min and max need new names in the root package, where they would hide the Go builtins used by cel_statistics.go. Revert the other renames so the files differ from their kubernetes originals only in the package clause and those two functions.
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.
Importing gomplate linked all of Kubernetes, is-healthy/gopher-lua, kubectl-neat and otto, even for callers that never use those functions. This makes them opt-in with
gomplate.Register(kubernetes.Extension(), js.Extension()), cutting the root package from 336 to 164 third-party packages and bringing commons-dbqueryunder its 500-package budget.Closes #189
Opus 5.5 Medium
Why:
cel.goappendedkubernetes.Library(),funcs.goregisteredfuncs.CreateKubernetesFuncs(andfuncs/k8s.goimportedkubernetes), andtemplate.goranTemplate.Javascriptwith otto. Go links by import, so every importer paid for these. commons-dbquerysat at 509 packages against a 500 budget and needed a.gavel.yamlexemption.What changed
gomplate.Extension(CEL options, Go template funcs, Javascript runner) andgomplate.Register(...). Register replaces extensions by name, rebuilds the cached base CEL env (formerlysync.OnceValues) and flushes the expression, extended-env and Go template caches. Meant to be called at startup.kubernetes.Extension(): health/status/readiness,k8s.neat, pod/node topology for CEL, plus thek8s,isHealthy,isReady,getStatus,getHealth,neattemplate funcs (moved fromfuncs/k8s.go).js.Extension(): the otto runner with underscore,k8s.jsandshared.js.k8s.cpuAsMillicores/k8s.memoryAsBytesneed no Kubernetes deps; they move into the root package (cel_lists.go,cel_url.go,cel_regex.go,cel_quantity.go) and stay enabled by default. The CPU and memory quantity parsers move toconv.CPUAsMillicores/conv.MemoryAsBytes.API changes for callers
Register,k8s.isHealthy& co. are undeclared in CEL,isHealthy/k8sare undefined in Go templates, and Javascript templates returnjavascript templates are not enabled. Apps that rely on them (mission-control, canary-checker, config-db) must callRegisterinmainin the same PR that bumps gomplate.gomplate.LoadSharedLibrary→js.LoadSharedLibrary.funcs.CreateKubernetesFuncsandfuncs/k8s_gen.go(unused) are removed.kubernetes.Lists/URLs/Regex,kubernetes.URL/URLType/URLObjectand the exported regex optimizations moved to the root package under the same names (gomplate.Lists,gomplate.URL, …);kubernetes.Library()now returns only the heavy functions.Verification
go list -deps .and./funcs: nok8s.io,sigs.k8s.io,is-healthy,kubectl-neat,ottoorgopher-lua.replaceto this branch builds and vetsquery,context,projections,types/eval. Third-party packages reached through direct imports (thedep-budget-packagerule):query507 → 339,projections431 → 259,context593 → 547 (still exempt for its own client-go use),query/datetime298 → 135.go testpasses for every package;go test -racepasses for root andtests(with-d=checkptr=0for a pre-existing ojg checkptr panic).cmd/cevalneeds the built webdist, as onmain.Register, the heavy k8s functions and JS fail with the errors above while core functions work; afterRegisterin the same process they all work; registering twice is harmless.cmd/genmonarchoutput is identical to whatmaingenerates, so the editor vocabulary keeps the k8s functions.