func genNodes(list *api.NodeList) (nodes []page.Node) { allPods, _ := kubeclient.GetAllPods() for i := range list.Items { nodes = append(nodes, genOneNode(&list.Items[i], allPods)) } return }
func describeNode(c *gin.Context) { nodename := c.Param("no") node, err := kubeclient.Get().Nodes().Get(nodename) if err != nil { c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()}) return } d := page.NodeDetail{ Name: node.Name, Labels: node.Labels, CreationTimestamp: node.CreationTimestamp.Time.Format(time.RFC1123Z), Conditions: node.Status.Conditions, Capacity: kube.TranslateResourseList(node.Status.Capacity), SystemInfo: node.Status.NodeInfo, } allPods, err := kubeclient.GetAllPods() if err != nil { c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()}) return } d.Pods = kube.FilterNodePods(allPods, node) d.TerminatedPods, d.NonTerminatedPods = kube.FilterTerminatedPods(d.Pods) d.NonTerminatedPodsResources = computePodsResources(d.NonTerminatedPods, node) d.TerminatedPodsResources = computePodsResources(d.TerminatedPods, node) d.AllocatedResources, err = computeNodeResources(d.NonTerminatedPods, node) if err != nil { c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()}) return } var pods []page.Pod for _, pod := range d.Pods { pods = append(pods, genOnePod(pod)) } var nodeEvents []page.Event var nodeEventList *api.EventList if ref, err := api.GetReference(node); err != nil { glog.Errorf("Unable to construct reference to '%#v': %v", node, err) } else { ref.UID = types.UID(ref.Name) if nodeEventList, err = kubeclient.Get().Events("").Search(ref); err != nil { glog.Errorf("Unable to search events for '%#v': %v", node, err) } } if nodeEventList != nil { nodeEvents = genEvents(nodeEventList) } var events []page.Event var eventList *api.EventList if eventList, err = kubeclient.Get().Events("").List(labels.Everything(), fields.Everything()); err != nil { glog.Errorf("Unable to search events for '%#v': %v", node, err) } if eventList != nil { events = genEvents(&api.EventList{Items: kube.FilterEventsFromNode(eventList.Items, node)}) } c.HTML(http.StatusOK, "nodeDetail", gin.H{ "title": nodename, "node": d, "pods": pods, "events": events, "nodeEvents": nodeEvents, }) }