Exemple #1
0
        public async Task <(bool found, bool update)> DeleteClusterAsync(Guid id)
        {
            var cluster = await clusterRepository.ReadAsync(c => c.Id == id);

            if (cluster == null)
            {
                return(false, false);
            }

            cluster.DeleteAt = DateTime.UtcNow;

            if ((await clusterRepository.UpdateClusterAsync(cluster)) > 0)
            {
                var nodes = await clusterNodeRepository.ReadsAsync(c => c.ClusterId == cluster.Id && c.DeleteAt == null);

                var selectedNode = await datacenterRepository.ReadAsync(f => f.Id == cluster.ProxmoxNodeId);

                var qemuClient = new QemuClient();

                foreach (var node in nodes)
                {
                    node.DeleteAt = DateTime.UtcNow;
                    await qemuClient.DeleteQemu(selectedNode.Name, node.OrderId);

                    await clusterNodeRepository.UpdateClusterNodeAsync(node);
                }

                return(true, await qemuClient.DeleteQemu(selectedNode.Name, cluster.OrderId));
            }

            return(true, false);
        }
Exemple #2
0
 private async Task ProcessStateAsync(Domain.Entities.Cluster cluster, k8s.Models.V1NodeList clusterNodes)
 {
     try
     {
         foreach (var clusterNode in clusterNodes.Items)
         {
             if (clusterNode.Metadata.Name.Contains("master"))
             {
                 cluster.State = clusterNode.Status.Conditions.FirstOrDefault(c => c.Reason == "KubeletReady")?.Type;
                 var _ = await clusterRepository.UpdateClusterAsync(cluster);
             }
             else
             {
                 var node = cluster.Nodes.FirstOrDefault(n => n.Name == clusterNode.Metadata.Name);
                 if (node != null)
                 {
                     node.State = clusterNode.Status.Conditions.FirstOrDefault(c => c.Reason == "KubeletReady")?.Type;
                     var __ = await clusterNodeRepository.UpdateClusterNodeAsync(node);
                 }
             }
         }
     }
     catch (Exception e)
     {
         logger.LogError(e, "Error on processing state");
     }
 }
        public async Task StartQueueListener()
        {
            await queueService.OnQueueMessageInit(async (message) =>
            {
                var clusterResult = JsonSerializer.Deserialize <ClusterCreationResultMessage>(message);
                var cluster       = await clusterRepository.ReadAsync(c => c.OrderId == clusterResult.Data.OrderId);

                if (cluster != null)
                {
                    cluster.KubeConfig     = clusterResult.Data.KubeConfig;
                    cluster.KubeConfigJson = clusterResult.Data.KubeConfigAsJson;

                    if ((await clusterRepository.UpdateClusterAsync(cluster)) > 0)
                    {
                        await hubContext.Clients.All.NotificationReceived("Cluster ready", "Cluster created and ready to use.", "success");
                    }
                }
            });
        }