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

Kubernetes Combine Example does not Work as Intended #991

Open
bijenkins opened this issue Aug 13, 2024 · 1 comment
Open

Kubernetes Combine Example does not Work as Intended #991

bijenkins opened this issue Aug 13, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@bijenkins
Copy link

bijenkins commented Aug 13, 2024

The example in the kubernetes folder does not work on the combine example, there is NO matching goodbye service yet it passes the test that every deployment has a matching service.

https://github.com/open-policy-agent/conftest/tree/master/examples/kubernetes/combine

Specifically, there's a rule that shows if a deployment has no matching service with the same label, it should fail:

msg := sprintf("Deployment '%v' has no matching service", [deployment.metadata.name])

package main

violation[msg] {
    some i
    input[i].contents.kind == "Deployment"
    deployment := input[i].contents
    not service_selects_app(deployment.spec.selector.matchLabels.app)
    msg := sprintf("Deployment '%v' has no matching service", [deployment.metadata.name])
}

service_selects_app(app) {
    some i
    input[i].contents.kind == "Service"
    service := input[i].contents
    service.spec.selector.app == app
}

Yaml running against:
https://github.com/open-policy-agent/conftest/blob/56d742d241174bbc790d7b6e6cb3a8632ffff576/examples/kubernetes/combine/combine.yaml

Specifically to reproduce:

conftest test conftest/examples/kubernetes/combine/combine.yaml --policy conftest/examples/kubernetes/combine/


> conftest test combine/combine.yaml --policy combine -o json                                                                                                                                                       1 ↵ ──(Tue,Aug13)─┘
[
        {
                "filename": "combine/combine.yaml",
                "namespace": "main",
                "successes": 3
        }
]

This should not have passed the tests, really trying to grasp this exact scenario and the example given doesn't work. There is no goodbye service. It should fail.

@bijenkins
Copy link
Author

bijenkins commented Aug 13, 2024

Trace for exact run:


file: combine/combine.yaml | query: data.main.exception[_][_] == ""
TRAC   Enter __localq0__ = data.main.exception[_][_]; equal(__localq0__, "", _); _
TRAC   | Eval __localq0__ = data.main.exception[_][_]
TRAC   | Unify __localq0__ = data.main.exception[_][_]
TRAC   | Fail __localq0__ = data.main.exception[_][_]
file: combine/combine.yaml | query: data.main.violation
TRAC   Enter data.main.violation = _
TRAC   | Eval data.main.violation = _
TRAC   | Unify data.main.violation = _
TRAC   | Index data.main.violation (matched 1 rule)
TRAC   | Enter data.main.violation
TRAC   | | Eval input[i].contents.kind = "Deployment"
TRAC   | | Unify input[i].contents.kind = "Deployment"
TRAC   | | Unify "apiVersion" = i
TRAC   | | Unify "kind" = i
TRAC   | | Unify "metadata" = i
TRAC   | | Unify "spec" = i
TRAC   | | Fail input[i].contents.kind = "Deployment"
TRAC   | Unify set() = _
TRAC   | Exit data.main.violation = _
TRAC   Redo data.main.violation = _
TRAC   | Redo data.main.violation = _
file: combine/combine.yaml | query: data.main.exception[_][_] == ""
TRAC   Enter __localq0__ = data.main.exception[_][_]; equal(__localq0__, "", _); _
TRAC   | Eval __localq0__ = data.main.exception[_][_]
TRAC   | Unify __localq0__ = data.main.exception[_][_]
TRAC   | Fail __localq0__ = data.main.exception[_][_]
file: combine/combine.yaml | query: data.main.violation
TRAC   Enter data.main.violation = _
TRAC   | Eval data.main.violation = _
TRAC   | Unify data.main.violation = _
TRAC   | Index data.main.violation (matched 1 rule)
TRAC   | Enter data.main.violation
TRAC   | | Eval input[i].contents.kind = "Deployment"
TRAC   | | Unify input[i].contents.kind = "Deployment"
TRAC   | | Unify "apiVersion" = i
TRAC   | | Unify "kind" = i
TRAC   | | Unify "metadata" = i
TRAC   | | Unify "spec" = i
TRAC   | | Fail input[i].contents.kind = "Deployment"
TRAC   | Unify set() = _
TRAC   | Exit data.main.violation = _
TRAC   Redo data.main.violation = _
TRAC   | Redo data.main.violation = _
file: combine/combine.yaml | query: data.main.exception[_][_] == ""
TRAC   Enter __localq0__ = data.main.exception[_][_]; equal(__localq0__, "", _); _
TRAC   | Eval __localq0__ = data.main.exception[_][_]
TRAC   | Unify __localq0__ = data.main.exception[_][_]
TRAC   | Fail __localq0__ = data.main.exception[_][_]
file: combine/combine.yaml | query: data.main.violation
TRAC   Enter data.main.violation = _
TRAC   | Eval data.main.violation = _
TRAC   | Unify data.main.violation = _
TRAC   | Index data.main.violation (matched 1 rule)
TRAC   | Enter data.main.violation
TRAC   | | Eval input[i].contents.kind = "Deployment"
TRAC   | | Unify input[i].contents.kind = "Deployment"
TRAC   | | Unify "apiVersion" = i
TRAC   | | Unify "kind" = i
TRAC   | | Unify "metadata" = i
TRAC   | | Unify "spec" = i
TRAC   | | Fail input[i].contents.kind = "Deployment"
TRAC   | Unify set() = _
TRAC   | Exit data.main.violation = _
TRAC   Redo data.main.violation = _
TRAC   | Redo data.main.violation = _

@boranx boranx added the bug Something isn't working label Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants