[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk: fix bug while activating the bundle plugin #6689

Merged
merged 4 commits into from
Apr 11, 2024

Conversation

xico42
Copy link
Contributor
@xico42 xico42 commented Apr 9, 2024

For some reason the bundle plugin activation with multiple optimized bundles, builded in v1 syntax, results in parsing error.

During the activation of the bundle, when we need to parse the rego modules, the ParserOptions is not forwarded to the bundle.ActivateOps, so the v1 syntax does not seem to be properly parsed.

Why the changes in this PR are needed?

The OPA SDK does not initialize when provided multiple bundles that were optimized with v1 syntax.

What are the changes in this PR?

Basically, I just forward the ParserOptions from the plugin manager to the bundle.ActivateOpts struct.

Notes to assist PR review:

I am not totally sure about what the root problem is, but I was able to provide a failing test
and the fix.

It might be related to the issue #6450

Further comments:

Copy link
netlify bot commented Apr 9, 2024

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit 7dd1dd8
🔍 Latest deploy log https://app.netlify.com/sites/openpolicyagent/deploys/6616bef55343d80008e31ca0
😎 Deploy Preview https://deploy-preview-6689--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

For some reason the bundle plugin activation with multiple optimized
bundles, builded in v1 syntax, results in parsing error.

During the activation of the bundle, when we need to parse the rego
modules, the ParserOptions is not forwarded to the `bundle.ActivateOps`,
so the v1 syntax does not seem to be properly parsed.

Signed-off-by: Francisco Rodrigues <ednofco@gmail.com>
…he function of multiple consecutive bundle updates.

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
Copy link
Contributor
@johanfylling johanfylling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great find @xico42 ! 😃

This is unrelated to #6450.

I've pushed an updated test to your branch to further assert your fix.

Just a minor nit before we can get this merged.

sdk/opa_test.go Outdated
@@ -2844,3 +2844,54 @@ func toMetricMap(metrics []*promdto.MetricFamily) map[string]bool {
}
return metricMap
}

func TestActivateOptimizedV1Bundles(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should rename this to TestActivateV1Bundles.
Colloquially, an "optimized" bundle is one that has been constructed through an optimized OPA build (e.g. opa build is used with the -O flag).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johanfylling I've renamed the test and simplified the test structure to better reflect this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you :)

Compiler: compiler,
Metrics: p.status[name].Metrics,
Bundles: map[string]*bundle.Bundle{name: b},
ParserOptions: p.manager.ParserOptions(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find 👍 🎉 .

Conflicts:
	plugins/bundle/plugin_test.go
The bug in activating bundles in the SDK is not necessarily related
to optimized bundles, but specifically for v1 bundles.

So the test was renamed to `TestActivateV1Bundles` and the test
structure simplified to better describe the scenario.

Signed-off-by: Francisco Rodrigues <ednofco@gmail.com>
Copy link
Contributor
@johanfylling johanfylling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!
Thank you for your contribution! 😃

@johanfylling johanfylling merged commit 8f551d9 into open-policy-agent:main Apr 11, 2024
27 checks passed
@xico42 xico42 deleted the fix/bundle-activation branch April 11, 2024 11:42
@xico42 xico42 restored the fix/bundle-activation branch April 11, 2024 11:42
@xico42 xico42 deleted the fix/bundle-activation branch April 11, 2024 11:42
tsidebottom pushed a commit to tsidebottom/opa- that referenced this pull request Apr 17, 2024
…policy-agent#6689)

Fixing issue where active parser options aren't propagated to module reload during bundle activation.

Signed-off-by: Francisco Rodrigues <ednofco@gmail.com>
Signed-off-by: Thomas Sidebottom <thomas.sidebottom@va.gov>
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.

2 participants