public List<String> getServices(Predicate<Service> filter) { return kubernetesClientServicesFunction.apply(client).list() .getItems() .stream() .filter(filter) .map(s -> s.getMetadata().getName()) .collect(Collectors.toList()); }
@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); } } }
String containerName = createdPod.getMetadata() == null ? containerIdPrefix : createdPod.getMetadata().getName(); return new ContainerCreationStatus(true, containerName, containerName, nodePort);
@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); } } }
containerId = pod.getMetadata().getName(); currentPod = pod; break;
public KubernetesClientTimeoutException(HasMetadata resource, long amount, TimeUnit timeUnit) { super(String.format(RESOURCE_FORMAT, timeUnit.toMillis(amount), resource.getKind(), resource.getMetadata().getName(), resource.getMetadata().getNamespace())); this.resourcesNotReady = Collections.unmodifiableList(Arrays.asList(resource)); }
new DefaultIsServicePortSecureResolver.Input( endpointPort.getPort(), service.getMetadata().getName(), service.getMetadata().getLabels(), service.getMetadata().getAnnotations()
protected static String name(CustomResourceDefinition crd) { return crd.getMetadata().getName(); }
@Override public void run() { LOG.debug("Only {}/{} pod(s) ready for {}: {} in namespace: {} seconds so waiting...", podCount.get(), requiredPodCount, obj.getKind(), obj.getMetadata().getName(), namespace); } }, 0, loggingIntervalMillis, TimeUnit.MILLISECONDS);
@Override public void eventReceived(Action action, BuildConfig resource) { System.out.println(">> Action: " + action + " on BuildConfig " + resource.getMetadata().getName() + " with version: " + resource.getApiVersion()); }
@Override public List<String> getServices() { return client.services().list() .getItems() .stream().map(s -> s.getMetadata().getName()) .collect(Collectors.toList()); } }
public String getURL(String portName) { String clusterIP = getMandatory().getSpec().getClusterIP(); if("None".equals(clusterIP)) { throw new IllegalStateException("Service: " + getMandatory().getMetadata().getName() + " in namespace " + namespace + " is head-less. Search for endpoints instead"); } return getUrlHelper(portName); }
@Override public void eventReceived(Action action, Pod aPod) { log(aPod.getMetadata().getName(), aPod.getStatus().getPhase()); if(aPod.getStatus().getPhase().equals("Succeeded")) { log("Logs -> ", client.pods().inNamespace(namespace).withName(aPod.getMetadata().getName()).getLog()); watchLatch.countDown(); } }
@Override public String getURL(Service service, String portName, String namespace, KubernetesClient client) { ServicePort port = URLFromServiceUtil.getServicePortByName(service, portName); String serviceName = service.getMetadata().getName(); if(port == null) { throw new RuntimeException("Couldn't find port: " + portName + " for service " + service.getMetadata().getName()); } IngressList ingresses = client.extensions().ingresses().inNamespace(namespace).list(); if(ingresses != null && !ingresses.getItems().isEmpty()) { return URLFromServiceUtil.getURLFromIngressList(ingresses.getItems(), namespace, serviceName, port); } return null; }
public static boolean isEndpointsReady(Endpoints e) { Utils.checkNotNull(e, "Endpoints can't be null."); String name = e.getMetadata().getName(); Utils.checkNotNull(name, "Endpoints name can't be null."); if (e.getSubsets() == null) { return false; } for (EndpointSubset subset : e.getSubsets()) { if(!subset.getAddresses().isEmpty() && !subset.getPorts().isEmpty()) { return true; } } return false; }
protected <T> String checkName(T item) { String operationName = getName(); String itemName = item instanceof HasMetadata ? ((HasMetadata) item).getMetadata().getName() : null; if (Utils.isNullOrEmpty(operationName) && Utils.isNullOrEmpty(itemName)) { return null; } else if (Utils.isNullOrEmpty(itemName)) { return operationName; } else if (Utils.isNullOrEmpty(operationName)) { return itemName; } else if (itemName.equals(operationName)) { return itemName; } throw new KubernetesClientException("Name mismatch. Item name:" + itemName + ". Operation name:" + operationName + "."); }
@Test public void testUnmarshalJSONTemplate() throws IOException { Template t = new OperationSupport().unmarshal(getClass().getResourceAsStream("/test-template.json"), Template.class); assertEquals("eap6-basic-sti", t.getMetadata().getName()); }
@Test public void testUnmarshalYAMLTemplate() throws IOException { Template t = new OperationSupport().unmarshal(getClass().getResourceAsStream("/test-template.yml"), Template.class); assertEquals("eap6-basic-sti", t.getMetadata().getName()); }
@Test public void testShowCurrentUser() throws Exception { OpenShiftClient client = new DefaultOpenShiftClient(); User user = client.currentUser(); System.out.println("Current user is: " + user); assertNotNull(user); ObjectMeta metadata = user.getMetadata(); assertNotNull(metadata); String name = metadata.getName(); System.out.println("User name is: " + name); assertNotNull(name); }