Skip to content

Commit 99aaf43

Browse files
fix: Policy/policy.open-cluster-management.io stuck in progressing status when no clusters match the policy (#21296) (cherry-pick #21297) (#21594)
Signed-off-by: Michele Baldessari <[email protected]> Co-authored-by: Michele Baldessari <[email protected]>
1 parent c8a62bb commit 99aaf43

File tree

4 files changed

+130
-1
lines changed

4 files changed

+130
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
hs = {}
2-
if obj.status == nil or obj.status.compliant == nil then
2+
if obj.status == nil then
33
hs.status = "Progressing"
44
hs.message = "Waiting for the status to be reported"
55
return hs
66
end
7+
8+
-- A policy will not have a compliant field but will have a placement key set if
9+
-- 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+
hs.status = "Healthy"
12+
hs.message = "No clusters match this policy"
13+
return hs
14+
end
15+
16+
if obj.status.compliant == nil then
17+
hs.status = "Progressing"
18+
hs.message = "Waiting for the status to be reported"
19+
return hs
20+
end
21+
722
if obj.status.compliant == "Compliant" then
823
hs.status = "Healthy"
924
else

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ tests:
1515
status: Healthy
1616
message: All templates are compliant
1717
inputPath: testdata/healthy_replicated.yaml
18+
- healthStatus:
19+
status: Progressing
20+
message: Waiting for the status to be reported
21+
inputPath: testdata/progressing_no_status.yaml
22+
- healthStatus:
23+
status: Healthy
24+
message: No clusters match this policy
25+
inputPath: testdata/healthy_with_placement_empty_compliant.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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
52+
status:
53+
placement:
54+
- placementBinding: acm-hub-ca-policy-placement-binding
55+
placementRule: acm-hub-ca-policy-placement
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

0 commit comments

Comments
 (0)