Refine search
public void start() { if (watch == null) { synchronized (lock) { if (watch == null) { LOGGER.debug("Starting leader record watcher"); watch = kubernetesClient .configMaps() .inNamespace(leaderProperties.getNamespace(kubernetesClient.getNamespace())) .withName(leaderProperties.getConfigMapName()) .watch(this); } } } }
private static Map<String, String> getData(KubernetesClient client, String name, String namespace, String[] profiles) { try { ConfigMap map = StringUtils.isEmpty(namespace) ? client.configMaps().withName(name).get() : client.configMaps().inNamespace(namespace).withName(name).get(); if (map != null) { return processAllEntries(map.getData(), profiles); } } catch (Exception e) { LOG.warn("Can't read configMap with name: [" + name + "] in namespace:[" + namespace + "]. Ignoring"); } return new HashMap<>(); }
private ConfigMap getConfigMap() { return kubernetesClient.configMaps() .inNamespace(leaderProperties.getNamespace(kubernetesClient.getNamespace())) .withName(leaderProperties.getConfigMapName()) .get(); }
private void updateConfigMap(ConfigMap oldConfigMap, ConfigMap newConfigMap) { kubernetesClient.configMaps() .inNamespace(leaderProperties.getNamespace(kubernetesClient.getNamespace())) .withName(leaderProperties.getConfigMapName()) .lockResourceVersion(oldConfigMap.getMetadata().getResourceVersion()) .replace(newConfigMap); } }
public List<Server> getUpdatedListOfServers() { Endpoints endpoints = namespace != null ? client.endpoints().inNamespace(namespace).withName(serviceId).get() : client.endpoints().withName(serviceId).get();
secret = client.secrets().inNamespace(namespace).withName(name).get(); client.secrets().inNamespace(namespace) .withLabels(config.getLabels()).list().getItems() .forEach(s -> putAll(s, result));
private static List<ServiceInstance> getInstances(KubernetesClient client, String name, String namespace) { Assert.notNull(name, "[Assertion failed] - the service name must not be null"); return Optional.ofNullable(client.endpoints().inNamespace(namespace).withName(name).get()) .orElse(new Endpoints()) .getSubsets() .stream() .flatMap(s -> s.getAddresses().stream().map(a -> (ServiceInstance) new KubernetesServiceInstance(name, a ,s.getPorts().stream().findFirst().orElseThrow(IllegalStateException::new), false))) .collect(Collectors.toList()); }
private static Map<String, String> getData(KubernetesClient client, String name, String namespace) { Map<String, String> result = new HashMap<>(); try { ConfigMap map = namespace == null || namespace.isEmpty() ? client.configMaps().withName(name).get() : client.configMaps().inNamespace(namespace).withName(name).get(); if (map != null) { for (Map.Entry<String, String> entry : map.getData().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (key.equals(APPLICATION_YAML) || key.equals(APPLICATION_YML)) { result.putAll(YAML_TO_PROPETIES.andThen(PROPERTIES_TO_MAP).apply(value)); } else if (key.equals(APPLICATION_PROPERTIES)) { result.putAll(KEY_VALUE_TO_PROPERTIES.andThen(PROPERTIES_TO_MAP).apply(value)); } else { result.put(key, value); } } } } catch (Exception e) { LOGGER.warn("Can't read configMap with name: [" + name + "] in namespace:[" + namespace + "]. Ignoring"); } return result; }
public void start() { ConfigMap map = Strings.isNullOrEmpty(namespace) ? client.configMaps().withName(name).get() : client.configMaps().inNamespace(namespace).withName(name).get(); if (map != null) { currentData.set(asObjectMap(map.getData())); } watch = Strings.isNullOrEmpty(namespace) ? client.configMaps().withName(name).watch(watcher) : client.configMaps().inNamespace(namespace).withName(namespace).watch(watcher); started.set(true); }
Config config = new ConfigBuilder().build(); try (final KubernetesClient client = new DefaultKubernetesClient(config)) { try (Watch watch = client.replicationControllers().inNamespace("default").withName("test").watch(new Watcher<ReplicationController>() { @Override public void eventReceived(Action action, ReplicationController resource) {
public static void main(String[] args) { if (args.length < 1) { System.out.println("Usage: podName [master] [namespace]"); return; } String podName = args[0]; String namespace = "default"; String master = "https://localhost:8443/"; if (args.length > 1) { master = args[1]; } if (args.length > 2) { namespace = args[2]; } System.out.println("Log of pod " + podName + " in " + namespace + " is:"); System.out.println("----------------------------------------------------------------"); Config config = new ConfigBuilder().withMasterUrl(master).build(); try (KubernetesClient client = new DefaultKubernetesClient(config); LogWatch watch = client.pods().inNamespace(namespace).withName(podName).tailingLines(10).watchLog(System.out)) { Thread.sleep(5 * 1000); } catch (Exception e) { logger.error(e.getMessage(), e); } } }
@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(); } }
public List<Server> getUpdatedListOfServers() { Endpoints endpoints = namespace != null ? client.endpoints().inNamespace(namespace).withName(serviceId).get() : client.endpoints().withName(serviceId).get();
client.pods().inNamespace("test").withLabel("this", "works").list() ); client.pods().inNamespace("test").withName("testing").get() ); PodList podList = client.pods().inNamespace("myproject").list(5, null); podList.getItems().forEach((obj) -> { System.out.println(obj.getMetadata().getName()); });
public static void main(String[] args) throws InterruptedException { if (args.length < 1) { System.out.println("Usage: podName [master] [namespace]"); return; } String podName = args[0]; String namespace = "default"; String master = "https://localhost:8443/"; if (args.length > 1) { master = args[1]; } if (args.length > 2) { namespace = args[2]; } Config config = new ConfigBuilder().withMasterUrl(master).build(); try (final KubernetesClient client = new DefaultKubernetesClient(config); ExecWatch watch = client.pods().inNamespace(namespace).withName(podName) .readingInput(System.in) .writingOutput(System.out) .writingError(System.err) .withTTY() .usingListener(new SimpleListener()) .exec()){ Thread.sleep(10 * 1000); } }
putAll( client.secrets() .inNamespace(namespace) .withName(name) .get(), result); } else { client.secrets() .inNamespace(namespace) .withLabels(config.getLabels()) .list()
@Override public String getURL(Service service, String portName, String namespace, KubernetesClient client) { String serviceName = service.getMetadata().getName(); ServicePort port = URLFromServiceUtil.getServicePortByName(service, portName); if(port != null && port.getName() != null && isOpenShift(client)) { try { String serviceProtocol = port.getProtocol(); OpenShiftClient openShiftClient = client.adapt(OpenShiftClient.class); Route route = openShiftClient.routes().inNamespace(namespace).withName(service.getMetadata().getName()).get(); if (route != null) { return (serviceProtocol + "://" + route.getSpec().getHost()).toLowerCase(); } } catch (KubernetesClientException e) { if(e.getCode() == HttpURLConnection.HTTP_FORBIDDEN) { logger.warn("Could not lookup route:" + serviceName + " in namespace:"+ namespace +", due to: " + e.getMessage()); } } } return null; }
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(); } }
.inNamespace(namespace) .withName(name) .get();
.build(); log("Created ImageStream", client.imageStreams().inNamespace(namespace).create(imageStream)); log("First Tag is " + client.imageStreams().inNamespace(namespace).withName("slave-jenkins").get().getSpec().getTags().get(0).getName()); log("Second Tag is " + client.imageStreams().inNamespace(namespace).withName("slave-jenkins").get().getSpec().getTags().get(1).getName()); client.imageStreams().inNamespace(namespace).withName("slave-jenkins").delete(); client.close();