Skip to content

feat: allow overriding YamlDotNet settings #1335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

IvanJosipovic
Copy link
Contributor

This PR allows overriding the default YamlDotNet settings by adding a new KubernetesYamlConfiguration class.

I'm not able to test this as its static.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 9, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: IvanJosipovic
Once this PR has been reviewed and has the lgtm label, please assign tg123 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Member

@tg123 tg123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you want event?

@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@60f94aa). Click here to learn what that means.
The diff coverage is n/a.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff            @@
##             master    #1335   +/-   ##
=========================================
  Coverage          ?   69.74%           
=========================================
  Files             ?       96           
  Lines             ?     2720           
  Branches          ?        0           
=========================================
  Hits              ?     1897           
  Misses            ?      823           
  Partials          ?        0           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 28, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 28, 2023
@IvanJosipovic
Copy link
Contributor Author

I converted the logic to use an event. It can be tested like this:

using k8s;
using System.Text.Json.Nodes;
using YamlDotNet.Serialization;
using YamlDotNet.System.Text.Json;

KubernetesYamlConfiguration.SeralizerEvent += KubernetesYamlConfiguration_SeralizerEvent;

void KubernetesYamlConfiguration_SeralizerEvent(object? sender, SerializerBuilder e)
{
    e.WithTypeConverter(new SystemTextJsonYamlTypeConverter(true))
     .WithTypeInspector(x => new SystemTextJsonTypeInspector(x));
}

KubernetesYamlConfiguration.DeseralizerEvent += KubernetesYamlConfiguration_DeseralizerEvent;

void KubernetesYamlConfiguration_DeseralizerEvent(object? sender, DeserializerBuilder e)
{
    e.WithTypeConverter(new SystemTextJsonYamlTypeConverter())
    .WithTypeInspector(x => new SystemTextJsonTypeInspector(x));
}

var obj = KubernetesYaml.LoadFromString<JsonObject>(File.ReadAllText("helm-release.yaml"));

var yaml = KubernetesYaml.Serialize(obj);

Console.ReadLine();

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 13, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 28, 2023
@tg123
Copy link
Member

tg123 commented Jan 14, 2024

close as of #1498

@tg123 tg123 closed this Jan 14, 2024
@IvanJosipovic
Copy link
Contributor Author

@tg123, can we please re-open this PR?
This PR is not related to AOT. It allows customizing the YAML serializer settings, this library has a similar capability for JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants