From f4990d0bee064be32ad9a86120caffe5382cca97 Mon Sep 17 00:00:00 2001 From: Guillaume Chervet Date: Sun, 17 Nov 2024 16:16:41 +0100 Subject: [PATCH] test --- demo/deployment-slimfaas.yml | 2 +- src/SlimFaas/Kubernetes/KubernetesService.cs | 34 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/demo/deployment-slimfaas.yml b/demo/deployment-slimfaas.yml index a8e1b4de..a4c140c4 100644 --- a/demo/deployment-slimfaas.yml +++ b/demo/deployment-slimfaas.yml @@ -84,7 +84,7 @@ spec: serviceAccountName: slimfaas containers: - name: slimfaas - image: axaguildev/slimfaas:pr-77-762 + image: axaguildev/slimfaas:pr-77-763 livenessProbe: httpGet: path: /health diff --git a/src/SlimFaas/Kubernetes/KubernetesService.cs b/src/SlimFaas/Kubernetes/KubernetesService.cs index 14f01ac1..d4d1f563 100644 --- a/src/SlimFaas/Kubernetes/KubernetesService.cs +++ b/src/SlimFaas/Kubernetes/KubernetesService.cs @@ -379,6 +379,8 @@ private static IEnumerable MapPodInformations(V1PodList v1PodLis continue; } + // I want to get the state when the pod is ready to receive http request + V1ContainerStatus? containerStatus = item.Status.ContainerStatuses.FirstOrDefault(); bool ready = containerStatus?.Ready ?? false; bool started = containerStatus?.Started ?? false; @@ -387,6 +389,9 @@ private static IEnumerable MapPodInformations(V1PodList v1PodLis bool? podReady = item.Status.Conditions.FirstOrDefault(c => c.Type == "Ready")?.Status == "True"; // I want the state when the pod is ready to receive http request bool podReadyHttp = item.Status.Conditions.FirstOrDefault(c => c.Type == "PodScheduled")?.Status == "True"; + + // I want the state when the container is ready and 1 second after the container is ready + bool containerReady = item.Status.Conditions.FirstOrDefault(c => c.Type == "ContainersReady")?.Status == "True"; // display pod name @@ -427,4 +432,33 @@ private static IEnumerable MapPodInformations(V1PodList v1PodLis } } + private static bool PodReady(V1Pod pod) + { + DateTime readyTime = DateTime.MinValue; + + foreach (var condition in pod.Status.Conditions) + { + if (condition.Type == "Ready" && condition.Status == "True") + { + readyTime = condition.LastTransitionTime ?? DateTime.UtcNow; // Convertir le timestamp en UTC + break; + } + } + + if (readyTime != DateTime.MinValue) + { + TimeSpan timeSinceReady = DateTime.UtcNow - readyTime; // Utiliser DateTime.UtcNow pour obtenir le temps actuel en UTC + + if (timeSinceReady.TotalSeconds > 1) + { + // Attendre que le temps écoulé depuis l'état "ready" soit supérieur à 1 seconde avant d'exécuter une action + // Par exemple, effectuer une requête HTTP vers le pod + return true; + } + + } + + return false; + } + }