Skip to content

Building bundle with optimization breaks metadata annotation parsing #6529

@anderseknert

Description

@anderseknert

cwd

.
└── bundle
    └── p.rego

bundle/p.rego

package p

a := 1

# METADATA
# description: a
# entrypoint: true
b := 2

# METADATA
# description: b
# entrypoint: true
c := 3
opa build -O=1 --bundle bundle/
opa eval -b bundle.tar.gz data.p
{
  "errors": [
    {
      "message": "loading error: bundle bundle.tar.gz: 1 error occurred: /bundle/p.rego:9: rego_parse_error: yaml: line 4: could not find expected ':'\n\t# description: b\n\t^"
    }
  ]
}

Looking inside of the optimized bundle, the p.rego file does indeed look broken wrt metadata:

p.rego (inside bundle.tar.gz)

package p

a := 1

# METADATA
# description: a
# entrypoint: true
# METADATA
# description: b
# entrypoint: true

The b and c rules have been moved to different files under the optimized directory, but since the metadata annotations haven't moved with them, they'll no longer be scoped to those rules.

Interestingly, running opa eval -O=1 --bundle bundle/ — i.e. on the directory directly (without passing opa build) does not produce this error, so presumably it does not do the same optimization?

Reported to me by @nevumx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions