Initial Backend
This commit is contained in:
parent
bcf92c21e6
commit
3f6ff87370
15 changed files with 782 additions and 0 deletions
61
backend/Repositories/KubernetesHandler.cs
Normal file
61
backend/Repositories/KubernetesHandler.cs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
using k8s;
|
||||
using ContainerDashboard.Models;
|
||||
using k8s.Models;
|
||||
|
||||
namespace ContainerDashboard.Repositories;
|
||||
|
||||
public class KubernetesHandler : IContainerHandler
|
||||
{
|
||||
private readonly KubernetesClientConfiguration _config;
|
||||
private readonly Kubernetes _client;
|
||||
|
||||
public KubernetesHandler()
|
||||
{
|
||||
try
|
||||
{
|
||||
var configPath = Environment.GetEnvironmentVariable("KUBECONFIG");
|
||||
_config = KubernetesClientConfiguration.BuildConfigFromConfigFile(Environment.GetEnvironmentVariable("KUBECONFIG"));
|
||||
}
|
||||
catch (ArgumentNullException)
|
||||
{
|
||||
_config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
|
||||
}
|
||||
|
||||
_client = new Kubernetes(_config);
|
||||
}
|
||||
|
||||
public Task<Container> GetContainer(string containerName, string? containerNamespace)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<Container[]> GetContainers()
|
||||
{
|
||||
var list = await _client.AppsV1.ListDeploymentForAllNamespacesAsync();
|
||||
var containers = new List<Container>();
|
||||
|
||||
foreach (var item in list.Items)
|
||||
{
|
||||
var c = new Container
|
||||
{
|
||||
containerNamespace = item.Namespace(),
|
||||
Name = item.Name(),
|
||||
Running = item.Status.Replicas > 0
|
||||
};
|
||||
|
||||
containers.Add(c);
|
||||
}
|
||||
|
||||
return containers.ToArray();
|
||||
}
|
||||
|
||||
public Task StartContainer()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task StopContainer()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue