示例#1
0
        /// <summary>
        ///     Get all Pods in the specified namespace, optionally matching a label selector.
        /// </summary>
        /// <param name="labelSelector">
        ///     An optional Kubernetes label selector expression used to filter the Pods.
        /// </param>
        /// <param name="kubeNamespace">
        ///     The target Kubernetes namespace (defaults to <see cref="KubeApiClient.DefaultNamespace"/>).
        /// </param>
        /// <param name="cancellationToken">
        ///     An optional <see cref="CancellationToken"/> that can be used to cancel the request.
        /// </param>
        /// <returns>
        ///     The Pods, as a list of <see cref="PodV1"/>s.
        /// </returns>
        public async Task <List <PodV1> > List(string labelSelector = null, string kubeNamespace = null, CancellationToken cancellationToken = default)
        {
            PodListV1 matchingPods =
                await Http.GetAsync(
                    Requests.Collection.WithTemplateParameters(new
            {
                Namespace     = kubeNamespace ?? Client.DefaultNamespace,
                LabelSelector = labelSelector
            }),
                    cancellationToken : cancellationToken
                    )
                .ReadContentAsAsync <PodListV1, StatusV1>();

            return(matchingPods.Items);
        }
示例#2
0
    public void CheckRandom()
    {
        // Assumes you're using "kubectl proxy", and no authentication is required.
        KubeApiClient client = KubeApiClient.Create("http://localhost:8001");

        PodListV1 pods = await client.PodsV1().List(
            labelSelector: "k8s-app=my-app"
            );    // Load from the default kubeconfig on the machine.

        var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();


        // Use the config object to create a client.
        var client = new Kubernetes(config);

        //var r = await GetRandomFromApi();


        //for (int i = 0; i < r.random; i++)
        //{
        //    Instantiate(prefab);
        //    await Task.Delay(500);
        //}
    }