Refine search
public void start() { if (watch == null) { synchronized (lock) { if (watch == null) { LOGGER.debug("Starting pod readiness watcher for '{}'", podName); PodResource<Pod, DoneablePod> podResource = kubernetesClient .pods() .withName(podName); previousState = podResource.isReady(); watch = podResource.watch(this); } } } }
/*** * Delete pod by name * @param namespace * @param podName * @throws Exception */ public void deletePod(String namespace, String podName) { client.pods().inNamespace(namespace).withName(podName).delete(); log.info("Pod {} removed", podName); }
/*** * Returns log of conrainer in pod * @param podName name of pod * @param containerName name of container in pod * @return log */ public String getLog(String podName, String containerName) { return client.pods().inNamespace(globalNamespace).withName(podName).inContainer(containerName).getLog(); }
client.namespaces().list() ); client.namespaces().withLabel("this", "works").list() ); client.pods().withLabel("this", "works").list() ); client.pods().inNamespace("test").withLabel("this", "works").list() ); client.pods().inNamespace("test").withName("testing").get() );
public static void main(String[] args) { String master = "https://localhost:8443/"; if (args.length == 1) { master = args[0]; } Config config = new ConfigBuilder().withMasterUrl(master).build(); KubernetesClient client = new DefaultKubernetesClient(config); try { log("Create namespace:", client.namespaces().create(new NamespaceBuilder().withNewMetadata().withName("thisisatest").endMetadata().build())); log("Deleted namespace:", client.namespaces().withName("test").delete()); log("Deleted testPod:", client.pods().inNamespace("thisisatest").withName("testpod").delete()); log("Deleted pod by label:", client.pods().withLabel("this", "works").delete()); } catch (KubernetesClientException e) { logger.error(e.getMessage(), e); } finally { client.namespaces().withName("thisisatest").delete(); client.close(); } }
String namespace = StringUtils.defaultIfBlank(slave.getNamespace(), client.getNamespace()); pod = client.pods().inNamespace(namespace).create(pod); LOGGER.log(INFO, "Created Pod: {0} in namespace {1}", new Object[]{podId, namespace}); logger.printf("Created Pod: %s in namespace %s%n", podId, namespace); pod = client.pods().inNamespace(namespace).withName(podId).get(); if (pod == null) { throw new IllegalStateException("Pod no longer exists: " + podId);
@Override Pod applyResource(Pod original, Pod current) { return client .pods() .inNamespace(getNamespace()) .withName(current.getMetadata().getName()) .edit() .withMetadata(current.getMetadata()) .withSpec(current.getSpec()) .done(); }
Service service = client.services().inNamespace(session.getNamespace()).withName(serviceName).get(); if (service != null) { return jolokiaClients.clientForService(service); Pod pod = client.pods().inNamespace(session.getNamespace()).withName(serviceName).get(); if (pod != null) { return jolokiaClients.clientForPod(pod); ReplicationController replicationController = client.replicationControllers().inNamespace(session.getNamespace()).withName(replicationControllerName).get(); if (replicationController != null) { return jolokiaClients.clientForReplicationController(replicationController);
try (KubernetesClient client = new DefaultKubernetesClient(config)) { try { log("Create namespace:", client.namespaces().create(new NamespaceBuilder().withNewMetadata().withName("thisisatest").endMetadata().build())); Pod createdPod = client.pods().inNamespace("thisisatest").createNew() .withNewMetadata() .withName("testpod") log("Created testPod:", createdPod); Pod updatedPod = client.pods().inNamespace("thisisatest").withName("testpod").edit() .editMetadata() .addToLabels("server2", "nginx2")
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; } }
String namespace = "default"; log("namespace", namespace); Pod pod = client.pods().inNamespace(namespace).load(PodPresetExamples.class.getResourceAsStream("/pod-preset-example.yml")).get(); log("Pod created"); client.pods().inNamespace(namespace).create(pod); client.settings().podPresets().inNamespace(namespace).create(podPreset); pod = client.pods().inNamespace(namespace).withName(pod.getMetadata().getName()).get(); log("Updated pod: "); log(SerializationUtils.dumpAsYaml(pod));
closeLogWatcher(); PodResource<Pod, DoneablePod> podResource = kubernetes.pods().inNamespace(namespace).withName(name); List<Container> containers = KubernetesHelper.getContainers(pod); String containerName = null; logWatchTerminateLatch = new CountDownLatch(1); if (containers.size() < 2) { logWatcher = podResource.watchLog(); } else { containerName = getLogContainerName(containers); logWatcher = podResource.inContainer(containerName).watchLog(); String logText; if (containers.size() < 2) { logText = podResource.getLog(); } else { containerName = getLogContainerName(containers); logText = podResource.inContainer(containerName).getLog();
public LogWatch watchPodLog(String name, String container, OutputStream outputStream) { return client.pods().withName(name).inContainer(container).watchLog(outputStream); }
@Override /** * Remove the template after step is done */ protected void finished(StepContext context) throws Exception { Cloud cloud = Jenkins.getInstance().getCloud(cloudName); if (cloud == null) { LOGGER.log(Level.WARNING, "Cloud {0} no longer exists, cannot delete pod template {1}", new Object[] { cloudName, podTemplate.getName() }); return; } if (cloud instanceof KubernetesCloud) { LOGGER.log(Level.INFO, "Removing pod template and deleting pod {1} from cloud {0}", new Object[] { cloud.name, podTemplate.getName() }); KubernetesCloud kubernetesCloud = (KubernetesCloud) cloud; kubernetesCloud.removeDynamicTemplate(podTemplate); KubernetesClient client = kubernetesCloud.connect(); Boolean deleted = client.pods().withName(podTemplate.getName()).delete(); if (!Boolean.TRUE.equals(deleted)) { LOGGER.log(Level.WARNING, "Failed to delete pod for agent {0}/{1}: not found", new String[] { client.getNamespace(), podTemplate.getName() }); return; } } else { LOGGER.log(Level.WARNING, "Cloud is not a KubernetesCloud: {0} {1}", new String[] { cloud.name, cloud.getClass().getName() }); } } }
pods().inNamespace(namespace).withName(pod.getMetadata().getName()) .edit() .editMetadata().addToLabels(DEPLOYMENT_KEY, oldDeploymentHash) .and().done(); D editable = resources().inNamespace(namespace).withName(oldName).cascading(false).edit(); updateDeploymentKey(editable, oldDeploymentHash); oldObj = editable.done(); T createdObj = resources().inNamespace(namespace).create(clonedObj);
/** * Watch the pod identified by the given {@code namespace} and {@code name} using the given {@code watcher}. * @param namespace The namespace * @param name The name * @param watcher The watcher * @return The watch */ public Watch watch(String namespace, String name, Watcher<Pod> watcher) { return operation().inNamespace(namespace).withName(name).watch(watcher); } }
public Watch watch(final String podName, AtomicBoolean alive, CountDownLatch started, CountDownLatch finished, Boolean cleanUpOnFinish) { Callable<Void> onCompletion = cleanUpOnFinish ? new Callable<Void>() { @Override public Void call() throws Exception { cleanUp(); return null; } } : null; Watch watch = client.pods().withName(podName).watch(new PodWatcher(alive, started, finished, onCompletion)); synchronized (closeables) { closeables.add(watch); } return watch; }