@@ -12,6 +12,10 @@ import (
12
12
"github.com/argoproj/gitops-engine/pkg/utils/kube"
13
13
)
14
14
15
+ const (
16
+ AnnotationIgnoreRestartPolicy = "argocd.argoproj.io/ignore-restart-policy"
17
+ )
18
+
15
19
func getPodHealth (obj * unstructured.Unstructured ) (* HealthStatus , error ) {
16
20
gvk := obj .GroupVersionKind ()
17
21
switch gvk {
@@ -93,9 +97,9 @@ func getCorev1PodHealth(pod *corev1.Pod) (*HealthStatus, error) {
93
97
}
94
98
95
99
return & HealthStatus {Status : HealthStatusDegraded , Message : "" }, nil
100
+
96
101
case corev1 .PodRunning :
97
- switch pod .Spec .RestartPolicy {
98
- case corev1 .RestartPolicyAlways :
102
+ getHealthStatus := func (pod * corev1.Pod ) (* HealthStatus , error ) {
99
103
// if pod is ready, it is automatically healthy
100
104
if podutils .IsPodReady (pod ) {
101
105
return & HealthStatus {
@@ -117,14 +121,24 @@ func getCorev1PodHealth(pod *corev1.Pod) (*HealthStatus, error) {
117
121
Status : HealthStatusProgressing ,
118
122
Message : pod .Status .Message ,
119
123
}, nil
120
- case corev1 .RestartPolicyOnFailure , corev1 .RestartPolicyNever :
121
- // pods set with a restart policy of OnFailure or Never, have a finite life.
122
- // These pods are typically resource hooks. Thus, we consider these as Progressing
123
- // instead of healthy.
124
- return & HealthStatus {
125
- Status : HealthStatusProgressing ,
126
- Message : pod .Status .Message ,
127
- }, nil
124
+ }
125
+ if _ , hook := pod .Annotations [AnnotationIgnoreRestartPolicy ]; hook {
126
+ return getHealthStatus (pod )
127
+ } else {
128
+ switch pod .Spec .RestartPolicy {
129
+ case corev1 .RestartPolicyAlways :
130
+ return getHealthStatus (pod )
131
+ case corev1 .RestartPolicyOnFailure , corev1 .RestartPolicyNever :
132
+ // Most pods set with a restart policy of OnFailure or Never, have a finite life.
133
+ // These pods are typically resource hooks. Thus, we consider these as Progressing
134
+ // instead of healthy. If this is unwanted, e.g., when the pod is managed by an
135
+ // operator and therefore has a restart policy of OnFailure or Never, then use the
136
+ // the AnnotationIgnoreRestartPolicy annotation.
137
+ return & HealthStatus {
138
+ Status : HealthStatusProgressing ,
139
+ Message : pod .Status .Message ,
140
+ }, nil
141
+ }
128
142
}
129
143
}
130
144
return & HealthStatus {
0 commit comments