Skip to content

Commit f231e8a

Browse files
author
Arvind Thirumurugan
committed
MetricCollector report condition
Signed-off-by: Arvind Thirumurugan <[email protected]>
1 parent 8dac379 commit f231e8a

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

apis/placement/v1beta1/metriccollector_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ const (
107107

108108
// MetricCollectorConditionTypeCollecting indicates metrics are being collected.
109109
MetricCollectorConditionTypeCollecting string = "MetricsCollecting"
110+
111+
// MetricCollectorConditionTypeReported indicates metrics were successfully reported to hub.
112+
MetricCollectorConditionTypeReported string = "MetricsReported"
110113
)
111114

112115
// +kubebuilder:object:root=true

pkg/controllers/metriccollector/controller.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,27 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
127127
// Sync MetricCollectorReport to hub cluster
128128
if err := r.syncReportToHub(ctx, mc); err != nil {
129129
klog.ErrorS(err, "Failed to sync MetricCollectorReport to hub", "metricCollector", req.NamespacedName)
130-
// Don't fail the reconcile loop, just log the error
130+
meta.SetStatusCondition(&mc.Status.Conditions, metav1.Condition{
131+
Type: placementv1beta1.MetricCollectorConditionTypeReported,
132+
Status: metav1.ConditionFalse,
133+
ObservedGeneration: mc.Generation,
134+
Reason: "ReportSyncFailed",
135+
Message: fmt.Sprintf("Failed to sync report to hub: %v", err),
136+
})
137+
} else {
138+
meta.SetStatusCondition(&mc.Status.Conditions, metav1.Condition{
139+
Type: placementv1beta1.MetricCollectorConditionTypeReported,
140+
Status: metav1.ConditionTrue,
141+
ObservedGeneration: mc.Generation,
142+
Reason: "ReportSyncSucceeded",
143+
Message: "Successfully synced metrics to hub cluster",
144+
})
145+
}
146+
147+
// Update status with reporting condition
148+
if err := r.MemberClient.Status().Update(ctx, mc); err != nil {
149+
klog.ErrorS(err, "Failed to update MetricCollector status with reporting condition", "metricCollector", req.NamespacedName)
150+
return ctrl.Result{}, err
131151
}
132152

133153
// Requeue after 30 seconds

0 commit comments

Comments
 (0)