committed by
Brendan Burns
parent
3f69820739
commit
d01446718d
44
examples/patch/Program.cs
Normal file
44
examples/patch/Program.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using k8s;
|
||||
using k8s.Models;
|
||||
using Microsoft.AspNetCore.JsonPatch;
|
||||
|
||||
namespace patch
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
|
||||
IKubernetes client = new Kubernetes(config);
|
||||
Console.WriteLine("Starting Request!");
|
||||
|
||||
var pod = client.ListNamespacedPod("default").Items.First();
|
||||
|
||||
var name = pod.Metadata.Name;
|
||||
PrintLabels(pod);
|
||||
|
||||
var newlables = new Dictionary<string, string>(pod.Metadata.Labels)
|
||||
{
|
||||
["test"] = "test"
|
||||
};
|
||||
var patch = new JsonPatchDocument<V1Pod>();
|
||||
patch.Replace(e => e.Metadata.Labels, newlables);
|
||||
client.PatchNamespacedPod(new V1Patch(patch), name, "default");
|
||||
|
||||
PrintLabels(client.ReadNamespacedPod(name, "default"));
|
||||
}
|
||||
|
||||
private static void PrintLabels(V1Pod pod)
|
||||
{
|
||||
Console.WriteLine($"Lables: for {pod.Metadata.Name}");
|
||||
foreach (var (k, v) in pod.Metadata.Labels)
|
||||
{
|
||||
Console.WriteLine($"{k} : {v}");
|
||||
}
|
||||
Console.WriteLine("=-=-=-=-=-=-=-=-=-=-=");
|
||||
}
|
||||
}
|
||||
}
|
||||
12
examples/patch/patch.csproj
Normal file
12
examples/patch/patch.csproj
Normal file
@@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\KubernetesClient\KubernetesClient.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user