* generated based on 1.33 * Update version to 17.0 in version.json * Remove extra API endpoint from swagger.json * Remove ModelConverter and related AutoMapper components * Update package versions * Refactor code to use ConfigureAwait(false) for asynchronous calls and update target framework to net9.0 * Remove ConfigureAwait(false) from OidcAuthTests for consistency in async calls * Update SDK version in README to reflect support for net8.0 and net9.0 * Update dotnet SDK version to 9.0.x in build workflow * Revert Fractions package version to 7.3.0 in Directory.Packages.props * Update target framework to netstandard2.1 for improved compatibility * Update package references for Microsoft.CodeAnalysis in Directory.Packages.props and LibKubernetesGenerator.target * Refactor Worker class constructor documentation and standardize Dictionary type declaration in Program.cs
42 lines
1.5 KiB
C#
42 lines
1.5 KiB
C#
using k8s;
|
|
|
|
namespace workerServiceDependencyInjection
|
|
{
|
|
public class Worker : BackgroundService
|
|
{
|
|
private readonly ILogger<Worker> logger;
|
|
private readonly IKubernetes kubernetesClient;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="Worker"/> class.
|
|
/// Inject in the constructor the IKubernetes interface.
|
|
/// </summary>
|
|
/// <param name="logger">The logger instance used for logging information.</param>
|
|
/// <param name="kubernetesClient">The Kubernetes client used to interact with the Kubernetes API.</param>
|
|
public Worker(ILogger<Worker> logger, IKubernetes kubernetesClient)
|
|
{
|
|
this.logger = logger;
|
|
this.kubernetesClient = kubernetesClient;
|
|
}
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
while (!stoppingToken.IsCancellationRequested)
|
|
{
|
|
logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
|
|
|
// Read the list of pods contained in default namespace
|
|
var podList = kubernetesClient.CoreV1.ListNamespacedPod("default");
|
|
|
|
// Print pods names
|
|
foreach (var pod in podList.Items)
|
|
{
|
|
Console.WriteLine(pod.Metadata.Name);
|
|
}
|
|
|
|
await Task.Delay(1000, stoppingToken).ConfigureAwait(false);
|
|
}
|
|
}
|
|
}
|
|
}
|