|
44 | 44 | import io.fabric8.kubernetes.api.model.ContainerPortBuilder; |
45 | 45 | import io.fabric8.kubernetes.api.model.EnvVar; |
46 | 46 | import io.fabric8.kubernetes.api.model.EnvVarSourceBuilder; |
| 47 | +import io.fabric8.kubernetes.api.model.Event; |
47 | 48 | import io.fabric8.kubernetes.api.model.GenericKubernetesResource; |
48 | 49 | import io.fabric8.kubernetes.api.model.GenericKubernetesResourceList; |
49 | 50 | import io.fabric8.kubernetes.api.model.HasMetadata; |
50 | 51 | import io.fabric8.kubernetes.api.model.LocalObjectReference; |
51 | 52 | import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; |
| 53 | +import io.fabric8.kubernetes.api.model.ObjectReferenceBuilder; |
52 | 54 | import io.fabric8.kubernetes.api.model.Pod; |
53 | 55 | import io.fabric8.kubernetes.api.model.PodBuilder; |
54 | 56 | import io.fabric8.kubernetes.api.model.ServiceBuilder; |
|
87 | 89 | import java.nio.file.Files; |
88 | 90 | import java.nio.file.Path; |
89 | 91 | import java.nio.file.Paths; |
| 92 | +import java.time.LocalDateTime; |
| 93 | +import java.time.OffsetDateTime; |
| 94 | +import java.time.ZoneId; |
90 | 95 | import java.util.ArrayList; |
91 | 96 | import java.util.Arrays; |
92 | 97 | import java.util.Collections; |
@@ -312,6 +317,39 @@ protected Container startContainer(ContainerSpec spec, Proxy proxy) throws Excep |
312 | 317 | proxyStatusService.containerStarted(proxy, container); |
313 | 318 | Pod pod = kubeClient.resource(startedPod).fromServer().get(); |
314 | 319 |
|
| 320 | + // TODO check k8s compatibility |
| 321 | + List<Event> events = kubeClient.v1().events().withInvolvedObject(new ObjectReferenceBuilder() |
| 322 | + .withKind("Pod") |
| 323 | + .withName(pod.getMetadata().getName()) |
| 324 | + .withNamespace(pod.getMetadata().getNamespace()) |
| 325 | + .build()).list().getItems(); |
| 326 | + |
| 327 | + LocalDateTime pullingTime = null; |
| 328 | + LocalDateTime pulledTime = null; |
| 329 | + LocalDateTime scheduledTime = null; |
| 330 | + |
| 331 | + for (Event event : events) { |
| 332 | + if (event.getCount() != null && event.getCount() > 1) { |
| 333 | + // ignore events which happened multiple time as we are unable to properly process them |
| 334 | + continue; |
| 335 | + } |
| 336 | + if (event.getReason().equalsIgnoreCase("Pulling")) { |
| 337 | + pullingTime = OffsetDateTime.parse(event.getLastTimestamp()).atZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime(); |
| 338 | + } else if (event.getReason().equalsIgnoreCase("Pulled")) { |
| 339 | + pulledTime = OffsetDateTime.parse(event.getLastTimestamp()).atZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime(); |
| 340 | + } else if (event.getReason().equalsIgnoreCase("Scheduled")) { |
| 341 | + scheduledTime = OffsetDateTime.parse(event.getEventTime().getTime()).atZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime(); |
| 342 | + } |
| 343 | + } |
| 344 | + |
| 345 | + if (pullingTime != null && pulledTime != null) { |
| 346 | + proxyStatusService.imagePulled(proxy, container, pullingTime, pulledTime); |
| 347 | + } |
| 348 | + |
| 349 | + if (scheduledTime != null) { |
| 350 | + proxyStatusService.containerScheduled(proxy, container, scheduledTime); |
| 351 | + } |
| 352 | + |
315 | 353 | Service service = null; |
316 | 354 | if (isUseInternalNetwork()) { |
317 | 355 | // If SP runs inside the cluster, it can access pods directly and doesn't need any port publishing service. |
|
0 commit comments