@@ -101,7 +101,8 @@ func (r *Reconciler) handleDelete(ctx context.Context, crp *fleetv1beta1.Cluster
101
101
}
102
102
klog .V (2 ).InfoS ("Removed crp-cleanup finalizer" , "clusterResourcePlacement" , crpKObj )
103
103
r .Recorder .Event (crp , corev1 .EventTypeNormal , "PlacementCleanupFinalizerRemoved" , "Deleted the snapshots and removed the placement cleanup finalizer" )
104
- metrics .FleetPlacementStatus .Delete (prometheus.Labels {"name" : crp .Name })
104
+ metrics .FleetPlacementComplete .DeletePartialMatch (prometheus.Labels {"name" : crp .Name })
105
+ metrics .FleetPlacementStatus .DeletePartialMatch (prometheus.Labels {"name" : crp .Name })
105
106
return ctrl.Result {}, nil
106
107
}
107
108
@@ -177,6 +178,8 @@ func (r *Reconciler) handleUpdate(ctx context.Context, crp *fleetv1beta1.Cluster
177
178
klog .ErrorS (updateErr , "Failed to update the status" , "clusterResourcePlacement" , crpKObj )
178
179
return ctrl.Result {}, controller .NewUpdateIgnoreConflictError (updateErr )
179
180
}
181
+ metrics .FleetPlacementStatus .DeletePartialMatch (prometheus.Labels {"name" : crp .Name })
182
+ metrics .FleetPlacementStatus .WithLabelValues (crp .Name , strconv .FormatInt (crp .Generation , 10 ), scheduleCondition .Type , string (scheduleCondition .Status )).SetToCurrentTime ()
180
183
return ctrl.Result {}, err
181
184
}
182
185
@@ -214,6 +217,7 @@ func (r *Reconciler) handleUpdate(ctx context.Context, crp *fleetv1beta1.Cluster
214
217
r .Recorder .Event (crp , corev1 .EventTypeNormal , i .EventReasonForTrue (), i .EventMessageForTrue ())
215
218
}
216
219
}
220
+ emitPlacementStatusMetric (crp )
217
221
218
222
// Rollout is considered to be completed when all the expected condition types are set to the
219
223
// True status.
@@ -222,12 +226,15 @@ func (r *Reconciler) handleUpdate(ctx context.Context, crp *fleetv1beta1.Cluster
222
226
klog .V (2 ).InfoS ("Placement has finished the rollout process and reached the desired status" , "clusterResourcePlacement" , crpKObj , "generation" , crp .Generation )
223
227
r .Recorder .Event (crp , corev1 .EventTypeNormal , "PlacementRolloutCompleted" , "Placement has finished the rollout process and reached the desired status" )
224
228
}
225
- metrics .FleetPlacementStatus .WithLabelValues (crp .Name ).Set (1 )
229
+ metrics .FleetPlacementComplete .DeletePartialMatch (prometheus.Labels {"name" : crp .Name })
230
+ metrics .FleetPlacementComplete .WithLabelValues (crp .Name , "true" ).SetToCurrentTime ()
226
231
// We don't need to requeue any request now by watching the binding changes
227
232
return ctrl.Result {}, nil
228
233
}
229
234
230
- metrics .FleetPlacementStatus .WithLabelValues (crp .Name ).Set (0 )
235
+ metrics .FleetPlacementComplete .DeletePartialMatch (prometheus.Labels {"name" : crp .Name })
236
+ metrics .FleetPlacementComplete .WithLabelValues (crp .Name , "false" ).SetToCurrentTime ()
237
+
231
238
if ! isClusterScheduled {
232
239
// Note:
233
240
// If the scheduledCondition is failed, it means the placement requirement cannot be satisfied fully. For example,
@@ -1035,3 +1042,23 @@ func isRolloutCompleted(crp *fleetv1beta1.ClusterResourcePlacement) bool {
1035
1042
func isCRPScheduled (crp * fleetv1beta1.ClusterResourcePlacement ) bool {
1036
1043
return condition .IsConditionStatusTrue (crp .GetCondition (string (fleetv1beta1 .ClusterResourcePlacementScheduledConditionType )), crp .Generation )
1037
1044
}
1045
+
1046
+ func emitPlacementStatusMetric (crp * fleetv1beta1.ClusterResourcePlacement ) {
1047
+ // Check CRP Scheduled condition
1048
+ cond := crp .GetCondition (string (fleetv1beta1 .ClusterResourcePlacementScheduledConditionType ))
1049
+ if cond != nil {
1050
+ metrics .FleetPlacementStatus .DeletePartialMatch (prometheus.Labels {"name" : crp .Name })
1051
+ metrics .FleetPlacementStatus .WithLabelValues (crp .Name , strconv .FormatInt (crp .Generation , 10 ), cond .Type , string (cond .Status )).SetToCurrentTime ()
1052
+ }
1053
+ // Check CRP expected conditions
1054
+ expectedCondTypes := determineExpectedCRPAndResourcePlacementStatusCondType (crp )
1055
+ for _ , i := range expectedCondTypes {
1056
+ cond := crp .GetCondition (string (i .ClusterResourcePlacementConditionType ()))
1057
+ if cond != nil { // emit if found
1058
+ metrics .FleetPlacementStatus .DeletePartialMatch (prometheus.Labels {"name" : crp .Name })
1059
+ metrics .FleetPlacementStatus .WithLabelValues (crp .Name , strconv .FormatInt (crp .Generation , 10 ), cond .Type , string (cond .Status )).SetToCurrentTime ()
1060
+ } else {
1061
+ return // return if not found
1062
+ }
1063
+ }
1064
+ }
0 commit comments