use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by jboss-fuse.
the class ListSpaces method main.
public static void main(String[] args) {
String namespace = null;
if (args.length > 0) {
namespace = args[0];
}
KubernetesClient kubernetesClient = new DefaultKubernetesClient();
Spaces spaces = Spaces.load(kubernetesClient, namespace);
SortedSet<Space> set = spaces.getSpaceSet();
for (Space space : set) {
System.out.println("Space " + space.getName() + " = " + space);
}
}
use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by jboss-fuse.
the class WatchPodsExample method main.
public static void main(String... args) throws Exception {
KubernetesClient client = new DefaultKubernetesClient();
client.pods().watch(new io.fabric8.kubernetes.client.Watcher<Pod>() {
@Override
public void eventReceived(Action action, Pod pod) {
System.out.println(action + ": " + pod);
}
@Override
public void onClose(KubernetesClientException e) {
System.out.println("Closed: " + e);
}
});
client.close();
}
use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by jboss-fuse.
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.DefaultKubernetesClient in project fabric8 by jboss-fuse.
the class Apply method main.
public static void main(String... args) {
if (args.length < 1) {
System.out.println("Usage jsonFileToApply");
return;
}
try {
KubernetesClient kube = new DefaultKubernetesClient();
File file = new File(args[0]);
System.out.println("Applying file: " + file);
if (!file.exists() || !file.isFile()) {
System.out.println("File does not exist! " + file.getAbsolutePath());
return;
}
Controller controller = new Controller(kube);
String answer = controller.apply(file);
System.out.println("Applied!: " + answer);
} catch (Exception e) {
System.out.println("FAILED: " + e);
e.printStackTrace();
}
}
use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project kubernetes by ballerinax.
the class OpenShiftBuildConfigTest method simpleBuildConfigTest.
/**
* Test case openshift build config annotation with default values.
*/
@Test(groups = { "openshift" })
public void simpleBuildConfigTest() throws IOException, InterruptedException, KubernetesPluginException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "simple_bc.bal"), 0);
File yamlFile = new File(KUBERNETES_TARGET_PATH + File.separator + "simple_bc.yaml");
Assert.assertTrue(yamlFile.exists());
KubernetesClient client = new DefaultKubernetesClient();
List<HasMetadata> k8sItems = client.load(new FileInputStream(yamlFile)).get();
for (HasMetadata data : k8sItems) {
switch(data.getKind()) {
case "Service":
case "Deployment":
break;
case "BuildConfig":
BuildConfig bc = (BuildConfig) data;
// metadata
Assert.assertNotNull(bc.getMetadata());
Assert.assertEquals(bc.getMetadata().getName(), "helloep-openshift-bc", "Invalid name found.");
Assert.assertNotNull(bc.getMetadata().getLabels(), "Labels are missing");
Assert.assertEquals(bc.getMetadata().getLabels().size(), 1, "Labels are missing");
Assert.assertNotNull(bc.getMetadata().getLabels().get("build"), "'build' label is missing");
Assert.assertEquals(bc.getMetadata().getLabels().get("build"), "helloep-openshift-bc", "Invalid label 'build' label value.");
// spec
Assert.assertNotNull(bc.getSpec());
Assert.assertNotNull(bc.getSpec().getOutput());
Assert.assertNotNull(bc.getSpec().getOutput().getTo());
Assert.assertEquals(bc.getSpec().getOutput().getTo().getKind(), "ImageStreamTag", "Invalid output kind.");
Assert.assertEquals(bc.getSpec().getOutput().getTo().getName(), "simple_bc:latest", "Invalid image stream name.");
Assert.assertNotNull(bc.getSpec().getSource());
Assert.assertNotNull(bc.getSpec().getSource().getBinary(), "Binary source is missing");
Assert.assertNotNull(bc.getSpec().getStrategy());
Assert.assertNotNull(bc.getSpec().getStrategy().getDockerStrategy(), "Docker strategy is missing.");
Assert.assertEquals(bc.getSpec().getStrategy().getDockerStrategy().getBuildArgs().size(), 0, "Invalid number of build args.");
Assert.assertEquals(bc.getSpec().getStrategy().getDockerStrategy().getDockerfilePath(), "kubernetes/docker/Dockerfile", "Invalid docker path.");
Assert.assertFalse(bc.getSpec().getStrategy().getDockerStrategy().getForcePull(), "Force pull image set to false");
Assert.assertFalse(bc.getSpec().getStrategy().getDockerStrategy().getNoCache(), "No cache for image build set to false");
break;
case "ImageStream":
ImageStream is = (ImageStream) data;
Assert.assertNotNull(is.getMetadata());
Assert.assertEquals(is.getMetadata().getName(), "simple_bc", "Invalid name found.");
Assert.assertEquals(is.getMetadata().getLabels().size(), 1, "Labels are missing");
Assert.assertNotNull(is.getMetadata().getLabels().get("build"), "'build' label is missing");
Assert.assertEquals(is.getMetadata().getLabels().get("build"), "helloep-openshift-bc", "Invalid label 'build' label value.");
Assert.assertNull(is.getSpec());
break;
default:
Assert.fail("Unexpected k8s resource found: " + data.getKind());
break;
}
}
KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
}
Aggregations