fix tests and examples to use v1.8 model
This commit is contained in:
@@ -54,7 +54,7 @@ namespace @namespace
|
||||
|
||||
ListNamespaces(client);
|
||||
|
||||
var ns = new Corev1Namespace
|
||||
var ns = new V1Namespace
|
||||
{
|
||||
Metadata = new V1ObjectMeta
|
||||
{
|
||||
@@ -71,7 +71,7 @@ namespace @namespace
|
||||
|
||||
if (status.HasObject)
|
||||
{
|
||||
var obj = status.ObjectView<Corev1Namespace>();
|
||||
var obj = status.ObjectView<V1Namespace>();
|
||||
Console.WriteLine(obj.Status.Phase);
|
||||
|
||||
Delete(client, ns.Metadata.Name, 3 * 1000);
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
using System;
|
||||
using k8s;
|
||||
|
||||
namespace simple
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
using k8s;
|
||||
|
||||
class PodList
|
||||
internal class PodList
|
||||
{
|
||||
static void Main(string[] args)
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
var k8sClientConfig = KubernetesClientConfiguration.BuildConfigFromConfigFile();
|
||||
IKubernetes client = new Kubernetes(k8sClientConfig);
|
||||
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
|
||||
IKubernetes client = new Kubernetes(config);
|
||||
Console.WriteLine("Starting Request!");
|
||||
var listTask = client.ListNamespacedPodWithHttpMessagesAsync("default").Result;
|
||||
var list = listTask.Body;
|
||||
foreach (var item in list.Items) {
|
||||
|
||||
var list = client.ListNamespacedPod("default");
|
||||
foreach (var item in list.Items)
|
||||
{
|
||||
Console.WriteLine(item.Metadata.Name);
|
||||
}
|
||||
if (list.Items.Count == 0) {
|
||||
if (list.Items.Count == 0)
|
||||
{
|
||||
Console.WriteLine("Empty!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace watch
|
||||
IKubernetes client = new Kubernetes(config);
|
||||
|
||||
var podlistResp = client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).Result;
|
||||
using (podlistResp.Watch<Corev1Pod>((type, item) =>
|
||||
using (podlistResp.Watch<V1Pod>((type, item) =>
|
||||
{
|
||||
Console.WriteLine("==on watch event==");
|
||||
Console.WriteLine(type);
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace k8s.Models
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
var s = (value as IntOrString)?.Value;
|
||||
var s = (value as IntstrIntOrString)?.Value;
|
||||
|
||||
if (int.TryParse(s, out var intv))
|
||||
{
|
||||
@@ -21,7 +21,7 @@ namespace k8s.Models
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
|
||||
JsonSerializer serializer)
|
||||
{
|
||||
return (IntOrString) serializer.Deserialize<string>(reader);
|
||||
return (IntstrIntOrString) serializer.Deserialize<string>(reader);
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
@@ -31,26 +31,26 @@ namespace k8s.Models
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(IntOrStringConverter))]
|
||||
public partial class IntOrString
|
||||
public partial class IntstrIntOrString
|
||||
{
|
||||
public static implicit operator int(IntOrString v)
|
||||
public static implicit operator int(IntstrIntOrString v)
|
||||
{
|
||||
return int.Parse(v.Value);
|
||||
}
|
||||
|
||||
public static implicit operator IntOrString(int v)
|
||||
public static implicit operator IntstrIntOrString(int v)
|
||||
{
|
||||
return new IntOrString(Convert.ToString(v));
|
||||
return new IntstrIntOrString(Convert.ToString(v));
|
||||
}
|
||||
|
||||
public static implicit operator string(IntOrString v)
|
||||
public static implicit operator string(IntstrIntOrString v)
|
||||
{
|
||||
return v.Value;
|
||||
}
|
||||
|
||||
public static implicit operator IntOrString(string v)
|
||||
public static implicit operator IntstrIntOrString(string v)
|
||||
{
|
||||
return new IntOrString(v);
|
||||
return new IntstrIntOrString(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ namespace k8s.Tests
|
||||
{
|
||||
public class AuthTests
|
||||
{
|
||||
private static HttpOperationResponse<Corev1PodList> ExecuteListPods(IKubernetes client)
|
||||
private static HttpOperationResponse<V1PodList> ExecuteListPods(IKubernetes client)
|
||||
{
|
||||
return client.ListNamespacedPodWithHttpMessagesAsync("default").Result;
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ namespace k8s.Tests
|
||||
{
|
||||
{
|
||||
var v = 123;
|
||||
IntOrString intorstr = v;
|
||||
IntstrIntOrString intorstr = v;
|
||||
|
||||
Assert.Equal("123", JsonConvert.SerializeObject(intorstr));
|
||||
}
|
||||
|
||||
{
|
||||
IntOrString intorstr = "12%";
|
||||
IntstrIntOrString intorstr = "12%";
|
||||
Assert.Equal("\"12%\"", JsonConvert.SerializeObject(intorstr));
|
||||
}
|
||||
}
|
||||
@@ -26,12 +26,12 @@ namespace k8s.Tests
|
||||
public void Deserialize()
|
||||
{
|
||||
{
|
||||
var v = JsonConvert.DeserializeObject<IntOrString>("1234");
|
||||
var v = JsonConvert.DeserializeObject<IntstrIntOrString>("1234");
|
||||
Assert.Equal("1234", v.Value);
|
||||
}
|
||||
|
||||
{
|
||||
var v = JsonConvert.DeserializeObject<IntOrString>("\"12%\"");
|
||||
var v = JsonConvert.DeserializeObject<IntstrIntOrString>("\"12%\"");
|
||||
Assert.Equal("12%", v.Value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,13 +34,13 @@ namespace k8s.Tests
|
||||
[Fact]
|
||||
public void ReturnObject()
|
||||
{
|
||||
var corev1Namespace = new Corev1Namespace()
|
||||
var corev1Namespace = new V1Namespace()
|
||||
{
|
||||
Metadata = new V1ObjectMeta()
|
||||
{
|
||||
Name = "test name"
|
||||
},
|
||||
Status = new Corev1NamespaceStatus()
|
||||
Status = new V1NamespaceStatus()
|
||||
{
|
||||
Phase = "test termating"
|
||||
}
|
||||
@@ -57,7 +57,7 @@ namespace k8s.Tests
|
||||
|
||||
Assert.True(status.HasObject);
|
||||
|
||||
var obj = status.ObjectView<Corev1Namespace>();
|
||||
var obj = status.ObjectView<V1Namespace>();
|
||||
|
||||
Assert.Equal(obj.Metadata.Name, corev1Namespace.Metadata.Name);
|
||||
Assert.Equal(obj.Status.Phase, corev1Namespace.Status.Phase);
|
||||
|
||||
@@ -26,8 +26,8 @@ namespace k8s.Tests
|
||||
|
||||
private static string BuildWatchEventStreamLine(WatchEventType eventType)
|
||||
{
|
||||
var corev1PodList = JsonConvert.DeserializeObject<Corev1PodList>(MockKubeApiServer.MockPodResponse);
|
||||
return JsonConvert.SerializeObject(new Watcher<Corev1Pod>.WatchEvent
|
||||
var corev1PodList = JsonConvert.DeserializeObject<V1PodList>(MockKubeApiServer.MockPodResponse);
|
||||
return JsonConvert.SerializeObject(new Watcher<V1Pod>.WatchEvent
|
||||
{
|
||||
Type = eventType,
|
||||
Object = corev1PodList.Items.First()
|
||||
@@ -57,7 +57,7 @@ namespace k8s.Tests
|
||||
var listTask = client.ListNamespacedPodWithHttpMessagesAsync("default").Result;
|
||||
Assert.ThrowsAny<KubernetesClientException>(() =>
|
||||
{
|
||||
listTask.Watch<Corev1Pod>((type, item) => { });
|
||||
listTask.Watch<V1Pod>((type, item) => { });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace k8s.Tests
|
||||
var events = new HashSet<WatchEventType>();
|
||||
var errors = 0;
|
||||
|
||||
var watcher = listTask.Watch<Corev1Pod>(
|
||||
var watcher = listTask.Watch<V1Pod>(
|
||||
(type, item) => { events.Add(type); },
|
||||
e => { errors += 1; }
|
||||
);
|
||||
@@ -159,7 +159,7 @@ namespace k8s.Tests
|
||||
|
||||
var events = new HashSet<WatchEventType>();
|
||||
|
||||
var watcher = listTask.Watch<Corev1Pod>(
|
||||
var watcher = listTask.Watch<V1Pod>(
|
||||
(type, item) => { events.Add(type); }
|
||||
);
|
||||
|
||||
@@ -217,7 +217,7 @@ namespace k8s.Tests
|
||||
var events = new HashSet<WatchEventType>();
|
||||
var errors = 0;
|
||||
|
||||
var watcher = listTask.Watch<Corev1Pod>(
|
||||
var watcher = listTask.Watch<V1Pod>(
|
||||
(type, item) => { events.Add(type); },
|
||||
e => { errors += 1; }
|
||||
);
|
||||
@@ -240,7 +240,7 @@ namespace k8s.Tests
|
||||
[Fact]
|
||||
public void WatchServerDisconnect()
|
||||
{
|
||||
Watcher<Corev1Pod> watcher;
|
||||
Watcher<V1Pod> watcher;
|
||||
Exception exceptionCatched = null;
|
||||
|
||||
using (var server = new MockKubeApiServer(async httpContext =>
|
||||
@@ -260,7 +260,7 @@ namespace k8s.Tests
|
||||
|
||||
var listTask = client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).Result;
|
||||
|
||||
watcher = listTask.Watch<Corev1Pod>(
|
||||
watcher = listTask.Watch<V1Pod>(
|
||||
(type, item) => { },
|
||||
e => { exceptionCatched = e; });
|
||||
}
|
||||
@@ -315,7 +315,7 @@ namespace k8s.Tests
|
||||
|
||||
var events = new HashSet<WatchEventType>();
|
||||
|
||||
var watcher = listTask.Watch<Corev1Pod>(
|
||||
var watcher = listTask.Watch<V1Pod>(
|
||||
(type, item) => { events.Add(type); }
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user