Example #1
0
        public async Task TestWithSpdySession()
        {
            var podPort = 80;
            var config  = new KubernetesConfiguration();
            var factory =
                new KubernetesClientFactory(config);

            using var client = factory.Create("kind-argo-demo-test");
            var session = await client.SpdyNamespacedPodPortForwardAsync(
                "argocd-server-78ffb87fd8-f6559",
                "argocd",
                new[] { podPort },
                CancellationToken.None)
                          .ConfigureAwait(false);

            using var stream = session.Open(
                      headers: new NameValueHeaderBlock(
                          (Kubernetes.Headers.StreamType, new[]
            {
                Kubernetes.Headers.StreamTypeData
            }),
                          (Kubernetes.Headers.Port, new[]
            {
                podPort.ToString()
            })));
            await stream.Remote.WaitForOpenedAsync()
            .ConfigureAwait(false);

            await Task.Delay(10)
            .ConfigureAwait(false);
        }
Example #2
0
        /// <summary>
        /// Creates api client if not exists.
        /// </summary>
        /// <returns></returns>
        private static void CreateClientIfNotExists()
        {
            if (_client != null)
            {
                return;
            }
            if (!IsKubernetes)
            {
                return;
            }

            ApiClient client = new ApiClient($"https://{Host}:{Port}/");

            Configuration.DefaultApiClient = client;
            try
            {
                KubernetesConfiguration.ConfigureWithPodEnvironment();
            }
            catch (NotKubernetesPodException)
            {
                return;
            }
            _client = client;
            client.AddDefaultHeader("Authorization", "Bearer " + Configuration.Password);

            // Initialize APIs
            APIApi        = new ApiApi(client);
            APIsApi       = new ApisApi(client);
            ExtensionsApi = new ExtensionsApi(client);
            V1Api         = new VApi(client);
            VBetaApi      = new VbetaApi(client);
            VersionApi    = new VersionApi(client);
        }
Example #3
0
        public async Task TestWithSpdy()
        {
            var config  = new KubernetesConfiguration();
            var factory =
                new KubernetesClientFactory(config);

            await using var ks = new KubernetesService(
                            factory, new SocketNetworkServerFactory(), new TestFeatureManager((nameof(Features.PortForwardingWithSpdy), true)));
            await ks.PortForwardAsync(
                "kind-argo-demo-test", new Shared.PortForward(
                    podPort: 80,
                    protocolType: ProtocolType.Tcp,
                    @namespace: "argocd",
                    service: "",
                    pod: "argocd-server-78ffb87fd8-f6559")
            {
                LocalPort = 8081
            }, CancellationTokenSource.Token)
            .ConfigureAwait(false);

            await Task.Delay(5000)
            .ConfigureAwait(false);
        }