use of com.marcnuri.yakc.api.NotFoundException in project yakc by manusa.
the class WipIT method deployment.
@Test
void deployment() throws IOException {
final AppsV1Api api = KC.create(AppsV1Api.class);
final String deploymentName = "java-test";
try {
api.deleteNamespacedDeployment(deploymentName, "default").get();
System.out.println("Deployment created");
} catch (NotFoundException ex) {
System.out.println("Deployment not found, deletion not needed");
}
final Deployment deployment = api.createNamespacedDeployment("default", Deployment.builder().metadata(ObjectMeta.builder().name(deploymentName).build()).spec(DeploymentSpec.builder().replicas(1).selector(LabelSelector.builder().putInMatchLabels("k8s-app", "test-java").build()).template(PodTemplateSpec.builder().metadata(ObjectMeta.builder().name("java-test-pod").putInLabels("k8s-app", "test-java").build()).spec(PodSpec.builder().addToContainers(Container.builder().image("containous/whoami").name("java-test-pod").build()).build()).build()).build()).build()).get();
System.out.println(deployment);
api.patchNamespacedDeployment(deploymentName, "default", Deployment.builder().spec(deployment.getSpec().toBuilder().replicas(2).build()).build()).get();
final PodList selectedPodList = KC.create(CoreV1Api.class).listPodForAllNamespaces(new ListPodForAllNamespaces().labelSelector("k8s-app=test-pod")).get();
System.out.println(selectedPodList);
}
use of com.marcnuri.yakc.api.NotFoundException in project yakc by manusa.
the class WipIT method configMaps.
@Test
void configMaps() throws Exception {
final String configMapName = "test";
final CountDownLatch cdl = new CountDownLatch(1);
KC.create(CoreV1Api.class).listConfigMapForAllNamespaces().watch().subscribeOn(Schedulers.newThread()).filter(we -> Stream.of(Type.ADDED, Type.DELETED).anyMatch(t -> we.getType() == t)).filter(we -> we.getObject().getMetadata().getName().equals(configMapName)).subscribe(we -> {
cdl.countDown();
System.out.printf("++ ConfigMap Watch %-15s - %s/%s%n", we.getType(), we.getObject().getMetadata().getNamespace(), we.getObject().getMetadata().getName());
});
try {
KC.create(CoreV1Api.class).deleteNamespacedConfigMap(configMapName, "default").get();
System.out.println("Existing ConfigMap was deleted");
} catch (NotFoundException ex) {
System.out.println("ConfigMap not found, deletion not needed");
}
KC.create(CoreV1Api.class).createNamespacedConfigMap("default", ConfigMap.builder().metadata(ObjectMeta.builder().name(configMapName).putInAnnotations("one-annotation-key", "annotation-value").build()).data(Collections.singletonMap("some", "to-keep")).putInData("test-key", "test-value").build()).get();
KC.create(CoreV1Api.class).patchNamespacedConfigMap(configMapName, "default", ConfigMap.builder().metadata(ObjectMeta.builder().putInLabels("other", "label").build()).build()).get();
cdl.await(5, TimeUnit.SECONDS);
}
Aggregations