tintoy / dotnet-kube-client

A Kubernetes API client for .NET Standard / .NET Core
MIT License
192 stars 33 forks source link

Question: Using DeploymentV1.Update() #50

Closed brobichaud closed 5 years ago

brobichaud commented 5 years ago

Are there any sample snippets on how to update a deployment? Specifically I'm struggling to figure out how to start a pod scale-out by increasing the Replicas count. The syntax of the api is tripping me up quite thoroughly...

tintoy commented 5 years ago

Hi. It's unfortunate, but the K8s API makes it painful to do updates that aren't JSON-PATCH-based (which is why the update API looks like it does).

I don't think we have a specific example, but I'll see if I can write one up.

brobichaud commented 5 years ago

That would be great @tintoy. Below is some pseudo code of where I am headed currently. I have no idea what to do in the Action delegate...

var depClient = GetDeploymentClient();
var dep = await depClient.Get("my-deployment-name");
var patchDoc = new JsonPatchDocument<DeploymentV1>();
patchDoc.Replace(e => e.Spec.Replicas, 2);
Action<JsonPatchDocument<DeploymentV1>> act = (JsonPatchDocument<DeploymentV1> p) => Console.WriteLine(p.Operations.Count);
await depClient.Update(dep.Metadata.Name, act);
tintoy commented 5 years ago

Ah, I think I see the source of the confusion :)

The idea is that you call Update with a callback delegate, and it passes your delegate a patch document in the delegate (makes it easier to use inline):

await depClient.Update("my-deployment-name", patch =>
{
    patch.Replace(deployment => deployment.Spec.Replicas, 2);
});
brobichaud commented 5 years ago

Perfect, exactly what I needed. Thanks!

tintoy commented 5 years ago

Hi - I'm going to close this issue, but feel free to reopen it if you need to :)