@@ -248,6 +248,92 @@ var _ = Describe("Pod Metrics", func() {
248
248
_ , found = FindMetricWithLabelValues ("karpenter_pods_provisioning_startup_duration_seconds" , nil )
249
249
Expect (found ).To (BeTrue ())
250
250
})
251
+ It ("should update the pod startup and unstarted time metrics when the pod has succeeded" , func () {
252
+ p := test .Pod ()
253
+ p .Status .Phase = corev1 .PodPending
254
+
255
+ fakeClock .Step (1 * time .Hour )
256
+ cluster .MarkPodSchedulingDecisions (ctx , map [* corev1.Pod ]error {}, map [string ][]* corev1.Pod {"n1" : {p }}, map [string ][]* corev1.Pod {"nc1" : {p }})
257
+ ExpectApplied (ctx , env .Client , p )
258
+ ExpectReconcileSucceeded (ctx , podController , client .ObjectKeyFromObject (p )) //This will add pod to pending pods and unscheduled pods set
259
+ _ , found := FindMetricWithLabelValues ("karpenter_pods_unstarted_time_seconds" , map [string ]string {
260
+ "name" : p .GetName (),
261
+ "namespace" : p .GetNamespace (),
262
+ })
263
+ Expect (found ).To (BeTrue ())
264
+ _ , found = FindMetricWithLabelValues ("karpenter_pods_provisioning_unstarted_time_seconds" , map [string ]string {
265
+ "name" : p .GetName (),
266
+ "namespace" : p .GetNamespace (),
267
+ })
268
+ Expect (found ).To (BeTrue ())
269
+
270
+ // Pod has now succeeded but readiness condition is set to false because the pod is now completed
271
+ p .Status .Phase = corev1 .PodSucceeded
272
+ p .Status .Conditions = []corev1.PodCondition {
273
+ {Type : corev1 .PodReady , Status : corev1 .ConditionFalse , LastTransitionTime : metav1 .Now ()},
274
+ {Type : corev1 .PodScheduled , Status : corev1 .ConditionTrue , LastTransitionTime : metav1 .Now ()},
275
+ }
276
+ ExpectApplied (ctx , env .Client , p )
277
+ ExpectReconcileSucceeded (ctx , podController , client .ObjectKeyFromObject (p )) //This will check if the pod was scheduled and completed
278
+ _ , found = FindMetricWithLabelValues ("karpenter_pods_unstarted_time_seconds" , map [string ]string {
279
+ "name" : p .GetName (),
280
+ "namespace" : p .GetNamespace (),
281
+ })
282
+ Expect (found ).To (BeFalse ())
283
+ _ , found = FindMetricWithLabelValues ("karpenter_pods_provisioning_unstarted_time_seconds" , map [string ]string {
284
+ "name" : p .GetName (),
285
+ "namespace" : p .GetNamespace (),
286
+ })
287
+ Expect (found ).To (BeFalse ())
288
+
289
+ _ , found = FindMetricWithLabelValues ("karpenter_pods_startup_duration_seconds" , nil )
290
+ Expect (found ).To (BeTrue ())
291
+ _ , found = FindMetricWithLabelValues ("karpenter_pods_provisioning_startup_duration_seconds" , nil )
292
+ Expect (found ).To (BeTrue ())
293
+ })
294
+ It ("should update the pod startup and unstarted time metrics when the pod has failed" , func () {
295
+ p := test .Pod ()
296
+ p .Status .Phase = corev1 .PodPending
297
+
298
+ fakeClock .Step (1 * time .Hour )
299
+ cluster .MarkPodSchedulingDecisions (ctx , map [* corev1.Pod ]error {}, map [string ][]* corev1.Pod {"n1" : {p }}, map [string ][]* corev1.Pod {"nc1" : {p }})
300
+ ExpectApplied (ctx , env .Client , p )
301
+ ExpectReconcileSucceeded (ctx , podController , client .ObjectKeyFromObject (p )) //This will add pod to pending pods and unscheduled pods set
302
+ _ , found := FindMetricWithLabelValues ("karpenter_pods_unstarted_time_seconds" , map [string ]string {
303
+ "name" : p .GetName (),
304
+ "namespace" : p .GetNamespace (),
305
+ })
306
+ Expect (found ).To (BeTrue ())
307
+ _ , found = FindMetricWithLabelValues ("karpenter_pods_provisioning_unstarted_time_seconds" , map [string ]string {
308
+ "name" : p .GetName (),
309
+ "namespace" : p .GetNamespace (),
310
+ })
311
+ Expect (found ).To (BeTrue ())
312
+
313
+ // Pod has now failed and readiness condition is set to false
314
+ p .Status .Phase = corev1 .PodFailed
315
+ p .Status .Conditions = []corev1.PodCondition {
316
+ {Type : corev1 .PodReady , Status : corev1 .ConditionFalse , LastTransitionTime : metav1 .Now ()},
317
+ {Type : corev1 .PodScheduled , Status : corev1 .ConditionTrue , LastTransitionTime : metav1 .Now ()},
318
+ }
319
+ ExpectApplied (ctx , env .Client , p )
320
+ ExpectReconcileSucceeded (ctx , podController , client .ObjectKeyFromObject (p )) //This will check if the pod was scheduled and completed
321
+ _ , found = FindMetricWithLabelValues ("karpenter_pods_unstarted_time_seconds" , map [string ]string {
322
+ "name" : p .GetName (),
323
+ "namespace" : p .GetNamespace (),
324
+ })
325
+ Expect (found ).To (BeFalse ())
326
+ _ , found = FindMetricWithLabelValues ("karpenter_pods_provisioning_unstarted_time_seconds" , map [string ]string {
327
+ "name" : p .GetName (),
328
+ "namespace" : p .GetNamespace (),
329
+ })
330
+ Expect (found ).To (BeFalse ())
331
+
332
+ _ , found = FindMetricWithLabelValues ("karpenter_pods_startup_duration_seconds" , nil )
333
+ Expect (found ).To (BeTrue ())
334
+ _ , found = FindMetricWithLabelValues ("karpenter_pods_provisioning_startup_duration_seconds" , nil )
335
+ Expect (found ).To (BeTrue ())
336
+ })
251
337
It ("should create and delete provisioning undecided metrics based on scheduling simulatinos" , func () {
252
338
p := test .Pod ()
253
339
p .Status .Phase = corev1 .PodPending
0 commit comments