-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
bundle: Fixing issue where --v0-compatible
isn't respected for custom bundles
#7338
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -715,8 +715,10 @@ func (r *Reader) Read() (Bundle, error) { | |
popts.RegoVersion = bundle.RegoVersion(popts.EffectiveRegoVersion()) | ||
for _, mf := range modules { | ||
modulePopts := popts | ||
if modulePopts.RegoVersion, err = bundle.RegoVersionForFile(mf.RelativePath, popts.EffectiveRegoVersion()); err != nil { | ||
if regoVersion, err := bundle.RegoVersionForFile(mf.RelativePath, popts.EffectiveRegoVersion()); err != nil { | ||
return bundle, err | ||
} else if regoVersion != ast.RegoUndefined { | ||
modulePopts.RegoVersion = regoVersion | ||
} | ||
r.metrics.Timer(metrics.RegoModuleParse).Start() | ||
mf.Parsed, err = ast.ParseModuleWithOpts(mf.Path, string(mf.Raw), modulePopts) | ||
|
@@ -1204,10 +1206,6 @@ func (b *Bundle) SetRegoVersion(v ast.RegoVersion) { | |
// If there is no defined version for the given path, the default version def is returned. | ||
// If the version does not correspond to ast.RegoV0 or ast.RegoV1, an error is returned. | ||
func (b *Bundle) RegoVersionForFile(path string, def ast.RegoVersion) (ast.RegoVersion, error) { | ||
if def == ast.RegoUndefined { | ||
def = ast.DefaultRegoVersion | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a "magic", undocumented behavior that even confused our own internal usage. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [comment]: I did wonder about this when I was looking at the sources recently. Thanks for addressing this! |
||
|
||
version, err := b.Manifest.numericRegoVersionForFile(path) | ||
if err != nil { | ||
return def, err | ||
|
@@ -1513,7 +1511,7 @@ func bundleRegoVersions(bundle *Bundle, regoVersion ast.RegoVersion, usePath boo | |
return nil, err | ||
} | ||
// only record the rego version if it's different from one applied globally to the result bundle | ||
if v != regoVersion { | ||
if regoVersion != ast.RegoUndefined && v != regoVersion { | ||
// We store the rego version by the absolute path to the bundle root, as this will be the - possibly new - path | ||
// to the module inside the merged bundle. | ||
fileRegoVersions[bundleAbsolutePath(m, usePath)] = v.Int() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -827,7 +827,7 @@ func writeModuleRegoVersionToStore(ctx context.Context, store storage.Store, txn | |
|
||
if regoVersion == ast.RegoUndefined { | ||
var err error | ||
regoVersion, err = b.RegoVersionForFile(mf.Path, ast.RegoUndefined) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the root cause of the issue. If no rego-version was declared for the module in the bundle, we'd always default to |
||
regoVersion, err = b.RegoVersionForFile(mf.Path, runtimeRegoVersion) | ||
if err != nil { | ||
return fmt.Errorf("failed to get rego version for module '%s' in bundle: %w", mf.Path, err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[comment/question]: It is not obvious to me exactly when this condition could occur, even after diving into the sources for
bundle.RegoVersionForFile
. As best I can tell though, getting both an error and aregoVersion
that isn't the defaultast.RegoUndefined
value should be pretty difficult.If there's an obvious edge-case I'm missing, could we add a quick comment to explain it here? 😅