You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I have noticed a bug with KubernetesJson that if we create a CustomResourceDefinition that takes a ResourceQuantity schema where for example resource 'cpu' value is a number, deserialization fails. It only accepts strings for KubernetesJson deserializers.
Custom resource example that works and cpu properly deserializes into a ResourceQuantity object in c#:
System.Text.Json.JsonException: The JSON value could not be converted to k8s.Models.ResourceQuantity.
Path: $.object.spec.mycustomresource.spec.template.spec.containers[0].resources.limits.cpu | LineNumber: 0 | BytePositionInLine: 1633. ---> System.InvalidOperationException: Cannot get the value of a token type 'Number' as a string.
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_ExpectedString(JsonTokenType tokenType)
at System.Text.Json.Utf8JsonReader.GetString()
at k8s.Models.ResourceQuantityJsonConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
When using KubernetesYaml however, this works as expected and the values deserialize to the custom object containing a ResourceQuantity type as expected, regardless of whether the cpu value is a string or a number.
My assumption that the root issue here lies with KubernetesJson that does not handle ResourceQuantity object deserialization. KubernetesYaml handles it properly on the other hand.
Although the above is mainly a guess. Does any one know what the issue here might be exactly?
Kubernetes C# SDK Client Version
10.0.31
Server Kubernetes Version
1.24.16
Dotnet Runtime Version
net6
To Reproduce
create a json that can deserialize into a ResourceQuantity, for example:
stringjsonString=@"{""cpu"": ""1""}";// this will deserialize finevartest= KubernetesJson.Deserialize<Dictionary<string,ResourceQuantity>>(jsonString);
The following will fail since cpu is now a number:
stringjsonString=@"{""cpu"": 1}";// this will fail because cpu value is a numbervartest= KubernetesJson.Deserialize<Dictionary<string,ResourceQuantity>>(jsonString);
Should result in the following error
ystem.Text.Json.JsonException: The JSON value could not be converted to k8s.Models.ResourceQuantity. Path: $.cpu | LineNumber: 0 | BytePositionInLine: 9.
---> System.InvalidOperationException: Cannot get the value of a token type 'Number' as a string.
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_ExpectedString(JsonTokenType tokenType)
at System.Text.Json.Utf8JsonReader.GetString()
at k8s.Models.ResourceQuantityJsonConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonDictionaryConverter`3.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TDictionary& value)
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
When running KubernetesYaml, it deserializes properly
stringjsonString=@"{""cpu"": 1}";vartest= KubernetesYaml.Deserialize<Dictionary<string,ResourceQuantity>>(jsonString);// no error
Expected behavior KubernetesJson should deserialize a string with a ResourceQuantity properly regardless of whether it is a string or an int
Where do you run your app with Kubernetes SDK (please complete the following information):
OS: MacOs
Environment: LocalMachine
The text was updated successfully, but these errors were encountered:
Describe the bug
I have noticed a bug with
KubernetesJson
that if we create a CustomResourceDefinition that takes a ResourceQuantity schema where for example resource 'cpu' value is a number, deserialization fails. It only accepts strings for KubernetesJson deserializers.Custom resource example that works and cpu properly deserializes into a
ResourceQuantity
object in c#:Custom resource example that fails because cpu is a "number" and not a string:
This fails with a long error error such as
When using
KubernetesYaml
however, this works as expected and the values deserialize to the custom object containing a ResourceQuantity type as expected, regardless of whether the cpu value is a string or a number.My assumption that the root issue here lies with KubernetesJson that does not handle ResourceQuantity object deserialization.
KubernetesYaml handles it properly on the other hand.
Although the above is mainly a guess. Does any one know what the issue here might be exactly?
Kubernetes C# SDK Client Version
10.0.31
Server Kubernetes Version
1.24.16
Dotnet Runtime Version
net6
To Reproduce
create a json that can deserialize into a ResourceQuantity, for example:
The following will fail since cpu is now a number:
Should result in the following error
When running
KubernetesYaml
, it deserializes properlyExpected behavior
KubernetesJson
should deserialize a string with a ResourceQuantity properly regardless of whether it is a string or an intWhere do you run your app with Kubernetes SDK (please complete the following information):
The text was updated successfully, but these errors were encountered: