@Override public void onClose(KubernetesClientException cause) { System.out.println("Watch Closed: " + cause); if (cause != null) { cause.printStackTrace(); } } })) {
@Override public void onClose(KubernetesClientException e) { if (e != null) { e.printStackTrace(); logger.error(e.getMessage(), e); } } })) {
public static void main(String[] args) { try { OpenShiftClient client = new DefaultOpenShiftClient(); String namespace = client.getNamespace(); System.out.println("Watching BuildConfigs in namespace " + namespace); try (Watch watchable = client.buildConfigs().inNamespace(namespace).watch(new Watcher<BuildConfig>() { @Override public void eventReceived(Action action, BuildConfig resource) { System.out.println(">> Action: " + action + " on BuildConfig " + resource.getMetadata().getName() + " with version: " + resource.getApiVersion()); } @Override public void onClose(KubernetesClientException cause) { System.out.println("Watch Closed: " + cause); if (cause != null) { cause.printStackTrace(); } } })) { System.out.println("Created watchable " + watchable); } } catch (KubernetesClientException e) { System.out.println("Failed: " + e); e.printStackTrace(); } }
public static void main(String[] args) { try { OpenShiftClient client = new DefaultOpenShiftClient(); if (!client.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.IMAGE)) { System.out.println("WARNING this cluster does not support the API Group " + OpenShiftAPIGroups.IMAGE); return; } ImageStreamList list = client.imageStreams().list(); if (list == null) { System.out.println("ERROR no list returned!"); return; } List<ImageStream> items = list.getItems(); for (ImageStream item : items) { System.out.println("ImageStream " + item.getMetadata().getName() + " has version: " + item.getApiVersion()); } System.out.println("Found " + items.size() + " ImageStream(s)"); } catch (KubernetesClientException e) { System.out.println("Failed: " + e); e.printStackTrace(); } }
public static void main(String[] args) { try { OpenShiftClient client = new DefaultOpenShiftClient(); if (!client.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.BUILD)) { System.out.println("WARNING this cluster does not support the API Group " + OpenShiftAPIGroups.BUILD); return; } BuildConfigList list = client.buildConfigs().list(); if (list == null) { System.out.println("ERROR no list returned!"); return; } List<BuildConfig> items = list.getItems(); for (BuildConfig item : items) { System.out.println("BuildConfig " + item.getMetadata().getName() + " has version: " + item.getApiVersion()); } } catch (KubernetesClientException e) { System.out.println("Failed: " + e); e.printStackTrace(); } }
public static void main(String[] args) { try { KubernetesClient client = new DefaultKubernetesClient(); if (!client.supportsApiPath("/apis/apiextensions.k8s.io/v1beta1") && !client.supportsApiPath("/apis/apiextensions.k8s.io/v1")) { System.out.println("WARNING this cluster does not support the API Group apiextensions.k8s.io"); return; } CustomResourceDefinitionList list = client.customResourceDefinitions().list(); if (list == null) { System.out.println("ERROR no list returned!"); return; } List<CustomResourceDefinition> items = list.getItems(); for (CustomResourceDefinition item : items) { System.out.println("CustomResourceDefinition " + item.getMetadata().getName() + " has version: " + item.getApiVersion()); } } catch (KubernetesClientException e) { System.out.println("Failed: " + e); e.printStackTrace(); } }}
public static void main(String[] args) { try { OpenShiftClient client = new DefaultOpenShiftClient(); if (!client.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.APPS)) { System.out.println("WARNING this cluster does not support the API Group " + OpenShiftAPIGroups.APPS); return; } DeploymentConfigList list = client.deploymentConfigs().list(); if (list == null) { System.out.println("ERROR no list returned!"); return; } List<DeploymentConfig> items = list.getItems(); for (DeploymentConfig item : items) { System.out.println("DeploymentConfig " + item.getMetadata().getName() + " has version: " + item.getApiVersion()); } if (items.size() > 0) { // lets check .get() too DeploymentConfig deploymentConfig = items.get(0); String name = deploymentConfig.getMetadata().getName(); deploymentConfig = client.deploymentConfigs().withName(name).get(); assertNotNull("No DeploymentConfig found for name " + name, deploymentConfig); System.out.println("get() DeploymentConfig " + name + " has version: " + deploymentConfig.getApiVersion()); } } catch (KubernetesClientException e) { System.out.println("Failed: " + e); e.printStackTrace(); } }
ClientException.printStackTrace();
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()); } }