github.com/argoproj/argo-cd@v1.8.7/util/health/health.go (about) 1 package health 2 3 import ( 4 "github.com/argoproj/gitops-engine/pkg/health" 5 hookutil "github.com/argoproj/gitops-engine/pkg/sync/hook" 6 "github.com/argoproj/gitops-engine/pkg/sync/ignore" 7 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 8 9 appv1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1" 10 "github.com/argoproj/argo-cd/util/lua" 11 ) 12 13 // SetApplicationHealth updates the health statuses of all resources performed in the comparison 14 func SetApplicationHealth(resStatuses []*appv1.ResourceStatus, liveObjs []*unstructured.Unstructured, resourceOverrides map[string]appv1.ResourceOverride, filter func(obj *unstructured.Unstructured) bool) (*appv1.HealthStatus, error) { 15 var savedErr error 16 appHealth := appv1.HealthStatus{Status: health.HealthStatusHealthy} 17 for i, liveObj := range liveObjs { 18 var healthStatus *health.HealthStatus 19 var err error 20 if liveObj == nil { 21 healthStatus = &health.HealthStatus{Status: health.HealthStatusMissing} 22 } else { 23 if filter(liveObj) { 24 healthStatus, err = health.GetResourceHealth(liveObj, lua.ResourceHealthOverrides(resourceOverrides)) 25 if err != nil && savedErr == nil { 26 savedErr = err 27 } 28 } 29 } 30 if healthStatus != nil { 31 resHealth := appv1.HealthStatus{Status: healthStatus.Status, Message: healthStatus.Message} 32 resStatuses[i].Health = &resHealth 33 ignore := ignoreLiveObjectHealth(liveObj, resHealth) 34 if !ignore && health.IsWorse(appHealth.Status, healthStatus.Status) { 35 appHealth.Status = healthStatus.Status 36 } 37 } 38 } 39 return &appHealth, savedErr 40 } 41 42 // ignoreLiveObjectHealth determines if we should not allow the live object to affect the overall 43 // health of the application (e.g. hooks, missing child applications) 44 func ignoreLiveObjectHealth(liveObj *unstructured.Unstructured, resHealth appv1.HealthStatus) bool { 45 if liveObj != nil { 46 // Don't allow resource hooks to affect health status 47 if hookutil.IsHook(liveObj) || ignore.Ignore(liveObj) { 48 return true 49 } 50 gvk := liveObj.GroupVersionKind() 51 if gvk.Group == "argoproj.io" && gvk.Kind == "Application" && (resHealth.Status == health.HealthStatusMissing || resHealth.Status == health.HealthStatusUnknown) { 52 // Covers the app-of-apps corner case where child app is deployed but that app itself 53 // has a status of 'Missing', which we don't want to cause the parent's health status 54 // to also be Missing 55 return true 56 } 57 } 58 return false 59 }