diff --git a/pkg/controllers/status/workstatus_controller.go b/pkg/controllers/status/workstatus_controller.go index 3d5d7c5d2..4b3ee6323 100644 --- a/pkg/controllers/status/workstatus_controller.go +++ b/pkg/controllers/status/workstatus_controller.go @@ -294,6 +294,18 @@ func (c *WorkStatusController) reflectStatus(work *workv1alpha1.Work, clusterObj return nil } + var resourceHealth workv1alpha1.ResourceHealth + // When an unregistered resource kind is requested with the ResourceInterpreter, + // the interpreter will return an error, we treat its health status as Unknown. + healthy, err := c.ResourceInterpreter.InterpretHealth(clusterObj) + if err != nil { + resourceHealth = workv1alpha1.ResourceUnknown + } else if healthy { + resourceHealth = workv1alpha1.ResourceHealthy + } else { + resourceHealth = workv1alpha1.ResourceUnhealthy + } + identifier, err := c.buildStatusIdentifier(work, clusterObj) if err != nil { return err @@ -302,6 +314,7 @@ func (c *WorkStatusController) reflectStatus(work *workv1alpha1.Work, clusterObj manifestStatus := workv1alpha1.ManifestStatus{ Identifier: *identifier, Status: statusRaw, + Health: resourceHealth, } workCopy := work.DeepCopy() diff --git a/pkg/resourceinterpreter/defaultinterpreter/default.go b/pkg/resourceinterpreter/defaultinterpreter/default.go index 672feb9cc..4702bf2e8 100644 --- a/pkg/resourceinterpreter/defaultinterpreter/default.go +++ b/pkg/resourceinterpreter/defaultinterpreter/default.go @@ -63,7 +63,9 @@ func (e *DefaultInterpreter) HookEnabled(kind schema.GroupVersionKind, operation case configv1alpha1.InterpreterOperationInterpretStatus: return true case configv1alpha1.InterpreterOperationInterpretHealth: - return true + if _, exist := e.healthHandlers[kind]; exist { + return true + } // TODO(RainbowMango): more cases should be added here } diff --git a/pkg/util/helper/workstatus.go b/pkg/util/helper/workstatus.go index c55a5f605..d33517c71 100644 --- a/pkg/util/helper/workstatus.go +++ b/pkg/util/helper/workstatus.go @@ -167,6 +167,7 @@ func assembleWorkStatus(works []workv1alpha1.Work, workload *unstructured.Unstru ClusterName: clusterName, Applied: applied, AppliedMessage: appliedMsg, + Health: workv1alpha2.ResourceUnknown, } statuses = append(statuses, aggregatedStatus) continue @@ -176,6 +177,7 @@ func assembleWorkStatus(works []workv1alpha1.Work, workload *unstructured.Unstru aggregatedStatus := workv1alpha2.AggregatedStatusItem{ ClusterName: clusterName, Applied: applied, + Health: workv1alpha2.ResourceUnknown, } for _, manifestStatus := range work.Status.ManifestStatuses { @@ -185,6 +187,7 @@ func assembleWorkStatus(works []workv1alpha1.Work, workload *unstructured.Unstru } if equal { aggregatedStatus.Status = manifestStatus.Status + aggregatedStatus.Health = workv1alpha2.ResourceHealth(manifestStatus.Health) break } }