use of io.fabric8.kubernetes.client.KubernetesClient in project fabric8 by fabric8io.
the class Example method main.
public static void main(String[] args) {
try {
final KubernetesClient client = new DefaultKubernetesClient();
assertThat(client).pods().runningStatus().hasSize(6);
assertThat(client).pods().runningStatus().filterLabel("provider", "fabric8").assertSize().isGreaterThan(0);
assertThat(client.services().inNamespace("default").withName("fabric8").get().getMetadata()).name().isEqualTo("fabric8");
Map<String, String> consoleLabels = new HashMap<>();
consoleLabels.put("component", "console");
consoleLabels.put("provider", "fabric8");
assertThat(client).podsForService("fabric8").runningStatus().extracting("metadata").extracting("labels").contains(consoleLabels);
assertThat(client).podsForService("fabric8").runningStatus().hasSize(1).extracting("metadata").extracting("labels").contains(consoleLabels);
assertThat(client).podsForService("fabric8").logs().doesNotContainText("Exception", "Error");
assertThat(client).pods().logs().doesNotContainText("Exception", "Error");
assertAssertionError(new Block() {
@Override
public void invoke() throws Exception {
try {
assertThat(client.services().inNamespace("default").withName("doesNotExist").get().getMetadata()).name().isEqualTo("fabric8-console-controller");
} catch (KubernetesClientException e) {
if (e.getCode() != 404) {
throw e;
} else {
throw new AssertionError(e);
}
}
}
});
assertAssertionError(new Block() {
@Override
public void invoke() throws Exception {
try {
assertThat(client).pods().runningStatus().filterLabel("component", "doesNotExist").hasSize(1);
} catch (KubernetesClientException e) {
if (e.getCode() != 404) {
throw e;
} else {
throw new AssertionError(e);
}
}
}
});
System.out.println("Done!");
} catch (Throwable e) {
System.out.println("Caught: " + e);
e.printStackTrace();
}
}
use of io.fabric8.kubernetes.client.KubernetesClient in project fabric8 by fabric8io.
the class Example method listReplicationControllers.
protected static void listReplicationControllers(KubernetesClient kube) {
System.out.println("\n\nLooking up replicationControllers");
System.out.println("=========================================================================");
ReplicationControllerList replicationControllers = kube.replicationControllers().list();
List<ReplicationController> items = replicationControllers.getItems();
for (ReplicationController item : items) {
ReplicationControllerSpec replicationControllerSpec = item.getSpec();
if (replicationControllerSpec != null) {
System.out.println("ReplicationController " + KubernetesHelper.getName(item) + " labels: " + item.getMetadata().getLabels() + " replicas: " + replicationControllerSpec.getReplicas() + " replicatorSelector: " + replicationControllerSpec.getSelector() + " podTemplate: " + replicationControllerSpec.getTemplate());
} else {
System.out.println("ReplicationController " + KubernetesHelper.getName(item) + " labels: " + item.getMetadata().getLabels() + " no replicationControllerSpec");
}
}
System.out.println();
}
use of io.fabric8.kubernetes.client.KubernetesClient in project fabric8 by fabric8io.
the class Example method listPods.
protected static void listPods(KubernetesClient kube) {
System.out.println("\n\nLooking up pods");
System.out.println("=========================================================================");
PodList pods = kube.pods().list();
// System.out.println("Got pods: " + pods);
List<Pod> items = pods.getItems();
for (Pod item : items) {
System.out.println("Pod " + KubernetesHelper.getName(item) + " with ip: " + item.getStatus().getPodIP() + " created: " + item.getMetadata().getCreationTimestamp());
PodSpec spec = item.getSpec();
if (spec != null) {
List<Container> containers = spec.getContainers();
if (containers != null) {
for (Container container : containers) {
System.out.println("Container " + container.getImage() + " " + container.getCommand() + " ports: " + container.getPorts());
}
}
}
Map<String, ContainerStatus> currentContainers = KubernetesHelper.getCurrentContainers(item);
System.out.println("Has " + currentContainers.size() + " container(s)");
Set<Map.Entry<String, ContainerStatus>> entries = currentContainers.entrySet();
for (Map.Entry<String, ContainerStatus> entry : entries) {
String id = entry.getKey();
ContainerStatus info = entry.getValue();
System.out.println("Current container: " + id + " info: " + info);
}
}
System.out.println();
}
use of io.fabric8.kubernetes.client.KubernetesClient in project fabric8 by fabric8io.
the class Example method main.
public static void main(String... args) {
System.out.println("\n\nfabric8 Kubernetes-api example");
KubernetesClient kube = new DefaultKubernetesClient();
System.out.println("=========================================================================");
try {
listPods(kube);
listReplicationControllers(kube);
listServices(kube);
listServiceAccounts(kube);
listEndpoints(kube);
} catch (Exception e) {
System.out.println("FAILED: " + e);
e.printStackTrace();
} finally {
kube.close();
}
System.out.println("=========================================================================");
}
use of io.fabric8.kubernetes.client.KubernetesClient in project fabric8 by fabric8io.
the class IsOpenShift method main.
public static void main(String... args) {
KubernetesClient client = new DefaultKubernetesClient();
try {
boolean openShift = KubernetesHelper.isOpenShift(client);
System.out.println("OpenShift: " + openShift);
} catch (Exception e) {
System.out.println("FAILED: " + e);
e.printStackTrace();
}
}
Aggregations