-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Special case serialization of V1Patch * Add AOT JSON Patch Example
- Loading branch information
1 parent
541abb0
commit c3b3a08
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using k8s; | ||
Check warning on line 1 in examples/patch-aot/Program.cs GitHub Actions / draft
Check warning on line 1 in examples/patch-aot/Program.cs GitHub Actions / draft
|
||
using k8s.Models; | ||
Check warning on line 2 in examples/patch-aot/Program.cs GitHub Actions / draft
|
||
|
||
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(); | ||
IKubernetes client = new Kubernetes(config); | ||
Console.WriteLine("Starting Request!"); | ||
|
||
var pod = client.CoreV1.ListNamespacedPod("default").Items.First(); | ||
var name = pod.Metadata.Name; | ||
PrintLabels(pod); | ||
|
||
var patchStr = @" | ||
{ | ||
""metadata"": { | ||
""labels"": { | ||
""test"": ""test"" | ||
} | ||
} | ||
}"; | ||
|
||
client.CoreV1.PatchNamespacedPod(new V1Patch(patchStr, V1Patch.PatchType.MergePatch), name, "default"); | ||
PrintLabels(client.CoreV1.ReadNamespacedPod(name, "default")); | ||
|
||
static void PrintLabels(V1Pod pod) | ||
{ | ||
Console.WriteLine($"Labels: for {pod.Metadata.Name}"); | ||
foreach (var (k, v) in pod.Metadata.Labels) | ||
{ | ||
Console.WriteLine($"{k} : {v}"); | ||
} | ||
Check warning on line 30 in examples/patch-aot/Program.cs GitHub Actions / draft
|
||
Console.WriteLine("=-=-=-=-=-=-=-=-=-=-="); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<PublishAot>true</PublishAot> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\KubernetesClient.Aot\KubernetesClient.Aot.csproj"/> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters