private static void Main(string[] args)
        {
            var         k8SClientConfig = KubernetesClientConfiguration.BuildConfigFromConfigFile();
            IKubernetes client          = new Kubernetes(k8SClientConfig);

            ListNamespaces(client);

            var ns = new V1Namespace {
                Metadata = new V1ObjectMeta {
                    Name = "test"
                }
            };

            var result = client.CreateNamespace(ns);

            Console.WriteLine(result);

            ListNamespaces(client);

            var status = client.DeleteNamespace(ns.Metadata.Name, new V1DeleteOptions());

            if (status.HasObject)
            {
                var obj = status.ObjectView <V1Namespace>();
                Console.WriteLine(obj.Status.Phase);

                Delete(client, ns.Metadata.Name, 3 * 1000);
            }
            else
            {
                Console.WriteLine(status.Message);
            }

            ListNamespaces(client);
        }
        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: JsonConvert.SerializeObject(corev1Namespace)))
            {
                var client = new Kubernetes(new KubernetesClientConfiguration
                {
                    Host = server.Uri.ToString()
                });

                var status = client.DeleteNamespace(new V1DeleteOptions(), "test");

                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);
            }
        }
Beispiel #3
0
 /// <summary>
 /// Dispose of the job manager by deleting the namespace and all pods
 /// therein.
 /// </summary>
 public override void Dispose()
 {
     // RemoveWorkers();
     WriteToLog("Deleting namespace...");
     client.DeleteNamespace(podNamespace);
     client.Dispose();
 }
        private void DeleteNamespaceIfEmpty(User user)
        {
            var groupNamespaceName = user.Spec.GetGroupNamespace();
            var serviceAccountName = user.Metadata.Name;
            var serviceAccounts    = _client.ListNamespacedServiceAccount(groupNamespaceName);

            if (serviceAccounts.Items.Count == 1 && serviceAccounts.Items[0].Metadata.Name == "default")
            {
                _client.DeleteNamespace(groupNamespaceName);
                Console.WriteLine($"** No accounts left, deleted namespace: {groupNamespaceName}");
            }
        }
Beispiel #5
0
        public ActionResult <IEnumerable <string> > deleteNamespace()
        {
            var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
            var client = new Kubernetes(config);
            var ns     = new V1Namespace
            {
                Metadata = new V1ObjectMeta
                {
                    Name = "test"
                }
            };
            var status = client.DeleteNamespace(new V1DeleteOptions(), ns.Metadata.Name);

            return(new string[] { "Operation", "Namespace Deleted" });
        }
        public void ReturnStatus()
        {
            var v1Status = new V1Status {
                Message = "test message", Status = "test status"
            };

            using (var server = new MockKubeApiServer(testOutput, resp: JsonConvert.SerializeObject(v1Status)))
            {
                var client = new Kubernetes(new KubernetesClientConfiguration {
                    Host = server.Uri.ToString()
                });

                var status = client.DeleteNamespace("test", new V1DeleteOptions());

                Assert.False(status.HasObject);
                Assert.Equal(v1Status.Message, status.Message);
                Assert.Equal(v1Status.Status, status.Status);
            }
        }
Beispiel #7
0
        public IActionResult Delete([FromQuery] string name)
        {
            var result = kubeClient.DeleteNamespace(name);

            return(Ok());
        }