fix: handle GrafanaFolder negative-polarity condition (#29395)
Project: argoproj/argo-cd | Language: Go | Concepts: error-handling, testing-strategy | Difficulty: mid
Link: https://github.com/argoproj/argo-cd/pull/29397
The problem
The Grafana Operator (v5.25.0+) introduced a new FolderUIDMismatch condition on GrafanaFolder resources, which uses negative polarity:
status: Falsewith reasonConsistentUIDmeans the folder is healthy (UIDs are consistent).status: Truemeans there is a UID mismatch (degraded).
Argo CD's health check customization for this resource previously treated all False conditions as degraded, so healthy folders were incorrectly shown as degraded when this new condition appeared.
Why it's non-trivial
A naive fix would just ignore the new condition or invert its polarity, but this could break handling for other conditions (like FolderSynchronized=False, which really does mean degraded). The fix needs to:
- Recognize and handle the special negative-polarity logic for
FolderUIDMismatchonly. - Preserve existing behavior for all other conditions.
- Add test coverage for both healthy and degraded cases with this new condition.
The approach
1. Special-case handling for FolderUIDMismatch negative polarity
The core logic change is in the Lua health check script:
- if condition.status == "False" then
+ -- FolderUIDMismatch is a negative-polarity condition: False means
+ -- the UIDs are consistent, not that the resource is unhealthy.
+ if condition.status == "True" and condition.type == "FolderUIDMismatch" then
+ hs.status = "Degraded"
+ return hs
+ end
+
+ if condition.status == "False" and condition.type ~= "FolderUIDMismatch" then
hs.status = "Degraded"
return hs
end
What this does:
- If
condition.type == "FolderUIDMismatch"andstatus == "True", set status to Degraded (UIDs are mismatched). - If
condition.type == "FolderUIDMismatch"andstatus == "False", do nothing (UIDs are consistent; healthy). - For all other conditions, keep the original logic:
status == "False"means Degraded.
2. Add test cases for both polarities
Two new test fixtures are added to ensure the logic works for both healthy and degraded states:
Healthy (UIDs consistent):
# resource_customizations/grafana.integreatly.org/GrafanaFolder/testdata/healthy-negative-polarity-condition.yaml
status:
conditions:
- type: FolderSynchronized
status: 'True'
reason: ApplySuccessful
message: Folder was successfully applied to 1 instances
- type: FolderUIDMismatch
status: 'False'
reason: ConsistentUID
message: UIDs consistent across all 1 instances
Degraded (UIDs mismatched):
# resource_customizations/grafana.integreatly.org/GrafanaFolder/testdata/degraded-folder-uid-mismatch.yaml
status:
conditions:
- type: FolderSynchronized
status: 'True'
reason: ApplySuccessful
message: Folder was successfully applied to 1 instances
- type: FolderUIDMismatch
status: 'True'
reason: FolderUIDInferred
message: |
UID was inferred for 1 out of 1 instances:
- grafana-operator/grafana: inferred bar-folder
Test assertions in health_test.yaml:
- healthStatus:
status: Healthy
message: >-
ApplySuccessful for FolderSynchronized because Folder was successfully applied to 1 instances, ConsistentUID for FolderUIDMismatch because UIDs consistent across all 1 instances
inputPath: testdata/healthy-negative-polarity-condition.yaml
- healthStatus:
status: Degraded
message: >-
ApplySuccessful for FolderSynchronized because Folder was successfully applied to 1 instances, FolderUIDInferred for FolderUIDMismatch because UID was inferred for 1 out of 1 instances:
- grafana-operator/grafana: inferred bar-folder
inputPath: testdata/degraded-folder-uid-mismatch.yaml
What this does:
- Ensures the new logic correctly marks healthy and degraded states for the new condition.
From the review thread
No notable review discussion on this PR.
Takeaways
- Handle negative-polarity conditions explicitly: Not all boolean conditions have the same meaning—sometimes
Falsemeans healthy. Code should recognize and handle these exceptions, not assume allFalsemeans degraded. - Preserve existing behavior for unrelated cases: When adding special-case logic, ensure it doesn't break handling for other conditions or types.
- Add regression tests for both polarities: When fixing a bug around condition evaluation, always add tests for both the "healthy" and "degraded" cases to prevent future regressions.