io.kubernetes.client.openapi.models.V1NodeAddress Java Examples

The following examples show how to use io.kubernetes.client.openapi.models.V1NodeAddress. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: V1NodeStatus.java    From java with Apache License 2.0 5 votes vote down vote up
public V1NodeStatus addAddressesItem(V1NodeAddress addressesItem) {
  if (this.addresses == null) {
    this.addresses = new ArrayList<V1NodeAddress>();
  }
  this.addresses.add(addressesItem);
  return this;
}
 
Example #2
Source File: V1NodeStatus.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * List of addresses reachable to the node. Queried from cloud provider, if available. More info: https://kubernetes.io/docs/concepts/nodes/node/#addresses Note: This field is declared as mergeable, but the merge key is not sufficiently unique, which can cause data corruption when it is merged. Callers should instead use a full-replacement patch. See http://pr.k8s.io/79391 for an example.
 * @return addresses
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "List of addresses reachable to the node. Queried from cloud provider, if available. More info: https://kubernetes.io/docs/concepts/nodes/node/#addresses Note: This field is declared as mergeable, but the merge key is not sufficiently unique, which can cause data corruption when it is merged. Callers should instead use a full-replacement patch. See http://pr.k8s.io/79391 for an example.")

public List<V1NodeAddress> getAddresses() {
  return addresses;
}
 
Example #3
Source File: KubeUtil.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public static Optional<String> getNodeIpV4Address(V1Node node) {
    return Optional.ofNullable(node.getStatus().getAddresses())
            .map(Collection::stream)
            .orElseGet(Stream::empty)
            .filter(a -> a.getType().equalsIgnoreCase(TYPE_INTERNAL_IP) && NetworkExt.isIpV4(a.getAddress()))
            .findFirst()
            .map(V1NodeAddress::getAddress);
}
 
Example #4
Source File: V1NodeStatus.java    From java with Apache License 2.0 4 votes vote down vote up
public void setAddresses(List<V1NodeAddress> addresses) {
  this.addresses = addresses;
}
 
Example #5
Source File: KubernetesController.java    From twister2 with Apache License 2.0 4 votes vote down vote up
/**
 * get NodeInfoUtils objects for the nodes on this cluster
 *
 * @return the NodeInfoUtils object list. If it can not get the list from K8s master, return null.
 */
public ArrayList<JobMasterAPI.NodeInfo> getNodeInfo(String rackLabelKey,
                                                    String datacenterLabelKey) {

  V1NodeList nodeList = null;
  try {
    nodeList = coreApi.listNode(null, null, null, null, null, null, null, null, null);
  } catch (ApiException e) {
    LOG.log(Level.SEVERE, "Exception when getting NodeList.", e);
    return null;
  }

  ArrayList<JobMasterAPI.NodeInfo> nodeInfoList = new ArrayList<>();
  for (V1Node node : nodeList.getItems()) {
    List<V1NodeAddress> addressList = node.getStatus().getAddresses();
    for (V1NodeAddress nodeAddress : addressList) {
      if ("InternalIP".equalsIgnoreCase(nodeAddress.getType())) {
        String nodeIP = nodeAddress.getAddress();
        String rackName = null;
        String datacenterName = null;

        // get labels
        Map<String, String> labelMap = node.getMetadata().getLabels();
        for (String key : labelMap.keySet()) {
          if (key.equalsIgnoreCase(rackLabelKey)) {
            rackName = labelMap.get(key);
          }
          if (key.equalsIgnoreCase(datacenterLabelKey)) {
            datacenterName = labelMap.get(key);
          }
        }

        JobMasterAPI.NodeInfo nodeInfo =
            NodeInfoUtils.createNodeInfo(nodeIP, rackName, datacenterName);
        nodeInfoList.add(nodeInfo);
        break;
      }
    }
  }

  return nodeInfoList;
}
 
Example #6
Source File: KubeNotificationProcessorTest.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
@Test
public void testUpdateTaskStatus() {
    V1Pod pod = new V1Pod()
            .metadata(new V1ObjectMeta()
                    .name(TASK.getId())
            )
            .status(new V1PodStatus()
                    .addContainerStatusesItem(new V1ContainerStatus()
                            .containerID(TASK.getId())
                            .state(new V1ContainerState()
                                    .running(new V1ContainerStateRunning().startedAt(DateTime.now()))
                            )
                    )
            );
    V1Node node = new V1Node()
            .metadata(new V1ObjectMeta()
                    .annotations(Collections.singletonMap(
                            TITUS_NODE_DOMAIN + "ami", "ami123"
                    ))
            )
            .status(new V1NodeStatus()
                    .addresses(Collections.singletonList(
                            new V1NodeAddress().address("2.2.2.2").type(KubeUtil.TYPE_INTERNAL_IP)
                    ))
            );
    Task updatedTask = KubeNotificationProcessor.updateTaskStatus(
            new PodWrapper(pod),
            TaskState.Started,
            Optional.of(new TitusExecutorDetails(Collections.emptyMap(), new TitusExecutorDetails.NetworkConfiguration(
                    true,
                    "1.2.3.4",
                    "",
                    "1.2.3.4",
                    "eniId123",
                    "resourceId123"
            ))),
            Optional.of(node),
            TASK
    );

    Set<TaskState> pastStates = updatedTask.getStatusHistory().stream().map(ExecutableStatus::getState).collect(Collectors.toSet());
    assertThat(pastStates).contains(TaskState.Accepted, TaskState.Launched, TaskState.StartInitiated);
    assertThat(updatedTask.getTaskContext()).containsEntry(TaskAttributes.TASK_ATTRIBUTES_AGENT_HOST, "2.2.2.2");
    assertThat(updatedTask.getTaskContext()).containsEntry(TaskAttributes.TASK_ATTRIBUTES_CONTAINER_IP, "1.2.3.4");
    assertThat(updatedTask.getTaskContext()).containsEntry(TaskAttributes.TASK_ATTRIBUTES_AGENT_AMI, "ami123");
}