Clean up warnings in examples (#1628)

* Refactor examples to streamline code structure and improve readability

* Update LangVersion to 13.0 for improved compatibility
This commit is contained in:
Boshi Lian
2025-04-29 16:55:55 -07:00
committed by GitHub
parent 001189de77
commit ae79be6665
17 changed files with 335 additions and 446 deletions

View File

@@ -3,35 +3,26 @@ using k8s.Models;
using System;
using System.Threading.Tasks;
namespace exec
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
IKubernetes client = new Kubernetes(config);
Console.WriteLine("Starting Request!");
var list = client.CoreV1.ListNamespacedPod("default");
var pod = list.Items[0];
await ExecInPod(client, pod).ConfigureAwait(false);
async Task ExecInPod(IKubernetes client, V1Pod pod)
{
internal class Exec
{
private static async Task Main(string[] args)
{
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
IKubernetes client = new Kubernetes(config);
Console.WriteLine("Starting Request!");
var webSocket =
await client.WebSocketNamespacedPodExecAsync(pod.Metadata.Name, "default", "ls",
pod.Spec.Containers[0].Name).ConfigureAwait(false);
var list = client.CoreV1.ListNamespacedPod("default");
var pod = list.Items[0];
await ExecInPod(client, pod).ConfigureAwait(false);
}
var demux = new StreamDemuxer(webSocket);
demux.Start();
private static async Task ExecInPod(IKubernetes client, V1Pod pod)
{
var webSocket =
await client.WebSocketNamespacedPodExecAsync(pod.Metadata.Name, "default", "ls",
pod.Spec.Containers[0].Name).ConfigureAwait(false);
var demux = new StreamDemuxer(webSocket);
demux.Start();
var buff = new byte[4096];
var stream = demux.GetStream(1, 1);
var read = stream.Read(buff, 0, 4096);
var str = System.Text.Encoding.Default.GetString(buff);
Console.WriteLine(str);
}
}
var buff = new byte[4096];
var stream = demux.GetStream(1, 1);
var read = stream.Read(buff, 0, 4096);
var str = System.Text.Encoding.Default.GetString(buff);
Console.WriteLine(str);
}