Skip to content

Commit

Permalink
Fix strict yaml parsing (#1061)
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-sz authored Oct 21, 2022
1 parent 0b67950 commit 16d3c01
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/KubernetesClient.Models/KubernetesYaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ public static List<object> LoadAllFromString(string content, IDictionary<string,
parser.Consume<StreamStart>();
while (parser.Accept<DocumentStart>(out _))
{
var obj = GetDeserializer(strict).Deserialize<KubernetesObject>(parser);
types.Add(mergedTypeMap[obj.ApiVersion + "/" + obj.Kind]);
var dict = GetDeserializer(strict).Deserialize<Dictionary<object, object>>(parser);
types.Add(mergedTypeMap[dict["apiVersion"] + "/" + dict["kind"]]);
}

parser = new Parser(new StringReader(content));
Expand Down
8 changes: 4 additions & 4 deletions tests/KubernetesClient.Tests/KubernetesYamlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public void LoadPropertyNamedReadOnlyFromString()
readOnly: false
";

var obj = KubernetesYaml.Deserialize<V1Pod>(content);
var obj = KubernetesYaml.Deserialize<V1Pod>(content, true);

Assert.True(obj.Spec.Containers[0].VolumeMounts[0].ReadOnlyProperty);
Assert.False(obj.Spec.Containers[0].VolumeMounts[1].ReadOnlyProperty);
Expand Down Expand Up @@ -476,7 +476,7 @@ public void CpuRequestAndLimitFromString()
- -cpus
- ""2""";

var obj = KubernetesYaml.Deserialize<V1Pod>(content);
var obj = KubernetesYaml.Deserialize<V1Pod>(content, true);

Assert.NotNull(obj?.Spec?.Containers);
var container = Assert.Single(obj.Spec.Containers);
Expand Down Expand Up @@ -811,7 +811,7 @@ public void LoadSecret()
password: Mzk1MjgkdmRnN0pi
";

var result = KubernetesYaml.Deserialize<V1Secret>(kManifest);
var result = KubernetesYaml.Deserialize<V1Secret>(kManifest, true);
Assert.Equal("bXktYXBw", Encoding.UTF8.GetString(result.Data["username"]));
Assert.Equal("Mzk1MjgkdmRnN0pi", Encoding.UTF8.GetString(result.Data["password"]));
}
Expand Down Expand Up @@ -890,7 +890,7 @@ public void LoadAllFromStringWithTypeMapGenericCRD()
var objs = KubernetesYaml.LoadAllFromString(content, new Dictionary<string, Type>
{
{ $"{V1AlphaFoo.KubeGroup}/{V1AlphaFoo.KubeApiVersion}/Foo", typeof(V1AlphaFoo) },
});
}, true);
Assert.Single(objs);
var v1AlphaFoo = Assert.IsType<V1AlphaFoo>(objs[0]);
Assert.Equal("foo", v1AlphaFoo.Metadata.Name);
Expand Down

0 comments on commit 16d3c01

Please sign in to comment.