* migrate to record * chore: update project files and clean up unused references * refactor: convert classes to records and simplify constructors for IntOrString, ResourceQuantity, and V1Patch * fix: define IsExternalInit to resolve CS0518 error in IntOrString * refactor: change IntOrString and ResourceQuantity from records to structs, update implicit conversions, and simplify null checks * refactor: add JsonPropertyName attribute to Value property in IntOrString struct * refactor: simplify V1Patch constructor and improve argument validation * refactor: remove unnecessary CultureInfo parameter in ToInt method * Update src/KubernetesClient/Models/ResourceQuantity.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/KubernetesClient/Models/IntOrString.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Revert "Update src/KubernetesClient/Models/ResourceQuantity.cs" This reverts commit 62b20a691554659e28d419067220dc1a0620133b. * refactor: remove commented-out formatting check and simplify build command * refactor: remove IValidate.cs from project references in Aot and Classic --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
64 lines
1.6 KiB
C#
64 lines
1.6 KiB
C#
using k8s;
|
|
using k8s.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
|
|
var config = KubernetesClientConfiguration.BuildDefaultConfig();
|
|
var client = new Kubernetes(config);
|
|
|
|
|
|
var pod = new V1Pod
|
|
{
|
|
Metadata = new V1ObjectMeta { Name = "nginx-pod" },
|
|
Spec = new V1PodSpec
|
|
{
|
|
Containers =
|
|
[
|
|
new V1Container
|
|
{
|
|
Name = "nginx",
|
|
Image = "nginx",
|
|
Resources = new V1ResourceRequirements
|
|
{
|
|
Requests = new Dictionary<string, ResourceQuantity>()
|
|
{
|
|
["cpu"] = "100m",
|
|
},
|
|
},
|
|
},
|
|
],
|
|
},
|
|
};
|
|
{
|
|
var created = await client.CoreV1.CreateNamespacedPodAsync(pod, "default").ConfigureAwait(false);
|
|
Console.WriteLine($"Created pod: {created.Metadata.Name}");
|
|
}
|
|
|
|
{
|
|
var patchStr = @"
|
|
{
|
|
""spec"": {
|
|
""containers"": [
|
|
{
|
|
""name"": ""nginx"",
|
|
""resources"": {
|
|
""requests"": {
|
|
""cpu"": ""200m""
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}";
|
|
|
|
var patch = await client.CoreV1.PatchNamespacedPodResizeAsync(new V1Patch(patchStr, V1Patch.PatchType.MergePatch), "nginx-pod", "default").ConfigureAwait(false);
|
|
|
|
if (patch?.Spec?.Containers?.Count > 0 &&
|
|
patch.Spec.Containers[0].Resources?.Requests != null &&
|
|
patch.Spec.Containers[0].Resources.Requests.TryGetValue("cpu", out var cpuQty))
|
|
{
|
|
Console.WriteLine($"CPU request: {cpuQty}");
|
|
}
|
|
}
|