-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(slimfaas): call only at least when one pod is read
- Loading branch information
1 parent
cca0a87
commit d99bb7d
Showing
7 changed files
with
195 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using k8s; | ||
using k8s.Models; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
|
||
namespace SlimFaas.Tests; | ||
|
||
public class TestShould | ||
{ | ||
[Fact] | ||
public async Task SyncLastTicksBetweenDatabaseAndMemory() | ||
{ | ||
var inMemorySettings = new Dictionary<string, string> { | ||
{"UseKubeConfig", "true"}, | ||
}; | ||
|
||
IConfiguration configuration = new ConfigurationBuilder() | ||
.AddInMemoryCollection(inMemorySettings) | ||
.Build(); | ||
//var kubernetesService = new KubernetesService(configuration); | ||
//var functions = await kubernetesService.ListFunctionsAsync("lightfaas-demo"); | ||
|
||
// Load from the default kubeconfig on the machine. | ||
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(); | ||
using var client = new Kubernetes(config); | ||
var namespaces = client.CoreV1.ListNamespace(); | ||
foreach (var ns in namespaces.Items) { | ||
Console.WriteLine(ns.Metadata.Name); | ||
|
||
|
||
var list = client.CoreV1.ListNamespacedPod(ns.Metadata.Name); | ||
MapPodInformations(list); | ||
} | ||
} | ||
|
||
private static IList<PodInformation> MapPodInformations(V1PodList list) | ||
{ | ||
IList<PodInformation> podInformations = new List<PodInformation>(); | ||
foreach (var item in list.Items) | ||
{ | ||
var containerStatus = item.Status.ContainerStatuses.FirstOrDefault(); | ||
if (containerStatus == null) | ||
{ | ||
continue; | ||
} | ||
|
||
var ready = containerStatus.Ready; | ||
var started = containerStatus.Started; | ||
var podIP = item.Status.PodIP; | ||
var podName = item.Metadata.Name; | ||
var deploymentName = string.Empty; | ||
if (item.Metadata.Labels.TryGetValue("app", out var label)) | ||
{ | ||
deploymentName = label; | ||
} | ||
|
||
var podInformation = new PodInformation() | ||
{ | ||
Started = started, | ||
Ready = ready, | ||
Ip = podIP, | ||
Name = podName, | ||
DeploymentName = deploymentName | ||
}; | ||
|
||
podInformations.Add(podInformation); | ||
} | ||
|
||
return podInformations; | ||
} | ||
} |