Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-chervet committed Nov 17, 2024
1 parent d79c212 commit f4990d0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion demo/deployment-slimfaas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions src/SlimFaas/Kubernetes/KubernetesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ private static IEnumerable<PodInformation> 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;
Expand All @@ -387,6 +389,9 @@ private static IEnumerable<PodInformation> 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
Expand Down Expand Up @@ -427,4 +432,33 @@ private static IEnumerable<PodInformation> 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;
}

}

0 comments on commit f4990d0

Please sign in to comment.