Skip to content

Commit

Permalink
k8s provider diagnostics (#1820)
Browse files Browse the repository at this point in the history
* k8s provider diagnostics

* add errorhandling to k8s provider
  • Loading branch information
rogeralsing authored Oct 16, 2022
1 parent 8f6fd89 commit 4a9e16b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Proto.Cluster.Kubernetes/KubernetesProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using k8s;
using k8s.Models;
using Microsoft.Extensions.Logging;
using Proto.Diagnostics;
using Proto.Utils;
using static Proto.Cluster.Kubernetes.Messages;
using static Proto.Cluster.Kubernetes.ProtoLabels;
Expand All @@ -38,6 +39,29 @@ public class KubernetesProvider : IClusterProvider
private string _podName;
private int _port;

public async Task<DiagnosticsEntry[]> GetDiagnostics()
{
try
{
var selector = $"{LabelCluster}={_clusterName}";
using var client = _config.ClientFactory();
var res = await client.ListNamespacedPodWithHttpMessagesAsync(
KubernetesExtensions.GetKubeNamespace(),
labelSelector: selector,
watch: false,
timeoutSeconds: _config.WatchTimeoutSeconds
);

var pods = new DiagnosticsEntry("KubernetesProvider", "Pods", res.Body);

return new[] { pods };
}
catch (Exception x)
{
return new[] { new DiagnosticsEntry("KubernetesProvider", "Exception", x.ToString() ) };
}
}

public KubernetesProvider() : this(new KubernetesProviderConfig())
{
}
Expand Down

0 comments on commit 4a9e16b

Please sign in to comment.