Skip to content

Update parser to support rules of the form <var> = <term containing ref> #192

Closed
@tsandall

Description

Rules can be written in the form <var> = <ground term>. This is useful for defining constants; it would be nice if we could do the same with terms containing refs. Currently, the parser will return an error because it deems the term as being non-ground (since references have not been resolved yet).

One solution would be to update the parser to allow non-ground terms. If the user did include a variable in the value and that variable was not eventually resolved, the compiler should catch the error when performing the safety checks on the head.

Example parse error:

torin:~$ opa run test.rego
test.rego:7: expected rule (annotations_versioned = {
    "metadata": {
        "annotations": annotations,
        "resourceVersion": object.metadata.resourceVersion
    }
} must be declared inside a rule)

Example input:

package io.k8s

import object

annotations = {}

annotations_versioned = {
    "metadata": {
        "annotations": annotations,
        "resourceVersion": object.metadata.resourceVersion
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions