예제 #1
0
        public async Task <SystemInfo> GetSystemInfo()
        {
            V1NodeList k8SNodes = await this.client.ListNodeAsync();

            string osType  = string.Empty;
            string arch    = string.Empty;
            string version = string.Empty;

            if (k8SNodes.Items != null)
            {
                V1Node firstNode = k8SNodes.Items.FirstOrDefault();

                if (firstNode?.Status?.NodeInfo != null)
                {
                    osType  = firstNode.Status.NodeInfo.OperatingSystem;
                    arch    = firstNode.Status.NodeInfo.Architecture;
                    version = firstNode.Status.NodeInfo.OsImage;
                }
                else
                {
                    Events.NullNodeInfoResponse(firstNode?.Metadata?.Name ?? "UNKNOWN");
                }
            }

            return(new SystemInfo(osType, arch, version));
        }
예제 #2
0
            /// <summary>
            /// Get node status from the Kubernetes API server.
            /// </summary>
            /// <returns></returns>
            public async Task GetNodesStatusAsync()
            {
                await SyncContext.Clear;

                var key = "nodes";

                try
                {
                    var value = await Cache.GetAsync <V1NodeList>(key);

                    if (value != null)
                    {
                        Nodes = value;
                    }
                }
                catch (Exception e)
                {
                    Logger.LogError(e);
                }

                try
                {
                    Nodes = await K8s.ListNodeAsync();

                    TotalNodes  = Nodes.Items.Count();
                    FailedNodes = Nodes.Items.Where(node => node.Status.Conditions.Any(condition => negativeNodeConditions.Contains(condition.Type) && condition.Status == "True")).Count();
                    ActiveNodes = Nodes.Items.Where(node => node.Status.Conditions.Any(condition => condition.Type == "Ready" && condition.Status == "True")).Count();

                    NotifyStateChanged();
                }
                catch (Exception e)
                {
                    Logger.LogError(e);
                }
            }
예제 #3
0
 public NodesInfo(V1NodeList v1NodeList)
 {
     v1NodeList.Items.ToList().ForEach(node =>
     {
         NodeAddresses = node.Status.Addresses.ToList().Select(address => address.Address);
     });
 }
예제 #4
0
        public async void GetSystemInfoTest(V1NodeList k8SNodes, SystemInfo expectedInfo)
        {
            var response = new HttpOperationResponse <V1NodeList>();

            response.Body = k8SNodes;
            var client = new Mock <IKubernetes>(MockBehavior.Strict); // Mock.Of<IKubernetes>(kc => kc.ListNodeAsync() == Task.FromResult(k8SNodes));

            client.Setup(
                kc =>
                kc.ListNodeWithHttpMessagesAsync(null, null, null, null, null, null, null, null, null, It.IsAny <CancellationToken>())).ReturnsAsync(() => response);
            var k8sRuntimeInfo = new KubernetesRuntimeInfoProvider(PodwatchNamespace, client.Object);

            var result = await k8sRuntimeInfo.GetSystemInfo();

            Assert.Equal(expectedInfo.Architecture, result.Architecture);
            Assert.Equal(expectedInfo.OperatingSystemType, result.OperatingSystemType);
            Assert.Equal(expectedInfo.Version, result.Version);
            client.VerifyAll();
        }