Skip to content

Commit d014467

Browse files
tg123brendandburns
authored andcommitted
add patch example (#189)
* add patch example * fix typo
1 parent 3f69820 commit d014467

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

examples/patch/Program.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using k8s;
5+
using k8s.Models;
6+
using Microsoft.AspNetCore.JsonPatch;
7+
8+
namespace patch
9+
{
10+
internal class Program
11+
{
12+
private static void Main(string[] args)
13+
{
14+
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
15+
IKubernetes client = new Kubernetes(config);
16+
Console.WriteLine("Starting Request!");
17+
18+
var pod = client.ListNamespacedPod("default").Items.First();
19+
20+
var name = pod.Metadata.Name;
21+
PrintLabels(pod);
22+
23+
var newlables = new Dictionary<string, string>(pod.Metadata.Labels)
24+
{
25+
["test"] = "test"
26+
};
27+
var patch = new JsonPatchDocument<V1Pod>();
28+
patch.Replace(e => e.Metadata.Labels, newlables);
29+
client.PatchNamespacedPod(new V1Patch(patch), name, "default");
30+
31+
PrintLabels(client.ReadNamespacedPod(name, "default"));
32+
}
33+
34+
private static void PrintLabels(V1Pod pod)
35+
{
36+
Console.WriteLine($"Lables: for {pod.Metadata.Name}");
37+
foreach (var (k, v) in pod.Metadata.Labels)
38+
{
39+
Console.WriteLine($"{k} : {v}");
40+
}
41+
Console.WriteLine("=-=-=-=-=-=-=-=-=-=-=");
42+
}
43+
}
44+
}

examples/patch/patch.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\..\src\KubernetesClient\KubernetesClient.csproj" />
10+
</ItemGroup>
11+
12+
</Project>

kubernetes-client.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "gen", "gen", "{879F8787-C3B
3131
EndProject
3232
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KubernetesWatchGenerator", "gen\KubernetesWatchGenerator\KubernetesWatchGenerator.csproj", "{542DC30E-FDF7-4A35-B026-6C21F435E8B1}"
3333
EndProject
34+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "patch", "examples\patch\patch.csproj", "{04DE2C84-117D-4E21-8B45-B7AE627697BD}"
35+
EndProject
3436
Global
3537
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3638
Debug|Any CPU = Debug|Any CPU
@@ -161,6 +163,18 @@ Global
161163
{542DC30E-FDF7-4A35-B026-6C21F435E8B1}.Release|x64.Build.0 = Release|Any CPU
162164
{542DC30E-FDF7-4A35-B026-6C21F435E8B1}.Release|x86.ActiveCfg = Release|Any CPU
163165
{542DC30E-FDF7-4A35-B026-6C21F435E8B1}.Release|x86.Build.0 = Release|Any CPU
166+
{04DE2C84-117D-4E21-8B45-B7AE627697BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
167+
{04DE2C84-117D-4E21-8B45-B7AE627697BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
168+
{04DE2C84-117D-4E21-8B45-B7AE627697BD}.Debug|x64.ActiveCfg = Debug|Any CPU
169+
{04DE2C84-117D-4E21-8B45-B7AE627697BD}.Debug|x64.Build.0 = Debug|Any CPU
170+
{04DE2C84-117D-4E21-8B45-B7AE627697BD}.Debug|x86.ActiveCfg = Debug|Any CPU
171+
{04DE2C84-117D-4E21-8B45-B7AE627697BD}.Debug|x86.Build.0 = Debug|Any CPU
172+
{04DE2C84-117D-4E21-8B45-B7AE627697BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
173+
{04DE2C84-117D-4E21-8B45-B7AE627697BD}.Release|Any CPU.Build.0 = Release|Any CPU
174+
{04DE2C84-117D-4E21-8B45-B7AE627697BD}.Release|x64.ActiveCfg = Release|Any CPU
175+
{04DE2C84-117D-4E21-8B45-B7AE627697BD}.Release|x64.Build.0 = Release|Any CPU
176+
{04DE2C84-117D-4E21-8B45-B7AE627697BD}.Release|x86.ActiveCfg = Release|Any CPU
177+
{04DE2C84-117D-4E21-8B45-B7AE627697BD}.Release|x86.Build.0 = Release|Any CPU
164178
EndGlobalSection
165179
GlobalSection(SolutionProperties) = preSolution
166180
HideSolutionNode = FALSE
@@ -176,6 +190,7 @@ Global
176190
{35DD7248-F9EC-4272-A32C-B0C59E5A6FA7} = {3D1864AA-1FFC-4512-BB13-46055E410F73}
177191
{806AD0E5-833F-42FB-A870-4BCEE7F4B17F} = {8AF4A5C2-F0CE-47D5-A4C5-FE4AB83CA509}
178192
{542DC30E-FDF7-4A35-B026-6C21F435E8B1} = {879F8787-C3BB-43F3-A92D-6D4C7D3A5285}
193+
{04DE2C84-117D-4E21-8B45-B7AE627697BD} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
179194
EndGlobalSection
180195
GlobalSection(ExtensibilityGlobals) = postSolution
181196
SolutionGuid = {049A763A-C891-4E8D-80CF-89DD3E22ADC7}

0 commit comments

Comments
 (0)