public void ReturnObject() { var corev1Namespace = new V1Namespace() { Metadata = new V1ObjectMeta() { Name = "test name" }, Status = new V1NamespaceStatus() { Phase = "test termating" }, }; using (var server = new MockKubeApiServer(testOutput, resp: KubernetesJson.Serialize(corev1Namespace))) { var client = new Kubernetes(new KubernetesClientConfiguration { Host = server.Uri.ToString() }); var status = client.DeleteNamespace("test", new V1DeleteOptions()); Assert.True(status.HasObject); var obj = status.ObjectView <V1Namespace>(); Assert.Equal(obj.Metadata.Name, corev1Namespace.Metadata.Name); Assert.Equal(obj.Status.Phase, corev1Namespace.Status.Phase); } }
private static string BuildWatchEventStreamLine(WatchEventType eventType) { var corev1PodList = KubernetesJson.Deserialize <V1PodList>(MockPodResponse); return(KubernetesJson.Serialize(new Watcher <V1Pod> .WatchEvent { Type = eventType, Object = corev1PodList.Items.First() })); }
public void Serialize() { { var v = 123; IntstrIntOrString intorstr = v; Assert.Equal("123", KubernetesJson.Serialize(intorstr)); } { IntstrIntOrString intorstr = "12%"; Assert.Equal("\"12%\"", KubernetesJson.Serialize(intorstr)); } }
public async Task <bool> ShouldNext(HttpContext httpContext) { var isWatch = (httpContext.Request.Query.ContainsKey("watch") && httpContext.Request.Query["watch"] == "true"); var returnStatusCode = (_serverFlags.HasFlag(MockKubeServerFlags.Throw500) ? HttpStatusCode.InternalServerError : HttpStatusCode.OK); httpContext.Response.StatusCode = (int)returnStatusCode; httpContext.Response.ContentLength = null; if (isWatch) { ServerShutdown = new AsyncManualResetEvent(); foreach (Enum flag in Enum.GetValues(_serverFlags.GetType())) { if (!_serverFlags.HasFlag(flag)) { continue; } switch (flag) { case MockKubeServerFlags.AddedPod: await WriteStreamLine(httpContext, _mockAddedEventStreamLine).ConfigureAwait(false); break; case MockKubeServerFlags.ErrorPod: await WriteStreamLine(httpContext, _mockErrorStreamLine).ConfigureAwait(false); break; case MockKubeServerFlags.DeletedPod: await WriteStreamLine(httpContext, _mockDeletedStreamLine).ConfigureAwait(false); break; case MockKubeServerFlags.ModifiedPod: await WriteStreamLine(httpContext, _mockModifiedStreamLine).ConfigureAwait(false); break; case MockKubeServerFlags.BadJson: await WriteStreamLine(httpContext, MockBadStreamLine).ConfigureAwait(false); break; case MockKubeServerFlags.Throw500: return(false); } } // keep server connection open await ServerShutdown.WaitAsync().ConfigureAwait(false); return(false); } foreach (Enum flag in Enum.GetValues(_serverFlags.GetType())) { if (!_serverFlags.HasFlag(flag)) { continue; } switch (flag) { case MockKubeServerFlags.ListPods: await WriteStreamLine(httpContext, MockPodResponse).ConfigureAwait(false); break; case MockKubeServerFlags.GetPod: var corev1PodList = KubernetesJson.Deserialize <V1PodList>(MockPodResponse); await WriteStreamLine(httpContext, KubernetesJson.Serialize(corev1PodList.Items.First())).ConfigureAwait(false); break; case MockKubeServerFlags.Throw500: return(false); } } return(false); }
protected override T SetLeaderElectionRecord(LeaderElectionRecord record, T metaObj) { metaObj.SetAnnotation(LeaderElectionRecordAnnotationKey, KubernetesJson.Serialize(record)); return(metaObj); }