generateNonTerminatedPodsTable()

in client/src/components/cluster/ClusterNodePods.js [134:259]


  generateNonTerminatedPodsTable(node, isLoading) {
    const columns = [
      {
        dataIndex: 'name',
        key: 'name',
        title: 'Name',
        render: (text, record) => record.isContainer
          ? (<span><span className={classNames(styles.podContainerIndicator, 'cp-tag')}>CONTAINER</span>{text}</span>)
          : text
      },
      {
        dataIndex: 'namespace',
        key: 'namespace',
        title: 'Namespace'
      },
      {
        dataIndex: 'status',
        key: 'status',
        title: 'Status',
        render: this.statusRenderer
      }
    ];
    const dataSource = [];
    const keys = [];

    for (let i = 0; i < node.pods.length; i++) {
      for (let j = 0; j < node.pods[i].containers.length; j++) {
        const container = node.pods[i].containers[j];
        if (container.requests) {
          for (let key in container.requests) {
            if (container.requests.hasOwnProperty(key) && keys.indexOf(key) === -1) {
              keys.push(key);
            }
          }
        }
        if (container.limits) {
          for (let key in container.limits) {
            if (container.limits.hasOwnProperty(key) && keys.indexOf(key) === -1) {
              keys.push(key);
            }
          }
        }
      }
    }

    if (keys.length > 0) {
      const requestsColumn = {
        title: 'Requests',
        children: keys.map(k => {
          return {
            dataIndex: `requests.${k}`,
            key: `requests.${k}`,
            title: k.toUpperCase()
          };
        })
      };
      const limitsColumn = {
        title: 'Limits',
        children: keys.map(k => {
          return {
            dataIndex: `limits.${k}`,
            key: `limits.${k}`,
            title: k.toUpperCase()
          };
        })
      };
      columns.push(requestsColumn);
      columns.push(limitsColumn);
    }

    for (let i = 0; i < node.pods.length; i++) {
      const pod = {
        name: node.pods[i].name,
        namespace: node.pods[i].namespace,
        status: node.pods[i].phase,
        uid: node.pods[i].uid
      };
      const containers = [];
      for (let j = 0; j < node.pods[i].containers.length; j++) {
        const container = node.pods[i].containers[j];
        containers.push({
          name: container.name,
          isContainer: true,
          requests: container.requests,
          limits: container.limits,
          uid: `${pod.uid}-${j}`,
          status: container.status
        });
      }
      const podRequests = {};
      const podLimits = {};
      for (let k = 0; k < keys.length; k++) {
        const req = this.summarize(keys[k], containers.map(c => c.requests));
        if (req) {
          podRequests[keys[k]] = req;
        }
        const lim = this.summarize(keys[k], containers.map(c => c.limits));
        if (lim) {
          podLimits[keys[k]] = lim;
        }
      }
      if (containers.length === 1) {
        pod.children = containers;
        pod.requests = containers[0].requests;
        pod.limits = containers[0].limits;
      } else if (containers.length > 0) {
        pod.children = containers;
        pod.requests = podRequests;
        pod.limits = podLimits;
      }
      dataSource.push(pod);
    }
    return (
      <Table
        className={styles.table}
        columns={columns}
        dataSource={dataSource}
        rowKey="uid"
        loading={isLoading}
        pagination={{pageSize: 20}}
        bordered
        rowClassName={(row, index) => index % 2 === 0 ? '' : 'cp-cluster-node-even-row'}
        size="small"
      />
    );
  }