protected override async Task ProcessRecordAsync(CancellationToken cancellationToken)
        {
            await base.ProcessRecordAsync(cancellationToken);

            IEnumerable <NamespaceV1> namespaces;

            if (String.IsNullOrEmpty(Name) || WildcardPattern.ContainsWildcardCharacters(Name))
            {
                namespaces = await client.NamespacesV1().List(
                    labelSelector: LabelSelector,
                    cancellationToken: cancellationToken
                    );
            }
            else
            {
                NamespaceV1 ns = await client.NamespacesV1().Get(
                    name: Name,
                    cancellationToken: cancellationToken
                    );

                namespaces = new[] { ns };
            }
            if (WildcardPattern.ContainsWildcardCharacters(Name))
            {
                var pattern = new WildcardPattern(Name);
                namespaces = namespaces.Where(pod => pattern.IsMatch(pod.Metadata.Name));
            }
            WriteObject(namespaces, true);
        }
Beispiel #2
0
 private async Task CreateNamespace(string kubeNamespace)
 {
     var namespaceDto = new NamespaceV1
     {
         Metadata = new ObjectMetaV1 {
             Name = kubeNamespace
         },
     };
     await kubeApiClient.Dynamic().Apply(namespaceDto, fieldManager: "clud", force: true);
 }
        /// <summary>
        ///     Request creation of a <see cref="NamespaceV1"/>.
        /// </summary>
        /// <param name="newNamespace">
        ///     A <see cref="NamespaceV1"/> representing the Namespace to create.
        /// </param>
        /// <param name="cancellationToken">
        ///     An optional <see cref="CancellationToken"/> that can be used to cancel the request.
        /// </param>
        /// <returns>
        ///     A <see cref="NamespaceV1"/> representing the current state for the newly-created Namespace.
        /// </returns>
        public async Task <NamespaceV1> Create(NamespaceV1 newNamespace, CancellationToken cancellationToken = default)
        {
            if (newNamespace == null)
            {
                throw new ArgumentNullException(nameof(newNamespace));
            }

            return(await Http
                   .PostAsJsonAsync(Requests.Collection,
                                    postBody : newNamespace,
                                    cancellationToken : cancellationToken
                                    )
                   .ReadContentAsObjectV1Async <NamespaceV1>("create v1/Namespace resource"));
        }