argoproj / argo-cd

Declarative Continuous Deployment for Kubernetes
https://argo-cd.readthedocs.io
Apache License 2.0
17.57k stars 5.35k forks source link

Policy/policy.open-cluster-management.io health check is broken #20108

Open itewk opened 1 week ago

itewk commented 1 week ago

Checklist:

Describe the bug

When using https://github.com/argoproj/argo-cd/blob/master/resource_customizations/policy.open-cluster-management.io/Policy/health.lua i get an error of the following type:

error setting app health: failed to get resource health for "Policy" with name "XXXX" in namespace "local-cluster": :35: invalid value (nil) at index 1 in table for concat stack traceback: [G]: in function 'concat' :35: in main chunk [G]: ?

I beleive I have narrowed down why this wasn't being caught by tests because it only seems to be an issue when the NonCompliant hit is AFTER the Compliant hit due to the way indexing and the way table.getn worked.

To Reproduce

  1. Add https://github.com/argoproj/argo-cd/blob/master/resource_customizations/policy.open-cluster-management.io/Policy/health.lua to your resource customizations
  2. create a policy that has a Compliant status then a NonCompliant status, then a Compliant status
  3. get the error

Expected behavior

Status should be correctly returned such as:

NonCompliant templates: validate-openshift-gitops-applications2, inform-gatekeeper-audit-argocd-applications-healthy-and-sycned

Screenshots

N/A

Version

argocd: v2.12.3+6b9cd82
  BuildDate: 2024-08-27T15:33:41Z
  GitCommit: 6b9cd828c6e9807398869ad5ac44efd2c28422d6
  GitTreeState: clean
  GoVersion: go1.23.0
  Compiler: gc
  Platform: darwin/arm64
WARN[0000] Failed to invoke grpc call. Use flag --grpc-web in grpc calls. To avoid this warning message, use flag --grpc-web.
argocd-server: v2.11.6+089247d
  BuildDate: 2024-07-23T00:41:35Z
  GitCommit: 089247df0f15e64813d00a2d1271a2095feecad4
  GitTreeState: clean
  GoVersion: go1.21.11 (Red Hat 1.21.11-1.module+el8.10.0+21986+2112108a)
  Compiler: gc
  Platform: linux/amd64
  ExtraBuildInfo: {Vendor Information: Red Hat OpenShift GitOps version: v1.13.1}
  Kustomize Version: v5.2.1 unknown
  Helm Version: v3.14.4+g81c902a
  Kubectl Version: v0.26.11
  Jsonnet Version: v0.20.0

Logs

If something other then the error message is needed let me know.

itewk commented 1 week ago

proposed fix: https://github.com/argoproj/argo-cd/pull/20109/files