Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions examples/resize/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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"] = new ResourceQuantity("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}");
}
}
5 changes: 5 additions & 0 deletions examples/resize/resize.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>
</Project>
Loading