Skip to content

Commit 4a14051

Browse files
authoredNov 21, 2024··
feat(app): add ignore-healthcheck annotation (#20462)
Signed-off-by: cef <moncef.abboud95@gmail.com>
1 parent b6cc0e6 commit 4a14051

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed
 

‎common/common.go

+4
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ const (
185185
// AnnotationCompareOptions is a comma-separated list of options for comparison
186186
AnnotationCompareOptions = "argocd.argoproj.io/compare-options"
187187

188+
// AnnotationIgnoreHealthCheck when set on an Application's immediate child indicates that its health check
189+
// can be disregarded.
190+
AnnotationIgnoreHealthCheck = "argocd.argoproj.io/ignore-healthcheck"
191+
188192
// AnnotationKeyManagedBy is annotation name which indicates that k8s resource is managed by an application.
189193
AnnotationKeyManagedBy = "managed-by"
190194
// AnnotationValueManagedByArgoCD is a 'managed-by' annotation value for resources managed by Argo CD

‎controller/health.go

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
log "github.com/sirupsen/logrus"
1111
"k8s.io/apimachinery/pkg/runtime/schema"
1212

13+
"github.com/argoproj/argo-cd/v2/common"
1314
"github.com/argoproj/argo-cd/v2/pkg/apis/application"
1415
appv1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
1516
"github.com/argoproj/argo-cd/v2/util/lua"
@@ -24,6 +25,9 @@ func setApplicationHealth(resources []managedResource, statuses []appv1.Resource
2425
if res.Target != nil && hookutil.Skip(res.Target) {
2526
continue
2627
}
28+
if res.Target != nil && res.Target.GetAnnotations() != nil && res.Target.GetAnnotations()[common.AnnotationIgnoreHealthCheck] == "true" {
29+
continue
30+
}
2731

2832
if res.Live != nil && (hookutil.IsHook(res.Live) || ignore.Ignore(res.Live)) {
2933
continue

‎controller/health_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ func TestSetApplicationHealth(t *testing.T) {
6565
healthStatus, err = setApplicationHealth(resources, resourceStatuses, nil, app, true)
6666
require.NoError(t, err)
6767
assert.Equal(t, health.HealthStatusHealthy, healthStatus.Status)
68+
69+
// now we set the `argocd.argoproj.io/ignore-healthcheck: "true"` annotation on the job's target.
70+
// The app is considered healthy
71+
failedJob.SetAnnotations(nil)
72+
failedJobIgnoreHealthcheck := resourceFromFile("./testdata/job-failed-ignore-healthcheck.yaml")
73+
resources[1].Target = &failedJobIgnoreHealthcheck
74+
healthStatus, err = setApplicationHealth(resources, resourceStatuses, nil, app, true)
75+
require.NoError(t, err)
76+
assert.Equal(t, health.HealthStatusHealthy, healthStatus.Status)
6877
}
6978

7079
func TestSetApplicationHealth_ResourceHealthNotPersisted(t *testing.T) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
annotations:
5+
argocd.argoproj.io/ignore-healthcheck: "true"
6+
labels:
7+
job-name: fail
8+
name: fail
9+
namespace: argoci-workflows
10+
selfLink: /apis/batch/v1/namespaces/argoci-workflows/jobs/fail
11+
spec:
12+
backoffLimit: 0
13+
completions: 1
14+
parallelism: 1
15+
template:
16+
metadata:
17+
creationTimestamp: null
18+
labels:
19+
job-name: fail
20+
spec:
21+
containers:
22+
- command:
23+
- sh
24+
- -c
25+
- exit 1
26+
image: alpine:latest
27+
imagePullPolicy: Always
28+
name: fail
29+
resources: {}
30+
terminationMessagePath: /dev/termination-log
31+
terminationMessagePolicy: File
32+
dnsPolicy: ClusterFirst
33+
restartPolicy: Never
34+
schedulerName: default-scheduler
35+
securityContext: {}
36+
terminationGracePeriodSeconds: 30

‎docs/operator-manual/health.md

+13
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,16 @@ App (healthy)
229229
└── CustomResource (healthy) <- This resource's health check needs to be fixed to mark the App as unhealthy
230230
└── CustomChildResource (unhealthy)
231231
```
232+
## Ignoring Child Resource Health Check in Applications
233+
234+
To ignore the health check of an immediate child resource within an Application, set the annotation `argocd.argoproj.io/ignore-healthcheck` to `true`. For example:
235+
236+
```yaml
237+
apiVersion: apps/v1
238+
kind: Deployment
239+
metadata:
240+
annotations:
241+
argocd.argoproj.io/ignore-healthcheck: "true"
242+
```
243+
244+
By doing this, the health status of the Deployment will not affect the health of its parent Application.

0 commit comments

Comments
 (0)
Please sign in to comment.