Uh oh!
There was an error while loading. Please reload this page.
policy: remove uses of deprecated WithBuiltins - #3914
Conversation
| } | ||
| func compilePolicyModules(modules map[string]*ast.Module, p *Policy, fsProvider func() (fs.StatFS, func() error, error)) (*ast.Compiler, func() error, error) { | ||
| func policyCapabilities(funcs []fun) *ast.Capabilities { |
There was a problem hiding this comment.
May as well make this a non-exported methods on Policy; let me update
thaJeztah
commented
Jun 16, 2026
The WithBuiltins method was deprecated in opa v0.23.0 ([opa@afc8c5e]) in favor of WithCapabilities, but the deprecation didn't use the standard format, causing it not being detected as deprecated. OPA v1.1.0 corrected the deprecation in [opa@622434d]. This patch replaces uses of the deprecated functions. [opa@afc8c5e]: open-policy-agent/opa@afc8c5e [opa@622434d]: open-policy-agent/opa@622434d Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
219b40a to
8b1d06aCompareThere was a problem hiding this comment.
Pull request overview
This PR updates the policy compilation setup to avoid using OPA’s deprecated WithBuiltins compiler API, aligning the code with the newer WithCapabilities approach introduced/fixed in newer OPA releases.
Changes:
- Introduce a shared
(*Policy).capabilities()helper that builds anast.Capabilitiesincluding both standard and policy-specific builtins. - Update policy compilation paths to use
WithCapabilities(p.capabilities())instead ofWithBuiltins(...). - Remove now-unneeded
slicesimport frompolicy/tester.go.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| policy/validate.go | Adds capabilities() and switches compiler setup to rely solely on WithCapabilities, removing deprecated WithBuiltins usage. |
| policy/tester.go | Simplifies module compilation by reusing p.capabilities() and drops the old WithBuiltins path (and the unused slices import). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
thaJeztah
commented
Jun 18, 2026
@tonistiigi PTAL |
| builtins := make(map[string]*ast.Builtin) | ||
| for _, f := range p.funcs { | ||
| builtins[f.decl.Name] = &ast.Builtin{ | ||
| caps.Builtins = append(caps.Builtins, &ast.Builtin{ |
There was a problem hiding this comment.
nit: this should set a cap based on len(p.funcs) to avoid slice resizing overhead (or somehow combine with builtins()). You can do this in a follow-up.
Uh oh!
There was an error while loading. Please reload this page.

The WithBuiltins method was deprecated in opa v0.23.0 (opa@afc8c5e) in favor of WithCapabilities, but the deprecation didn't use the standard format, causing it not being detected as deprecated. OPA v1.1.0 corrected the deprecation in opa@622434d.
This patch replaces uses of the deprecated functions.