Skip to content

Commit

Permalink
fix obsolete warning about KubernetesYaml (#839)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiweiv authored Apr 22, 2022
1 parent 262e166 commit 4db390f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/KubernetesClient.Models/KubernetesYaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public static async Task<T> LoadFromStreamAsync<T>(Stream stream)
{
var reader = new StreamReader(stream);
var content = await reader.ReadToEndAsync().ConfigureAwait(false);
return LoadFromString<T>(content);
return Deserialize<T>(content);
}

public static async Task<T> LoadFromFileAsync<T>(string file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ public void ContextWithWildcardIPv62()
public void LoadKubeConfigExplicitFilePath()
{
var txt = File.ReadAllText("assets/kubeconfig.yml");
var expectedCfg = KubernetesYaml.LoadFromString<K8SConfiguration>(txt);
var expectedCfg = KubernetesYaml.Deserialize<K8SConfiguration>(txt);

var cfg = KubernetesClientConfiguration.LoadKubeConfig("assets/kubeconfig.yml");

Expand All @@ -458,7 +458,7 @@ public void LoadKubeConfigFileInfo()
{
var filePath = "assets/kubeconfig.yml";
var txt = File.ReadAllText(filePath);
var expectedCfg = KubernetesYaml.LoadFromString<K8SConfiguration>(txt);
var expectedCfg = KubernetesYaml.Deserialize<K8SConfiguration>(txt);

var fileInfo = new FileInfo(filePath);
var cfg = KubernetesClientConfiguration.LoadKubeConfig(fileInfo);
Expand All @@ -472,7 +472,7 @@ public void LoadKubeConfigStream()
{
var filePath = "assets/kubeconfig.yml";
var txt = File.ReadAllText(filePath);
var expectedCfg = KubernetesYaml.LoadFromString<K8SConfiguration>(txt);
var expectedCfg = KubernetesYaml.Deserialize<K8SConfiguration>(txt);

var fileInfo = new FileInfo(filePath);
K8SConfiguration cfg;
Expand Down Expand Up @@ -524,7 +524,7 @@ public void LoadKubeConfigFromEnvironmentVariableMultipleConfigs()
public void LoadSameKubeConfigFromEnvironmentVariableUnmodified()
{
var txt = File.ReadAllText("assets/kubeconfig.yml");
var expectedCfg = KubernetesYaml.LoadFromString<K8SConfiguration>(txt);
var expectedCfg = KubernetesYaml.Deserialize<K8SConfiguration>(txt);

var fileInfo = new FileInfo(Path.GetFullPath("assets/kubeconfig.yml"));

Expand All @@ -537,7 +537,7 @@ public void LoadSameKubeConfigFromEnvironmentVariableUnmodified()
public void LoadKubeConfigWithAdditionalProperties()
{
var txt = File.ReadAllText("assets/kubeconfig.additional-properties.yml");
var expectedCfg = KubernetesYaml.LoadFromString<K8SConfiguration>(txt);
var expectedCfg = KubernetesYaml.Deserialize<K8SConfiguration>(txt);

var fileInfo = new FileInfo(Path.GetFullPath("assets/kubeconfig.additional-properties.yml"));

Expand Down
34 changes: 17 additions & 17 deletions tests/KubernetesClient.Tests/KubernetesYamlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void LoadFromString()
name: foo
";

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

Assert.Equal("foo", obj.Metadata.Name);
}
Expand All @@ -208,7 +208,7 @@ public void LoadFromStringWithAdditionalProperties()
youDontKnow: Me
";

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

Assert.Equal("foo", obj.Metadata.Name);
}
Expand All @@ -223,7 +223,7 @@ public void LoadFromStringWithAdditionalPropertiesAndCustomType()
youDontKnow: Me
";

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

Assert.Equal("foo", obj.Metadata.Name);
}
Expand All @@ -238,7 +238,7 @@ public void LoadNamespacedFromString()
name: foo
";

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

Assert.Equal("foo", obj.Metadata.Name);
Assert.Equal("bar", obj.Metadata.NamespaceProperty);
Expand All @@ -264,7 +264,7 @@ public void LoadPropertyNamedReadOnlyFromString()
readOnly: false
";

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

Assert.True(obj.Spec.Containers[0].VolumeMounts[0].ReadOnlyProperty);
Assert.False(obj.Spec.Containers[0].VolumeMounts[1].ReadOnlyProperty);
Expand Down Expand Up @@ -318,10 +318,10 @@ public void RoundtripTypeWithMismatchedPropertyName()
{
var content = @"namespace: foo";

var deserialized = KubernetesYaml.LoadFromString<V1ObjectMeta>(content);
var deserialized = KubernetesYaml.Deserialize<V1ObjectMeta>(content);
Assert.Equal("foo", deserialized.NamespaceProperty);

var serialized = KubernetesYaml.SaveToString(deserialized);
var serialized = KubernetesYaml.Serialize(deserialized);
Assert.Equal(content, serialized);
}

Expand All @@ -330,7 +330,7 @@ public void WriteToString()
{
var pod = new V1Pod() { ApiVersion = "v1", Kind = "Pod", Metadata = new V1ObjectMeta() { Name = "foo" } };

var yaml = KubernetesYaml.SaveToString(pod);
var yaml = KubernetesYaml.Serialize(pod);
Assert.Equal(
ToLines(@"apiVersion: v1
kind: Pod
Expand All @@ -348,7 +348,7 @@ public void WriteNamespacedToString()
Metadata = new V1ObjectMeta() { Name = "foo", NamespaceProperty = "bar" },
};

var yaml = KubernetesYaml.SaveToString(pod);
var yaml = KubernetesYaml.Serialize(pod);
Assert.Equal(
ToLines(@"apiVersion: v1
kind: Pod
Expand Down Expand Up @@ -388,7 +388,7 @@ public void WritePropertyNamedReadOnlyToString()
},
};

var yaml = KubernetesYaml.SaveToString(pod);
var yaml = KubernetesYaml.Serialize(pod);
Assert.Equal(
ToLines(@"apiVersion: v1
kind: Pod
Expand Down Expand Up @@ -446,7 +446,7 @@ public void CpuRequestAndLimitFromString()
- -cpus
- ""2""";

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

Assert.NotNull(obj?.Spec?.Containers);
var container = Assert.Single(obj.Spec.Containers);
Expand Down Expand Up @@ -476,7 +476,7 @@ public void LoadIntOrString()
targetPort: 3000
";

var obj = KubernetesYaml.LoadFromString<V1Service>(content);
var obj = KubernetesYaml.Deserialize<V1Service>(content);

Assert.Equal(3000, obj.Spec.Ports[0].Port);
Assert.Equal(3000, int.Parse(obj.Spec.Ports[0].TargetPort));
Expand Down Expand Up @@ -508,7 +508,7 @@ public void SerializeIntOrString()
},
};

var output = KubernetesYaml.SaveToString(obj);
var output = KubernetesYaml.Serialize(obj);
Assert.Equal(ToLines(output), ToLines(content));
}

Expand All @@ -534,11 +534,11 @@ public void QuotedValuesShouldRemainQuotedAfterSerialization()
value: ""false""
image: vish/stress
name: cpu-demo-ctr";
var obj = KubernetesYaml.LoadFromString<V1Pod>(content);
var obj = KubernetesYaml.Deserialize<V1Pod>(content);
Assert.NotNull(obj?.Spec?.Containers);
var container = Assert.Single(obj.Spec.Containers);
Assert.NotNull(container.Env);
var objStr = KubernetesYaml.SaveToString(obj);
var objStr = KubernetesYaml.Serialize(obj);
Assert.Equal(content.Replace("\r\n", "\n"), objStr.Replace("\r\n", "\n"));
}

Expand All @@ -555,7 +555,7 @@ public void LoadSecret()
password: Mzk1MjgkdmRnN0pi
";

var result = KubernetesYaml.LoadFromString<V1Secret>(kManifest);
var result = KubernetesYaml.Deserialize<V1Secret>(kManifest);
Assert.Equal("bXktYXBw", Encoding.UTF8.GetString(result.Data["username"]));
Assert.Equal("Mzk1MjgkdmRnN0pi", Encoding.UTF8.GetString(result.Data["password"]));
}
Expand Down Expand Up @@ -589,7 +589,7 @@ public void DeserializeWithJsonPropertyName()
served: true
storage: true
";
var result = KubernetesYaml.LoadFromString<V1CustomResourceDefinition>(kManifest);
var result = KubernetesYaml.Deserialize<V1CustomResourceDefinition>(kManifest);
Assert.Single(result?.Spec?.Versions);
var ver = result.Spec.Versions[0];
Assert.Equal(true, ver?.Schema?.OpenAPIV3Schema?.XKubernetesIntOrString);
Expand Down
4 changes: 2 additions & 2 deletions tests/KubernetesClient.Tests/QuantityValueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,14 @@ public void Serialize()
[Fact]
public void DeserializeYaml()
{
var value = KubernetesYaml.LoadFromString<ResourceQuantity>("\"1\"");
var value = KubernetesYaml.Deserialize<ResourceQuantity>("\"1\"");
Assert.Equal(new ResourceQuantity(1, 0, DecimalSI), value);
}

[Fact]
public void SerializeYaml()
{
var value = KubernetesYaml.SaveToString(new ResourceQuantity(1, -1, DecimalSI));
var value = KubernetesYaml.Serialize(new ResourceQuantity(1, -1, DecimalSI));
Assert.Equal("100m", value);
}
}
Expand Down

0 comments on commit 4db390f

Please sign in to comment.