@@ -101,7 +101,8 @@ func (r *Reconciler) handleDelete(ctx context.Context, crp *fleetv1beta1.Cluster
101101 }
102102 klog .V (2 ).InfoS ("Removed crp-cleanup finalizer" , "clusterResourcePlacement" , crpKObj )
103103 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 .Delete (prometheus.Labels {"name" : crp .Name })
105+ metrics .FleetPlacementStatus .DeletePartialMatch (prometheus.Labels {"name" : crp .Name })
105106 return ctrl.Result {}, nil
106107}
107108
@@ -222,12 +223,12 @@ func (r *Reconciler) handleUpdate(ctx context.Context, crp *fleetv1beta1.Cluster
222223 klog .V (2 ).InfoS ("Placement has finished the rollout process and reached the desired status" , "clusterResourcePlacement" , crpKObj , "generation" , crp .Generation )
223224 r .Recorder .Event (crp , corev1 .EventTypeNormal , "PlacementRolloutCompleted" , "Placement has finished the rollout process and reached the desired status" )
224225 }
225- metrics .FleetPlacementStatus .WithLabelValues (crp .Name ).Set ( 1 )
226+ metrics .FleetPlacementComplete .WithLabelValues (crp .Name ).SetToCurrentTime ( )
226227 // We don't need to requeue any request now by watching the binding changes
227228 return ctrl.Result {}, nil
228229 }
229230
230- metrics .FleetPlacementStatus .WithLabelValues (crp .Name ).Set (0 )
231+ metrics .FleetPlacementComplete .WithLabelValues (crp .Name ).Set (0 )
231232 if ! isClusterScheduled {
232233 // Note:
233234 // If the scheduledCondition is failed, it means the placement requirement cannot be satisfied fully. For example,
@@ -1025,13 +1026,26 @@ func isRolloutCompleted(crp *fleetv1beta1.ClusterResourcePlacement) bool {
10251026
10261027 expectedCondTypes := determineExpectedCRPAndResourcePlacementStatusCondType (crp )
10271028 for _ , i := range expectedCondTypes {
1028- if ! condition .IsConditionStatusTrue (crp .GetCondition (string (i .ClusterResourcePlacementConditionType ())), crp .Generation ) {
1029+ cond := crp .GetCondition (string (i .ClusterResourcePlacementConditionType ()))
1030+ if cond != nil {
1031+ emitPlacementStatusMetric (cond , crp )
1032+ }
1033+ if ! condition .IsConditionStatusTrue (cond , crp .Generation ) {
10291034 return false
10301035 }
10311036 }
10321037 return true
10331038}
10341039
10351040func isCRPScheduled (crp * fleetv1beta1.ClusterResourcePlacement ) bool {
1036- return condition .IsConditionStatusTrue (crp .GetCondition (string (fleetv1beta1 .ClusterResourcePlacementScheduledConditionType )), crp .Generation )
1041+ cond := crp .GetCondition (string (fleetv1beta1 .ClusterResourcePlacementScheduledConditionType ))
1042+ if cond != nil {
1043+ emitPlacementStatusMetric (cond , crp )
1044+ }
1045+ return condition .IsConditionStatusTrue (cond , crp .Generation )
1046+ }
1047+
1048+ func emitPlacementStatusMetric (cond * metav1.Condition , crp * fleetv1beta1.ClusterResourcePlacement ) {
1049+ metrics .FleetPlacementStatus .DeletePartialMatch (prometheus.Labels {"name" : crp .Name , "conditionType" : cond .Type })
1050+ metrics .FleetPlacementStatus .WithLabelValues (crp .Name , strconv .FormatInt (crp .Generation , 10 ), cond .Type , strconv .FormatInt (cond .ObservedGeneration , 10 ), string (cond .Status ), cond .Reason ).Set (float64 (cond .LastTransitionTime .UnixNano () / 1e9 ))
10371051}
0 commit comments