private void revoke(ConfigMap configMap) { LOGGER.debug("Trying to revoke leadership for '{}'", candidate); try { String leaderKey = getLeaderKey(); removeConfigMapEntry(configMap, leaderKey); handleLeaderChange(null); } catch (KubernetesClientException e) { LOGGER.warn("Failure when revoking leadership for '{}': {}", candidate, e.getMessage()); } }
private void acquire(ConfigMap configMap) { LOGGER.debug("Trying to acquire leadership for '{}'", candidate); if (!isPodReady(candidate.getId())) { LOGGER.debug("Pod of '{}' is not ready at the moment, cannot acquire leadership", candidate); return; } try { Map<String, String> data = getLeaderData(candidate); if (configMap == null) { createConfigMap(data); } else { updateConfigMapEntry(configMap, data); } Leader newLeader = new Leader(candidate.getRole(), candidate.getId()); handleLeaderChange(newLeader); } catch (KubernetesClientException e) { LOGGER.warn("Failure when acquiring leadership for '{}': {}", candidate, e.getMessage()); notifyOnFailedToAcquire(); } }
@Override public void onClose(KubernetesClientException e) { logger.debug("Watcher onClose"); if (e != null) { logger.error(e.getMessage(), e); closeLatch.countDown(); } } })) {
@Override public void onClose(KubernetesClientException e) { if (e != null) { e.printStackTrace(); logger.error(e.getMessage(), e); } } })) {
logger.error(e.getMessage(), e); } catch (Exception e) { logger.error(e.getMessage(), e);
public static void main(String[] args) { String master = "http://localhost:8080/"; if (args.length == 1) { master = args[0]; } io.fabric8.kubernetes.client.Config config = new io.fabric8.kubernetes.client.ConfigBuilder().withMasterUrl(master).build(); try (final KubernetesClient client = new DefaultKubernetesClient(config)) { StorageClassList storageClassList = client.storage().storageClasses().list(); logger.info(storageClassList.toString()); } catch (KubernetesClientException e) { logger.error(e.getMessage(), e); } } }
logger.error(e.getMessage(), e);
System.out.println(services); } catch (KubernetesClientException e) { logger.error(e.getMessage(), e);
@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; }
logger.error(e.getMessage(), e); } catch (Exception e) { logger.error(e.getMessage(), e);
@Override public void onClose(KubernetesClientException cause) { if (cause != null) { LOG.error(cause.getMessage(), cause); } } });
public static void main(String args[]) throws InterruptedException { String master = "https://192.168.99.100:8443/"; if (args.length == 1) { master = args[0]; } log("Using master with url ", master); Config config = new ConfigBuilder().withMasterUrl(master).build(); try (final KubernetesClient client = new DefaultKubernetesClient(config)) { final String namespace = "default"; PodDisruptionBudget podDisruptionBudget = new PodDisruptionBudgetBuilder() .withNewMetadata().withName("zk-pkb").endMetadata() .withNewSpec() .withMaxUnavailable(new IntOrString("1%")) .withNewSelector() .withMatchLabels(Collections.singletonMap("app", "zookeeper")) .endSelector() .endSpec() .build(); log("Current namespace is", namespace); client.policy().podDisruptionBudget().inNamespace(namespace).create(podDisruptionBudget); } catch (KubernetesClientException e) { log("Could not create resource", e.getMessage()); } }
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(); } }
public static void main(String[] args) throws InterruptedException { try (OpenShiftClient client = new DefaultOpenShiftClient()) { SecurityContextConstraints scc = new SecurityContextConstraintsBuilder() .withNewMetadata().withName("scc").endMetadata() .withAllowPrivilegedContainer(true) .withNewRunAsUser() .withType("RunAsAny") .endRunAsUser() .withNewSeLinuxContext() .withType("RunAsAny") .endSeLinuxContext() .withNewFsGroup() .withType("RunAsAny") .endFsGroup() .withNewSupplementalGroups() .withType("RunAsAny") .endSupplementalGroups() .addToUsers("admin") .addToGroups("admin-group") .build(); log("Created SecurityContextConstraints", client.securityContextConstraints().create(scc)); client.close(); } catch (KubernetesClientException e) { logger.error(e.getMessage(), e); } }
public static void main(String args[]) throws InterruptedException { String master = "https://192.168.99.100:8443/"; if (args.length == 1) { master = args[0]; } log("Using master with url ", master); Config config = new ConfigBuilder().withMasterUrl(master).build(); try (final KubernetesClient client = new DefaultKubernetesClient(config)) { PriorityClass priorityClass = new PriorityClassBuilder() .withNewMetadata().withName("high-priority").endMetadata() .withValue(new Integer(100000)) .withGlobalDefault(false) .withDescription("This priority class should be used for XYZ service pods only.") .build(); client.scheduling().priorityClass().create(priorityClass); client.pods().inNamespace("default").create(new PodBuilder() .withNewMetadata().withName("nginx").withLabels(Collections.singletonMap("env", "test")).endMetadata() .withNewSpec() .addToContainers(new ContainerBuilder().withName("nginx").withImage("nginx").withImagePullPolicy("IfNotPresent").build()) .withPriorityClassName("high-priority") .endSpec() .build() ); } catch (KubernetesClientException e) { e.printStackTrace(); log("Could not create resource", e.getMessage()); } }
log("Successfully created Persistent Volume object"); } catch (KubernetesClientException e) { log("Could not create resource", e.getMessage());
logger.error(e.getMessage(), e);
log("An error occured while processing cronjobs:", exception.getMessage());
logger.error(e.getMessage(), e); } finally { client.namespaces().withName("thisisatest").delete();
.and().done(); } catch (KubernetesClientException e) { LOG.warn("Unable to add deployment key to pod: {}", e.getMessage());