@Override public void contribute(Builder builder) { try { Pod current = utils.currentPod().get(); Map<String, Object> details = new HashMap<>(); if (current != null) { details.put("inside", true); details.put("namespace", current.getMetadata().getNamespace()); details.put("podName", current.getMetadata().getName()); details.put("podIp", current.getStatus().getPodIP()); details.put("serviceAccount", current.getSpec().getServiceAccountName()); details.put("nodeName", current.getSpec().getNodeName()); details.put("hostIp", current.getStatus().getHostIP()); } else { details.put("inside", false); } builder.withDetail("kubernetes", details); } catch (Exception e) { LOG.warn("Failed to get pod details", e); } } }
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { try { Pod current = utils.currentPod().get(); if (current != null) { builder.up().withDetail("inside", true) .withDetail("namespace", current.getMetadata().getNamespace()) .withDetail("podName", current.getMetadata().getName()) .withDetail("podIp", current.getStatus().getPodIP()) .withDetail("serviceAccount", current.getSpec().getServiceAccountName()) .withDetail("nodeName", current.getSpec().getNodeName()) .withDetail("hostIp", current.getStatus().getHostIP()); } else { builder.up().withDetail("inside", false); } } catch (Exception e) { builder.down(e); } } }
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { try { Pod current = utils.currentPod().get(); if (current != null) { builder.up() .withDetail("inside", true) .withDetail("namespace", current.getMetadata().getNamespace()) .withDetail("podName", current.getMetadata().getName()) .withDetail("podIp", current.getStatus().getPodIP()) .withDetail("serviceAccount", current.getSpec().getServiceAccountName()) .withDetail("nodeName", current.getSpec().getNodeName()) .withDetail("hostIp", current.getStatus().getHostIP()); } else { builder.up() .withDetail("inside", false); } } catch (Exception e) { builder.down(e); } } }
@Override public void contribute(Builder builder) { try { Pod current = utils.currentPod().get(); Map<String, Object> details = new HashMap<>(); if (current != null) { details.put("inside", true); details.put("namespace", current.getMetadata().getNamespace()); details.put("podName", current.getMetadata().getName()); details.put("podIp", current.getStatus().getPodIP()); details.put("serviceAccount", current.getSpec().getServiceAccountName()); details.put("nodeName", current.getSpec().getNodeName()); details.put("hostIp", current.getStatus().getHostIP()); } else { details.put("inside", false); } builder.withDetail("kubernetes", details); } catch (Exception e) { LOG.warn("Failed to get pod details", e); } } }
private Node getNodeOfPod(String podName) { Node node; if (Utils.isNullOrEmpty(podName)) { LOGGER.warning("Failed to find the current pod name."); return null; } Pod pod = client.pods().withName(podName).get(); if (pod == null) { LOGGER.warning("Failed to find pod with name:" + podName + " in namespace:" + client.getNamespace() + "."); node = null; } else { String nodeName = pod.getSpec().getNodeName(); node = client.nodes().withName(nodeName).get(); } if (node == null) { LOGGER.warning("Failed to find pod with name:" + podName + "."); return null; } else { return node; } }
protected LocationSpec<KubernetesSshMachineLocation> prepareSshableLocationSpec(Entity entity, ConfigBag setup, Namespace namespace, String deploymentName, Service service, Pod pod) { InetAddress node = Networking.getInetAddressWithFixedName(pod.getSpec().getNodeName()); String podAddress = pod.getStatus().getPodIP(); LocationSpec<KubernetesSshMachineLocation> locationSpec = LocationSpec.create(KubernetesSshMachineLocation.class) .configure("address", node) .configure(SshMachineLocation.PRIVATE_ADDRESSES, ImmutableSet.of(podAddress)) .configure(CALLER_CONTEXT, setup.get(CALLER_CONTEXT)); if (!isDockerContainer(entity)) { Optional<ServicePort> sshPort = Iterables.tryFind(service.getSpec().getPorts(), new Predicate<ServicePort>() { @Override public boolean apply(ServicePort input) { return input.getProtocol().equalsIgnoreCase("TCP") && input.getPort().intValue() == 22; } }); Optional<Integer> sshPortNumber; if (sshPort.isPresent()) { sshPortNumber = Optional.of(sshPort.get().getNodePort()); } else { LOG.warn("No port-mapping found to ssh port 22, for container {}", service); sshPortNumber = Optional.absent(); } locationSpec.configure(CloudLocationConfig.USER, setup.get(KubernetesLocationConfig.LOGIN_USER)) .configure(SshMachineLocation.PASSWORD, setup.get(KubernetesLocationConfig.LOGIN_USER_PASSWORD)) .configureIfNotNull(SshMachineLocation.SSH_PORT, sshPortNumber.orNull()) .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true) .configure(BrooklynConfigKeys.ONBOX_BASE_DIR, "/tmp"); } return locationSpec; }
entity.sensors().set(KubernetesPod.KUBERNETES_POD, pod.getMetadata().getName()); InetAddress node = Networking.getInetAddressWithFixedName(pod.getSpec().getNodeName()); String podAddress = pod.getStatus().getPodIP(); entity.sensors().set(KubernetesPod.KUBERNETES_POD, podName); InetAddress node = Networking.getInetAddressWithFixedName(pod.getSpec().getNodeName()); locationSpec.configure("address", node); } catch (KubernetesClientException kce) {
n.put("hostname", spec.getHostname()); n.put("hostPID", spec.getHostPID()); n.put("nodeName", spec.getNodeName()); n.put("schedulerName", spec.getSchedulerName()); n.put("serviceAccount", spec.getServiceAccount());
@Override protected boolean findResourceAddress(LocationSpec<? extends KubernetesMachineLocation> locationSpec, Entity entity, HasMetadata metadata, String resourceType, String resourceName, String namespace) { if (super.findResourceAddress(locationSpec, entity, metadata, resourceType, resourceName, namespace)) { return true; } if (resourceType.equals(OpenShiftResource.DEPLOYMENT_CONFIG)) { DeploymentConfig deploymentConfig = (DeploymentConfig) metadata; Map<String, String> labels = deploymentConfig.getSpec().getTemplate().getMetadata().getLabels(); Pod pod = getPod(namespace, labels); entity.sensors().set(OpenShiftPod.KUBERNETES_POD, pod.getMetadata().getName()); InetAddress node = Networking.getInetAddressWithFixedName(pod.getSpec().getNodeName()); String podAddress = pod.getStatus().getPodIP(); locationSpec.configure("address", node); locationSpec.configure(SshMachineLocation.PRIVATE_ADDRESSES, ImmutableSet.of(podAddress)); return true; } else { return false; } }
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { try { Pod current = utils.currentPod().get(); if (current != null) { builder.up() .withDetail("inside", true) .withDetail("podName", current.getMetadata().getName()) .withDetail("podIp", current.getStatus().getPodIP()) .withDetail("serviceAccount", current.getSpec().getServiceAccountName()) .withDetail("nodeName", current.getSpec().getNodeName()) .withDetail("hostIp", current.getStatus().getHostIP()); } else { builder.up() .withDetail("inside", false); } } catch (Exception e) { builder.down(e); } } }
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { try { Pod current = utils.currentPod().get(); if (current != null) { builder.up() .withDetail("inside", true) .withDetail("namespace", current.getMetadata().getNamespace()) .withDetail("podName", current.getMetadata().getName()) .withDetail("podIp", current.getStatus().getPodIP()) .withDetail("serviceAccount", current.getSpec().getServiceAccountName()) .withDetail("nodeName", current.getSpec().getNodeName()) .withDetail("hostIp", current.getStatus().getHostIP()); } else { builder.up() .withDetail("inside", false); } } catch (Exception e) { builder.down(e); } } }
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { try { Pod current = utils.currentPod().get(); if (current != null) { builder.up().withDetail("inside", true) .withDetail("namespace", current.getMetadata().getNamespace()) .withDetail("podName", current.getMetadata().getName()) .withDetail("podIp", current.getStatus().getPodIP()) .withDetail("serviceAccount", current.getSpec().getServiceAccountName()) .withDetail("nodeName", current.getSpec().getNodeName()) .withDetail("hostIp", current.getStatus().getHostIP()); } else { builder.up().withDetail("inside", false); } } catch (Exception e) { builder.down(e); } } }
public PodSpecBuilder(PodSpec instance,Boolean validationEnabled){ this.fluent = this; this.withActiveDeadlineSeconds(instance.getActiveDeadlineSeconds()); this.withContainers(instance.getContainers()); this.withDnsPolicy(instance.getDnsPolicy()); this.withHost(instance.getHost()); this.withHostIPC(instance.getHostIPC()); this.withHostNetwork(instance.getHostNetwork()); this.withHostPID(instance.getHostPID()); this.withHostname(instance.getHostname()); this.withImagePullSecrets(instance.getImagePullSecrets()); this.withNodeName(instance.getNodeName()); this.withNodeSelector(instance.getNodeSelector()); this.withRestartPolicy(instance.getRestartPolicy()); this.withSecurityContext(instance.getSecurityContext()); this.withServiceAccount(instance.getServiceAccount()); this.withServiceAccountName(instance.getServiceAccountName()); this.withSubdomain(instance.getSubdomain()); this.withTerminationGracePeriodSeconds(instance.getTerminationGracePeriodSeconds()); this.withVolumes(instance.getVolumes()); this.validationEnabled = validationEnabled; }
public PodSpecBuilder(PodSpecFluent<?> fluent,PodSpec instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withActiveDeadlineSeconds(instance.getActiveDeadlineSeconds()); fluent.withContainers(instance.getContainers()); fluent.withDnsPolicy(instance.getDnsPolicy()); fluent.withHost(instance.getHost()); fluent.withHostIPC(instance.getHostIPC()); fluent.withHostNetwork(instance.getHostNetwork()); fluent.withHostPID(instance.getHostPID()); fluent.withHostname(instance.getHostname()); fluent.withImagePullSecrets(instance.getImagePullSecrets()); fluent.withNodeName(instance.getNodeName()); fluent.withNodeSelector(instance.getNodeSelector()); fluent.withRestartPolicy(instance.getRestartPolicy()); fluent.withSecurityContext(instance.getSecurityContext()); fluent.withServiceAccount(instance.getServiceAccount()); fluent.withServiceAccountName(instance.getServiceAccountName()); fluent.withSubdomain(instance.getSubdomain()); fluent.withTerminationGracePeriodSeconds(instance.getTerminationGracePeriodSeconds()); fluent.withVolumes(instance.getVolumes()); this.validationEnabled = validationEnabled; } public PodSpecBuilder(PodSpec instance){
public PodSpecFluentImpl(PodSpec instance){ this.withActiveDeadlineSeconds(instance.getActiveDeadlineSeconds()); this.withContainers(instance.getContainers()); this.withDnsPolicy(instance.getDnsPolicy()); this.withHost(instance.getHost()); this.withHostIPC(instance.getHostIPC()); this.withHostNetwork(instance.getHostNetwork()); this.withHostPID(instance.getHostPID()); this.withHostname(instance.getHostname()); this.withImagePullSecrets(instance.getImagePullSecrets()); this.withNodeName(instance.getNodeName()); this.withNodeSelector(instance.getNodeSelector()); this.withRestartPolicy(instance.getRestartPolicy()); this.withSecurityContext(instance.getSecurityContext()); this.withServiceAccount(instance.getServiceAccount()); this.withServiceAccountName(instance.getServiceAccountName()); this.withSubdomain(instance.getSubdomain()); this.withTerminationGracePeriodSeconds(instance.getTerminationGracePeriodSeconds()); this.withVolumes(instance.getVolumes()); }