func (t *NodesTable) Generate(ctx context.Context, queryContext table.QueryContext) ([]map[string]string, error) {
	nodes, err := t.client.CoreV1().Nodes().List(metav1.ListOptions{})
	if err != nil {
		log.Println("could not list nodes from k8s api")
		return nil, err
	}

	rows := make([]map[string]string, len(nodes.Items))
	for i, node := range nodes.Items {
		currRow := map[string]string{
			"name":            node.Status.NodeInfo.BootID,
			"kernel_version":  node.Status.NodeInfo.KernelVersion,
			"kubelet_version": node.Status.NodeInfo.KubeletVersion,
			"role":            "slave", // default to slave, unless decided master
		}

		// checking if it's a master node
		if _, hasMasterRoleLabel := node.ObjectMeta.Labels["node-role.kubernetes.io/master"]; hasMasterRoleLabel {
			currRow["role"] = "master"
		}

		// setting addresses
		for _, address := range node.Status.Addresses {
			if address.Type == corev1.NodeHostName {
				currRow["name"] = address.Address
			} else if address.Type == corev1.NodeExternalIP {
				currRow["external_ip"] = address.Address
			}
		}

		// if nodename exists, we extract metrics using the name
		if nodename := currRow["name"]; nodename != "" {
			nodemetric, err := t.metricsClient.MetricsV1beta1().NodeMetricses().Get(nodename, metav1.GetOptions{})
			if err == nil {
				// nodemetric.Usage is of type *resource.Quantity. from:
				// https://github.com/kubernetes/apimachinery/blob/master/pkg/api/resource/quantity.go
				if cpu, ok := nodemetric.Usage[corev1.ResourceCPU]; ok {
					currRow["cpu_usage"] = cpu.String()
				}
				if memory, ok := nodemetric.Usage[corev1.ResourceMemory]; ok {
					currRow["memory_usage"] = memory.String()
				}
			}
		}

		rows[i] = currRow
	}
	return rows, nil
}
// Generate uses the api to retrieve information on all pods
Generate uses the api to retrieve information on all pods
// Generate uses the api to retrieve information on all pods
func (t *NodesTable) Generate(ctx context.Context, queryContext table.QueryContext) ([]map[string]string, error) {
	nodes, err := t.client.CoreV1().Nodes().List(metav1.ListOptions{})
	if err != nil {
		log.Println("could not list nodes from k8s api")
		return nil, err
	}
	rows := make([]map[string]string, len(nodes.Items))
	for i, node := range nodes.Items {
		currRow := map[string]string{
			"name":            node.Status.NodeInfo.BootID,
			"kernel_version":  node.Status.NodeInfo.KernelVersion,
			"kubelet_version": node.Status.NodeInfo.KubeletVersion,
			"role":            "slave", 
		}
		if _, hasMasterRoleLabel := node.ObjectMeta.Labels["node-role.kubernetes.io/master"]; hasMasterRoleLabel {
			currRow["role"] = "master"
		}
		for _, address := range node.Status.Addresses {
			if address.Type == corev1.NodeHostName {
				currRow["name"] = address.Address
			} else if address.Type == corev1.NodeExternalIP {
				currRow["external_ip"] = address.Address
			}
		}
		if nodename := currRow["name"]; nodename != "" {
			nodemetric, err := t.metricsClient.MetricsV1beta1().NodeMetricses().Get(nodename, metav1.GetOptions{})
			if err == nil {
				if cpu, ok := nodemetric.Usage[corev1.ResourceCPU]; ok {
					currRow["cpu_usage"] = cpu.String()
				}
				if memory, ok := nodemetric.Usage[corev1.ResourceMemory]; ok {
					currRow["memory_usage"] = memory.String()
				}
			}
		}
		rows[i] = currRow
	}
	return rows, nil
}
func ( t * NodesTable ) Generate ( ctx context . Context , queryContext table . QueryContext ) ( [ ] map [ string ] string , error ) { nodes , err := t . client . CoreV1 ( ) . Nodes ( ) . List ( metav1 . ListOptions { } ) if err != nil { log . Println ( " " ) return nil , err } rows := make ( [ ] map [ string ] string , len ( nodes . Items ) ) for i , node := range nodes . Items { currRow := map [ string ] string { " " : node . Status . NodeInfo . BootID , " " : node . Status . NodeInfo . KernelVersion , " " : node . Status . NodeInfo . KubeletVersion , " " : " " , } if _ , hasMasterRoleLabel := node . ObjectMeta . Labels [ " " ] ; hasMasterRoleLabel { currRow [ " " ] = " " } for _ , address := range node . Status . Addresses { if address . Type == corev1 . NodeHostName { currRow [ " " ] = address . Address } else if address . Type == corev1 . NodeExternalIP { currRow [ " " ] = address . Address } } if nodename := currRow [ " " ] ; nodename != " " { nodemetric , err := t . metricsClient . MetricsV1beta1 ( ) . NodeMetricses ( ) . Get ( nodename , metav1 . GetOptions { } ) if err == nil { if cpu , ok := nodemetric . Usage [ corev1 . ResourceCPU ] ; ok { currRow [ " " ] = cpu . String ( ) } if memory , ok := nodemetric . Usage [ corev1 . ResourceMemory ] ; ok { currRow [ " " ] = memory . String ( ) } } } rows [ i ] = currRow } return rows , nil }
Generate uses the api to retrieve information on all pods
Generate uses the api to retrieve information on all pods
// default to slave, unless decided master // checking if it's a master node // setting addresses // if nodename exists, we extract metrics using the name // nodemetric.Usage is of type *resource.Quantity. from: // https://github.com/kubernetes/apimachinery/blob/master/pkg/api/resource/quantity.go