Skip to content

feat: make Kubernetes and JavaScript function groups opt-in - #190

Draft
adityathebe wants to merge 3 commits into
mainfrom
feat/opt-in-k8s-js-extensions
Draft

adityathebe wants to merge 3 commits into
mainfrom
feat/opt-in-k8s-js-extensions

Conversation

@adityathebe

@adityathebe adityathebe commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

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-db query under its 500-package budget.

Closes #189

Opus 5.5 Medium

Why: cel.go appended kubernetes.Library(), funcs.go registered funcs.CreateKubernetesFuncs (and funcs/k8s.go imported kubernetes), and template.go ran Template.Javascript with otto. Go links by import, so every importer paid for these. commons-db query sat at 509 packages against a 500 budget and needed a .gavel.yaml exemption.

What changed

  • New gomplate.Extension (CEL options, Go template funcs, Javascript runner) and gomplate.Register(...). Register replaces extensions by name, rebuilds the cached base CEL env (formerly sync.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 the k8s, isHealthy, isReady, getStatus, getHealth, neat template funcs (moved from funcs/k8s.go).
  • js.Extension(): the otto runner with underscore, k8s.js and shared.js.
  • Lists, URL, regex and k8s.cpuAsMillicores/k8s.memoryAsBytes need 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 to conv.CPUAsMillicores/conv.MemoryAsBytes.
  • playground, ceval, wasm and genmonarch binaries and the test suites register both extensions. README and CEL.md document the opt-in.

API changes for callers

  • Without Register, k8s.isHealthy & co. are undeclared in CEL, isHealthy/k8s are undefined in Go templates, and Javascript templates return javascript templates are not enabled. Apps that rely on them (mission-control, canary-checker, config-db) must call Register in main in the same PR that bumps gomplate.
  • gomplate.LoadSharedLibrary → js.LoadSharedLibrary.
  • funcs.CreateKubernetesFuncs and funcs/k8s_gen.go (unused) are removed.
  • kubernetes.Lists/URLs/Regex, kubernetes.URL/URLType/URLObject and 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: no k8s.io, sigs.k8s.io, is-healthy, kubectl-neat, otto or gopher-lua.
  • commons-db with a replace to this branch builds and vets query, context, projections, types/eval. Third-party packages reached through direct imports (the dep-budget-package rule): query 507 → 339, projections 431 → 259, context 593 → 547 (still exempt for its own client-go use), query/datetime 298 → 135.
  • go test passes for every package; go test -race passes for root and tests (with -d=checkptr=0 for a pre-existing ojg checkptr panic). cmd/ceval needs the built web dist, as on main.
  • Scratch program: before Register, the heavy k8s functions and JS fail with the errors above while core functions work; after Register in the same process they all work; registering twice is harmless.
  • cmd/genmonarch output is identical to what main generates, so the editor vocabulary keeps the k8s functions.

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.
@coderabbitai

coderabbitai Bot commented Nov 29, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Benchstat

Base: 8e753f00723ad0b294362a8d9593e1f290dd29e7
Head: 1b5f19fd012f9682cc339aa96c883aac6f294cc6

12 regression(s) detected (threshold: >5%)

Benchmark Metric Base Head Change p-value
Serialize_NoNativeTypes/items=1000/native_values=false-4 sec/op 1.03 ms/op 1.1 ms/op +6.30% 0.000
CELProgramEvaluation/expression=list_optional_regex/optimized=true-4 sec/op 1.3 us/op 1.35 us/op +3.58% 0.001
RunExpressionNativeInput/input=map-4 sec/op 2.3 us/op 2.36 us/op +2.66% 0.007
CELProgramEvaluation/expression=list_optional_regex/optimized=false-4 sec/op 3.56 us/op 3.65 us/op +2.36% 0.000
RunExpressionContext/cache=hit/environment=small-4 sec/op 1.33 us/op 1.36 us/op +2.19% 0.011
CELProgramEvaluation/expression=scalar/optimized=true-4 sec/op 140 ns/op 142 ns/op +1.00% 0.014
CELProgramEvaluation/expression=scalar/optimized=false-4 sec/op 141 ns/op 142 ns/op +0.71% 0.011
CELProgramEvaluation/expression=list_optional_regex/optimized=false-4 B/op 4.34e+03 B/op 4.35e+03 B/op +0.20% 0.000
CELProgramEvaluation/expression=list_optional_regex/optimized=true-4 B/op 1.18e+03 B/op 1.18e+03 B/op +0.17% 0.000
RunTemplate_LargeEnv/items=10-4 B/op 5.4e+03 B/op 5.4e+03 B/op +0.02% 0.000
CELEnvExtendCustomFunction-4 B/op 4.74e+04 B/op 4.74e+04 B/op +0.01% 0.000
CELEnvExtend/variables=10/functions=0-4 B/op 6.3e+03 B/op 6.3e+03 B/op +0.01% 0.033
5 improvement(s)
Benchmark Metric Base Head Change p-value
RunExpressionContextCompile/cache=miss/environment=small-4 allocs/op 2.37e+03 allocs/op 2.29e+03 allocs/op -3.37% 0.000
RunExpressionContextCompile/cache=miss/environment=large-4 allocs/op 2.38e+03 allocs/op 2.3e+03 allocs/op -3.36% 0.000
RunExpressionContextCompile/cache=miss/environment=large-4 sec/op 251 us/op 246 us/op -2.13% 0.043
RunExpressionContextCompile/cache=miss/environment=large-4 B/op 2.25e+05 B/op 2.22e+05 B/op -1.64% 0.000
RunExpressionContextCompile/cache=miss/environment=small-4 B/op 2.25e+05 B/op 2.21e+05 B/op -1.62% 0.000
Full benchstat output
goos: linux
goarch: amd64
cpu: AMD EPYC 9V74 80-Core Processor                
                                                                         │ bench-base.txt │           bench-head.txt           │
                                                                         │     sec/op     │   sec/op     vs base               │
CELEnvExtendCustomFunction-4                                                  62.97µ ± 2%   62.72µ ± 2%       ~ (p=0.631 n=10)
CELProgramEvaluation/expression=scalar/optimized=false-4                      141.4n ± 1%   142.4n ± 0%  +0.71% (p=0.011 n=10)
CELProgramEvaluation/expression=scalar/optimized=true-4                       140.5n ± 1%   141.8n ± 1%  +1.00% (p=0.014 n=10)
CELProgramEvaluation/expression=list_optional_regex/optimized=false-4         3.563µ ± 2%   3.647µ ± 1%  +2.36% (p=0.000 n=10)
CELProgramEvaluation/expression=list_optional_regex/optimized=true-4          1.301µ ± 2%   1.347µ ± 1%  +3.58% (p=0.001 n=10)
CELProgramEvaluation/expression=comprehension/optimized=false-4               4.737µ ± 2%   4.700µ ± 2%       ~ (p=0.197 n=10)
CELProgramEvaluation/expression=comprehension/optimized=true-4                4.522µ ± 2%   4.564µ ± 3%       ~ (p=0.063 n=10)
RunExpressionNativeInput/input=map-4                                          2.296µ ± 2%   2.357µ ± 2%  +2.66% (p=0.007 n=10)
RunExpressionNativeInput/input=native_struct-4                                2.345µ ± 1%   2.352µ ± 2%       ~ (p=0.616 n=10)
RunExpressionContext/cache=hit/environment=small-4                            1.327µ ± 2%   1.356µ ± 2%  +2.19% (p=0.011 n=10)
RunExpressionContext/cache=hit/environment=large-4                            1.430µ ± 2%   1.456µ ± 2%       ~ (p=0.066 n=10)
RunExpressionContextCompile/cache=miss/environment=small-4                    253.3µ ± 3%   248.6µ ± 2%       ~ (p=0.165 n=10)
RunExpressionContextCompile/cache=miss/environment=large-4                    251.3µ ± 2%   246.0µ ± 2%  -2.13% (p=0.043 n=10)
CELEnvExtend/variables=1/functions=0-4                                        4.703µ ± 3%   4.768µ ± 1%       ~ (p=0.280 n=10)
CELEnvExtend/variables=10/functions=0-4                                       6.048µ ± 4%   6.176µ ± 3%       ~ (p=0.315 n=10)
CELEnvExtend/variables=100/functions=0-4                                      17.96µ ± 3%   17.95µ ± 2%       ~ (p=0.631 n=10)
RunExpressionContextFunctions/celFunctions/cache=hit/environment=large-4      3.190µ ± 4%   3.190µ ± 1%       ~ (p=0.670 n=10)
RunExpressionContextFunctions/functions/cache=hit/environment=large-4         3.188µ ± 3%   3.219µ ± 1%       ~ (p=0.101 n=10)
Serialize/items=10/native_values=true-4                                       30.14µ ± 3%   29.98µ ± 2%       ~ (p=0.579 n=10)
Serialize/items=100/native_values=true-4                                      253.1µ ± 3%   256.4µ ± 2%       ~ (p=0.353 n=10)
Serialize/items=1000/native_values=true-4                                     2.602m ± 3%   2.626m ± 2%       ~ (p=0.190 n=10)
Serialize/items=10000/native_values=true-4                                    29.14m ± 4%   28.64m ± 3%       ~ (p=0.315 n=10)
Serialize_NoNativeTypes/items=100/native_values=false-4                       107.2µ ± 3%   107.8µ ± 1%       ~ (p=0.393 n=10)
Serialize_NoNativeTypes/items=1000/native_values=false-4                      1.030m ± 3%   1.095m ± 2%  +6.30% (p=0.000 n=10)
Serialize_NoNativeTypes/items=10000/native_values=false-4                     11.28m ± 4%   11.29m ± 4%       ~ (p=0.684 n=10)
RunTemplate_LargeEnv/items=10-4                                               3.970µ ± 5%   3.972µ ± 3%       ~ (p=0.838 n=10)
RunTemplate_LargeEnv/items=1000-4                                             3.894µ ± 4%   3.944µ ± 3%       ~ (p=0.796 n=10)
RunTemplate_LargeEnv/items=10000-4                                            3.857µ ± 4%   3.868µ ± 5%       ~ (p=0.393 n=10)
geomean                                                                       16.73µ        16.86µ       +0.82%

                                                                         │ bench-base.txt │            bench-head.txt             │
                                                                         │      B/op      │     B/op      vs base                 │
CELEnvExtendCustomFunction-4                                                 46.31Ki ± 0%   46.32Ki ± 0%  +0.01% (p=0.000 n=10)
CELProgramEvaluation/expression=scalar/optimized=false-4                       96.00 ± 0%     96.00 ± 0%       ~ (p=1.000 n=10) ¹
CELProgramEvaluation/expression=scalar/optimized=true-4                        96.00 ± 0%     96.00 ± 0%       ~ (p=1.000 n=10) ¹
CELProgramEvaluation/expression=list_optional_regex/optimized=false-4        4.241Ki ± 0%   4.249Ki ± 0%  +0.20% (p=0.000 n=10)
CELProgramEvaluation/expression=list_optional_regex/optimized=true-4         1.148Ki ± 0%   1.150Ki ± 0%  +0.17% (p=0.000 n=10)
CELProgramEvaluation/expression=comprehension/optimized=false-4              3.063Ki ± 0%   3.063Ki ± 0%       ~ (p=1.000 n=10) ¹
CELProgramEvaluation/expression=comprehension/optimized=true-4               2.798Ki ± 0%   2.798Ki ± 0%       ~ (p=1.000 n=10) ¹
RunExpressionNativeInput/input=map-4                                         1.375Ki ± 0%   1.375Ki ± 0%       ~ (p=1.000 n=10) ¹
RunExpressionNativeInput/input=native_struct-4                               1.250Ki ± 0%   1.250Ki ± 0%       ~ (p=1.000 n=10) ¹
RunExpressionContext/cache=hit/environment=small-4                             840.0 ± 0%     840.0 ± 0%       ~ (p=1.000 n=10) ¹
RunExpressionContext/cache=hit/environment=large-4                             936.0 ± 0%     936.0 ± 0%       ~ (p=1.000 n=10) ¹
RunExpressionContextCompile/cache=miss/environment=small-4                   219.6Ki ± 0%   216.1Ki ± 0%  -1.62% (p=0.000 n=10)
RunExpressionContextCompile/cache=miss/environment=large-4                   219.9Ki ± 0%   216.3Ki ± 0%  -1.64% (p=0.000 n=10)
CELEnvExtend/variables=1/functions=0-4                                       4.477Ki ± 0%   4.477Ki ± 0%       ~ (p=1.000 n=10) ¹
CELEnvExtend/variables=10/functions=0-4                                      6.157Ki ± 0%   6.157Ki ± 0%  +0.01% (p=0.033 n=10)
CELEnvExtend/variables=100/functions=0-4                                     23.63Ki ± 0%   23.63Ki ± 0%  +0.00% (p=0.000 n=10)
RunExpressionContextFunctions/celFunctions/cache=hit/environment=large-4     2.297Ki ± 0%   2.297Ki ± 0%       ~ (p=1.000 n=10) ¹
RunExpressionContextFunctions/functions/cache=hit/environment=large-4        2.359Ki ± 0%   2.359Ki ± 0%       ~ (p=1.000 n=10) ¹
Serialize/items=10/native_values=true-4                                      34.39Ki ± 0%   34.39Ki ± 0%       ~ (p=1.000 n=10) ¹
Serialize/items=100/native_values=true-4                                     304.6Ki ± 0%   304.6Ki ± 0%       ~ (p=1.000 n=10) ¹
Serialize/items=1000/native_values=true-4                                    2.946Mi ± 0%   2.946Mi ± 0%  +0.00% (p=0.007 n=10)
Serialize/items=10000/native_values=true-4                                   29.45Mi ± 0%   29.45Mi ± 0%       ~ (p=0.813 n=10)
Serialize_NoNativeTypes/items=100/native_values=false-4                      104.0Ki ± 0%   104.0Ki ± 0%       ~ (p=1.000 n=10) ¹
Serialize_NoNativeTypes/items=1000/native_values=false-4                     1.007Mi ± 0%   1.007Mi ± 0%  -0.00% (p=0.005 n=10)
Serialize_NoNativeTypes/items=10000/native_values=false-4                    10.07Mi ± 0%   10.07Mi ± 0%       ~ (p=0.455 n=10)
RunTemplate_LargeEnv/items=10-4                                              5.273Ki ± 0%   5.274Ki ± 0%  +0.02% (p=0.000 n=10)
RunTemplate_LargeEnv/items=1000-4                                            5.273Ki ± 0%   5.273Ki ± 0%       ~ (p=1.000 n=10) ¹
RunTemplate_LargeEnv/items=10000-4                                           5.273Ki ± 0%   5.273Ki ± 0%       ~ (p=1.000 n=10) ¹
geomean                                                                      14.79Ki        14.78Ki       -0.10%
¹ all samples are equal

                                                                         │ bench-base.txt │            bench-head.txt            │
                                                                         │   allocs/op    │  allocs/op   vs base                 │
CELEnvExtendCustomFunction-4                                                   112.0 ± 0%    112.0 ± 0%       ~ (p=1.000 n=10) ¹
CELProgramEvaluation/expression=scalar/optimized=false-4                       3.000 ± 0%    3.000 ± 0%       ~ (p=1.000 n=10) ¹
CELProgramEvaluation/expression=scalar/optimized=true-4                        3.000 ± 0%    3.000 ± 0%       ~ (p=1.000 n=10) ¹
CELProgramEvaluation/expression=list_optional_regex/optimized=false-4          79.00 ± 0%    79.00 ± 0%       ~ (p=1.000 n=10) ¹
CELProgramEvaluation/expression=list_optional_regex/optimized=true-4           30.00 ± 0%    30.00 ± 0%       ~ (p=1.000 n=10) ¹
CELProgramEvaluation/expression=comprehension/optimized=false-4                91.00 ± 0%    91.00 ± 0%       ~ (p=1.000 n=10) ¹
CELProgramEvaluation/expression=comprehension/optimized=true-4                 87.00 ± 0%    87.00 ± 0%       ~ (p=1.000 n=10) ¹
RunExpressionNativeInput/input=map-4                                           36.00 ± 0%    36.00 ± 0%       ~ (p=1.000 n=10) ¹
RunExpressionNativeInput/input=native_struct-4                                 29.00 ± 0%    29.00 ± 0%       ~ (p=1.000 n=10) ¹
RunExpressionContext/cache=hit/environment=small-4                             20.00 ± 0%    20.00 ± 0%       ~ (p=1.000 n=10) ¹
RunExpressionContext/cache=hit/environment=large-4                             23.00 ± 0%    23.00 ± 0%       ~ (p=1.000 n=10) ¹
RunExpressionContextCompile/cache=miss/environment=small-4                    2.373k ± 0%   2.293k ± 0%  -3.37% (p=0.000 n=10)
RunExpressionContextCompile/cache=miss/environment=large-4                    2.378k ± 0%   2.298k ± 0%  -3.36% (p=0.000 n=10)
CELEnvExtend/variables=1/functions=0-4                                         72.00 ± 0%    72.00 ± 0%       ~ (p=1.000 n=10) ¹
CELEnvExtend/variables=10/functions=0-4                                        91.00 ± 0%    91.00 ± 0%       ~ (p=1.000 n=10) ¹
CELEnvExtend/variables=100/functions=0-4                                       193.0 ± 0%    193.0 ± 0%       ~ (p=1.000 n=10) ¹
RunExpressionContextFunctions/celFunctions/cache=hit/environment=large-4       44.00 ± 0%    44.00 ± 0%       ~ (p=1.000 n=10) ¹
RunExpressionContextFunctions/functions/cache=hit/environment=large-4          48.00 ± 0%    48.00 ± 0%       ~ (p=1.000 n=10) ¹
Serialize/items=10/native_values=true-4                                        424.0 ± 0%    424.0 ± 0%       ~ (p=1.000 n=10) ¹
Serialize/items=100/native_values=true-4                                      3.844k ± 0%   3.844k ± 0%       ~ (p=1.000 n=10) ¹
Serialize/items=1000/native_values=true-4                                     39.53k ± 0%   39.53k ± 0%       ~ (p=1.000 n=10) ¹
Serialize/items=10000/native_values=true-4                                    399.5k ± 0%   399.5k ± 0%       ~ (p=1.000 n=10) ¹
Serialize_NoNativeTypes/items=100/native_values=false-4                       1.721k ± 0%   1.721k ± 0%       ~ (p=1.000 n=10) ¹
Serialize_NoNativeTypes/items=1000/native_values=false-4                      17.77k ± 0%   17.77k ± 0%       ~ (p=1.000 n=10) ¹
Serialize_NoNativeTypes/items=10000/native_values=false-4                     179.8k ± 0%   179.8k ± 0%       ~ (p=1.000 n=10) ¹
RunTemplate_LargeEnv/items=10-4                                                39.00 ± 0%    39.00 ± 0%       ~ (p=1.000 n=10) ¹
RunTemplate_LargeEnv/items=1000-4                                              39.00 ± 0%    39.00 ± 0%       ~ (p=1.000 n=10) ¹
RunTemplate_LargeEnv/items=10000-4                                             39.00 ± 0%    39.00 ± 0%       ~ (p=1.000 n=10) ¹
geomean                                                                        228.7         228.2       -0.24%
¹ all samples are equal

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gomplate: make Kubernetes/JS/Lua/data function groups opt-in (then drop query/.gavel.yaml ignore)

1 participant