This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: not using the K8s options in every case. (#125)
- Loading branch information
Showing
5 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
*.user | ||
*.userosscache | ||
*.sln.docstates | ||
.vs/ | ||
|
||
# Ci things | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Text.Json; | ||
using k8s; | ||
|
||
#nullable enable | ||
|
||
namespace DotnetKubernetesClient | ||
{ | ||
internal static class KubernetesJsonOptions | ||
{ | ||
private static readonly Lazy<JsonSerializerOptions?> Lazy = new(GetJsonSerializerOptions); | ||
|
||
public static JsonSerializerOptions? DefaultOptions => Lazy.Value; | ||
|
||
private static JsonSerializerOptions? GetJsonSerializerOptions() | ||
{ | ||
try | ||
{ | ||
// Get the default (and private) KubernetesJson options. | ||
var fieldInfo = typeof(KubernetesJson).GetField("JsonSerializerOptions", BindingFlags.Static | BindingFlags.NonPublic); | ||
if (fieldInfo != null | ||
&& fieldInfo.GetValue(null) is JsonSerializerOptions options) | ||
{ | ||
return options; | ||
} | ||
} | ||
catch | ||
{ | ||
// Ignored | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/DotnetKubernetesClient.Test/KubernetesJsonOptions.Test.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace DotnetKubernetesClient.Test | ||
{ | ||
public class KubernetesJsonOptionsTest | ||
{ | ||
[Fact] | ||
public void DefaultOptions_should_not_return_null() | ||
{ | ||
var result = KubernetesJsonOptions.DefaultOptions; | ||
|
||
result.Should().NotBe(null); | ||
} | ||
} | ||
} |