Code Monkey home page Code Monkey logo

Comments (7)

tg123 avatar tg123 commented on July 26, 2024 1

seems PatchNamespacedDeployment is not working as except, I will have a look at that api.

from csharp.

tg123 avatar tg123 commented on July 26, 2024 1

using Microsoft.AspNetCore.JsonPatch;

var newlables = new Dictionary<string, string>(p.Metadata.Labels)
{
    ["test"] = "test"
};
var patch = new JsonPatchDocument<V1Pod>();
patch.Replace(e => e.Metadata.Labels, newlables);
client.PatchNamespacedPod(new V1Patch(patch), n, "default");

from csharp.

brendandburns avatar brendandburns commented on July 26, 2024

@tg123 I think this is the same underlying issue as this:

kubernetes-client/java#127

from csharp.

tg123 avatar tg123 commented on July 26, 2024

@RouR sorry for the late reply, just another busy week

Your approach is right and there is a tricky thing in generated client:
"will serialize all anonymous into {}"
due to default SerializationSettings

SerializationSettings = new JsonSerializerSettings
            {
               .........
                ContractResolver = new ReadOnlyJsonContractResolver(),
               .......
            };

workarounds might be:

here is my tested using JsonPatch which is trying to add another label to pod.

                var newlables = new Dictionary<string, string>(p.Metadata.Labels)
                {
                    ["test"] = "test"
                };
                var patch = new JsonPatchDocument<V1Pod>();
                patch.Replace(e => e.Metadata.Labels, newlables);
                client.PatchNamespacedPod(patch, n, "default");

@brendanburns
We need to support all 3 kinds of PatchType in the client

  • JSONPatchType
  • MergePatchType
  • StrategicMergePatchType

howerver the generated client, like Java client, treat all body object as JSONPatchType.
I will try to find a better way to support Patch calls

from csharp.

RouR avatar RouR commented on July 26, 2024

Hmm,
As I see Headers is forced to "application/json-patch+json; charset=utf-8", but it`s work (I check in debugger headers)

_httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json; charset=utf-8");

I use Microsoft.AspNetCore.JsonPatch instead of https://github.com/aaxelm/JsonPatch.NetStandard
with this code:

var newlables = new Dictionary<string, string>(item.Spec.Template.Metadata.Labels)
{
	[ciLabel.Key] = "newData" 
};
var patch = new JsonPatchDocument<Appsv1beta1Deployment>();
patch.Replace(e => e.Spec.Template.Metadata.Labels, newlables);
client.PatchNamespacedDeployment(patch, item.Metadata.Name, k8Namespace);

The type Appsv1beta1Deployment is not defined in NuGet-package KubernetesClient 0.3.0-beta
Please, update NuGet
Thank`s for the help!

from csharp.

RouR avatar RouR commented on July 26, 2024

Hi!
I took the latest version today.
I see breaking changes - PatchNamespacedDeployment require V1Patch object.

Can you explain how to use it? Or provide some example - how to change label in deployment specification?

from csharp.

RouR avatar RouR commented on July 26, 2024

Thanks!

from csharp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.