Exemple #1
0
        public void CreatePodHttpClient_ValidatesArguments()
        {
            var protocol = new Mock <IKubernetesProtocol>(MockBehavior.Strict);

            protocol.Setup(p => p.Dispose()).Verifiable();

            using (var client = new KubernetesClient(protocol.Object, KubernetesOptions.Default, NullLogger <KubernetesClient> .Instance, NullLoggerFactory.Instance))
            {
                Assert.Throws <ArgumentNullException>("pod", () => client.CreatePodHttpClient(null, 80));
                Assert.Throws <ValidationException>(() => client.CreatePodHttpClient(new V1Pod(), 80));
                Assert.Throws <ValidationException>(() => client.CreatePodHttpClient(new V1Pod()
                {
                    Metadata = new V1ObjectMeta()
                }, 80));
                Assert.Throws <ValidationException>(() => client.CreatePodHttpClient(new V1Pod()
                {
                    Metadata = new V1ObjectMeta()
                    {
                        Name = "foo"
                    }
                }, 80));
                Assert.Throws <ValidationException>(() => client.CreatePodHttpClient(new V1Pod()
                {
                    Metadata = new V1ObjectMeta()
                    {
                        NamespaceProperty = "bar"
                    }
                }, 80));
            }
        }
Exemple #2
0
        public async Task Registry_Running_Async()
        {
            var config = KubernetesClientConfiguration.BuildDefaultConfig();

            if (config.Namespace == null)
            {
                config.Namespace = "default";
            }

            using (var kubernetes = new KubernetesProtocol(
                       config,
                       this.loggerFactory.CreateLogger <KubernetesProtocol>(),
                       this.loggerFactory))
                using (var client = new KubernetesClient(
                           kubernetes,
                           KubernetesOptions.Default,
                           this.output.BuildLoggerFor <KubernetesClient>(),
                           this.loggerFactory))
                {
                    // There's at least one usbmuxd pod
                    var pods = await kubernetes.ListNamespacedPodAsync(config.Namespace, labelSelector : "app.kubernetes.io/component=registry");

                    Assert.NotEmpty(pods.Items);
                    var pod = pods.Items[0];

                    // The pod is in the running state
                    pod = await client.WaitForPodRunningAsync(pod, TimeSpan.FromMinutes(2), default).ConfigureAwait(false);

                    Assert.Equal("Running", pod.Status.Phase);

                    // Try to perform a handshake
                    var httpClient = client.CreatePodHttpClient(pod, 5000);
                    httpClient.BaseAddress = new Uri($"http://{pod.Metadata.Name}:5000/v2/");

                    var response = await httpClient.GetAsync(string.Empty).ConfigureAwait(false);

                    Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                    var apiVersion = Assert.Single(response.Headers.GetValues("Docker-Distribution-Api-Version"));
                    Assert.Equal("registry/2.0", apiVersion);
                }
        }