Skip to content

Commit 71fd4e5

Browse files
fix: Check placement exists before length check (#22060) (cherry-pick #22057) (#22089)
Signed-off-by: Dale Haiducek <[email protected]> Co-authored-by: Dale Haiducek <[email protected]>
1 parent cb1df5d commit 71fd4e5

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

resource_customizations/policy.open-cluster-management.io/Policy/health.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
hs = {}
2+
23
if obj.status == nil then
34
hs.status = "Progressing"
45
hs.message = "Waiting for the status to be reported"
@@ -7,7 +8,7 @@ end
78

89
-- A policy will not have a compliant field but will have a placement key set if
910
-- it is not being applied to any clusters
10-
if obj.status.compliant == nil and #obj.status.placement > 0 and obj.status.status == nil then
11+
if obj.status.compliant == nil and obj.status.status == nil and obj.status.placement ~= nil and #obj.status.placement > 0 then
1112
hs.status = "Healthy"
1213
hs.message = "No clusters match this policy"
1314
return hs
@@ -24,6 +25,8 @@ if obj.status.compliant == "Compliant" then
2425
else
2526
hs.status = "Degraded"
2627
end
28+
29+
-- Collect NonCompliant clusters for the policy
2730
noncompliants = {}
2831
if obj.status.status ~= nil then
2932
-- "root" policy
@@ -50,4 +53,5 @@ elseif obj.status.details ~= nil then
5053
hs.message = "NonCompliant templates: " .. table.concat(noncompliants, ", ")
5154
end
5255
end
56+
5357
return hs

resource_customizations/policy.open-cluster-management.io/Policy/health_test.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ tests:
1919
status: Progressing
2020
message: Waiting for the status to be reported
2121
inputPath: testdata/progressing_no_status.yaml
22+
- healthStatus:
23+
status: Progressing
24+
message: Waiting for the status to be reported
25+
inputPath: testdata/progressing_nil_status.yaml
2226
- healthStatus:
2327
status: Healthy
2428
message: No clusters match this policy
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
apiVersion: policy.open-cluster-management.io/v1
2+
kind: Policy
3+
metadata:
4+
annotations:
5+
argocd.argoproj.io/compare-options: IgnoreExtraneous
6+
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
7+
labels:
8+
argocd.argoproj.io/instance: acm
9+
name: acm-hub-ca-policy
10+
namespace: open-cluster-management
11+
spec:
12+
disabled: false
13+
policy-templates:
14+
- objectDefinition:
15+
apiVersion: policy.open-cluster-management.io/v1
16+
kind: ConfigurationPolicy
17+
metadata:
18+
name: acm-hub-ca-config-policy
19+
spec:
20+
namespaceSelector:
21+
include:
22+
- default
23+
object-templates:
24+
- complianceType: mustonlyhave
25+
objectDefinition:
26+
apiVersion: v1
27+
data:
28+
hub-kube-root-ca.crt: '{{hub fromConfigMap "" "kube-root-ca.crt" "ca.crt"
29+
| base64enc hub}}'
30+
hub-openshift-service-ca.crt: '{{hub fromConfigMap "" "openshift-service-ca.crt"
31+
"service-ca.crt" | base64enc hub}}'
32+
kind: Secret
33+
metadata:
34+
name: hub-ca
35+
namespace: golang-external-secrets
36+
type: Opaque
37+
- complianceType: mustonlyhave
38+
objectDefinition:
39+
apiVersion: v1
40+
data:
41+
hub-kube-root-ca.crt: |
42+
{{hub fromConfigMap "" "kube-root-ca.crt" "ca.crt" | autoindent hub}}
43+
hub-openshift-service-ca.crt: |
44+
{{hub fromConfigMap "" "openshift-service-ca.crt" "service-ca.crt" | autoindent hub}}
45+
kind: ConfigMap
46+
metadata:
47+
name: trusted-hub-bundle
48+
namespace: imperative
49+
remediationAction: enforce
50+
severity: medium
51+
remediationAction: enforce

resource_customizations/policy.open-cluster-management.io/Policy/testdata/progressing_no_status.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ spec:
4949
remediationAction: enforce
5050
severity: medium
5151
remediationAction: enforce
52+
status: {}

0 commit comments

Comments
 (0)