Files
csharp/examples/httpClientFactory/PodListHostedService.cs
Boshi Lian cfc4306528 stylecop fix followup, enforce SA1503 (#432)
* enforce SA1503

* fix spacing

* fix SA1413

* fix spacing

* fix SA1013
2020-04-23 11:40:06 -07:00

45 lines
1.5 KiB
C#

using k8s;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace httpClientFactory
{
// Learn more about IHostedServices at https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-2.2&tabs=visual-studio
internal class PodListHostedService : IHostedService
{
private readonly IKubernetes _kubernetesClient;
private readonly ILogger<PodListHostedService> _logger;
public PodListHostedService(IKubernetes kubernetesClient, ILogger<PodListHostedService> logger)
{
_kubernetesClient = kubernetesClient ?? throw new ArgumentNullException(nameof(kubernetesClient));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public async Task StartAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Starting Request!");
var list = await _kubernetesClient.ListNamespacedPodAsync("default", cancellationToken: cancellationToken);
foreach (var item in list.Items)
{
_logger.LogInformation(item.Metadata.Name);
}
if (list.Items.Count == 0)
{
_logger.LogInformation("Empty!");
}
}
public Task StopAsync(CancellationToken cancellationToken)
{
// Nothing to stop
return Task.CompletedTask;
}
}
}