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

[BUG] Policies with PreConditions are marked as "failed" in the metrics #2629

Closed
diranged opened this issue Oct 28, 2021 · 2 comments · Fixed by #2643
Closed

[BUG] Policies with PreConditions are marked as "failed" in the metrics #2629

diranged opened this issue Oct 28, 2021 · 2 comments · Fixed by #2643
Assignees
Labels
bug Something isn't working

Comments

@diranged
Copy link

diranged commented Oct 28, 2021

Software version numbers

  • Kubernetes version: 1.21
  • Kubernetes platform (if applicable; ex., EKS, GKE, OpenShift): EKS
  • Kyverno version: 1.5.1

Describe the bug
Slack Thread: https://kubernetes.slack.com/archives/CLGR9BJU9/p1635458987180000

Any Policy or ClusterPolicy with a preconditions field will report rule_result=fail for rules that do not match the precondition. This makes it hard to monitor for rule failures when preconditions are used to exclude a rule from being applied.

To Reproduce

Create this rule:

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: set-service-defaults
spec:
  background: false
  validationFailureAction: enforce
  rules:
  - name: set-service-defaults
    match:
      resources:
        kinds: [Service]
    preconditions:
      - key: "{{request.object.spec.type}}"
        operator: Equals
        value: LoadBalancer
    mutate:
      patchStrategicMerge:
        metadata:
          annotations:
            service.beta.kubernetes.io/aws-load-balancer-additional-resource-tags: "kubernetes_namespace={{request.object.metadata.namespace}},project={{request.object.metadata.namespace}}"

Then create some Service objects that are not LoadBalancer types. Check your metrics and you will see that they are continually being marked as rule_result=fail in the metrics, while they are not marked that way in the PolicyReport.

image

Expected behavior

The data that populates the metrics should be the same as the data we see in the PolicyReport.

@diranged diranged added the bug Something isn't working label Oct 28, 2021
@chipzoller
Copy link
Member

/cc @yashvardhan-kukreja

@yashvardhan-kukreja
Copy link
Contributor

ack'd on it 👍🏼

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
4 participants