Search in sources :

Example 1 with NotFoundException

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);
}
Also used : PodList(com.marcnuri.yakc.model.io.k8s.api.core.v1.PodList) AppsV1Api(com.marcnuri.yakc.api.apps.v1.AppsV1Api) NotFoundException(com.marcnuri.yakc.api.NotFoundException) Deployment(com.marcnuri.yakc.model.io.k8s.api.apps.v1.Deployment) ListPodForAllNamespaces(com.marcnuri.yakc.api.core.v1.CoreV1Api.ListPodForAllNamespaces) Test(org.junit.jupiter.api.Test)

Example 2 with NotFoundException

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);
}
Also used : APIResourceList(com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.APIResourceList) LabelSelector(com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector) ListPodForAllNamespaces(com.marcnuri.yakc.api.core.v1.CoreV1Api.ListPodForAllNamespaces) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Container(com.marcnuri.yakc.model.io.k8s.api.core.v1.Container) PodSpec(com.marcnuri.yakc.model.io.k8s.api.core.v1.PodSpec) ObjectMeta(com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta) DeleteOptions(com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.DeleteOptions) NotFoundException(com.marcnuri.yakc.api.NotFoundException) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConfigMap(com.marcnuri.yakc.model.io.k8s.api.core.v1.ConfigMap) Schedulers(io.reactivex.schedulers.Schedulers) Type(com.marcnuri.yakc.api.WatchEvent.Type) KC(com.marcnuri.yakc.KubernetesClientExtension.KC) IOException(java.io.IOException) Pod(com.marcnuri.yakc.model.io.k8s.api.core.v1.Pod) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) CoreV1Api(com.marcnuri.yakc.api.core.v1.CoreV1Api) CountDownLatch(java.util.concurrent.CountDownLatch) Disposable(io.reactivex.disposables.Disposable) AppsV1Api(com.marcnuri.yakc.api.apps.v1.AppsV1Api) Deployment(com.marcnuri.yakc.model.io.k8s.api.apps.v1.Deployment) Stream(java.util.stream.Stream) PodList(com.marcnuri.yakc.model.io.k8s.api.core.v1.PodList) PodTemplateSpec(com.marcnuri.yakc.model.io.k8s.api.core.v1.PodTemplateSpec) KubernetesException(com.marcnuri.yakc.api.KubernetesException) Collections(java.util.Collections) DeploymentSpec(com.marcnuri.yakc.model.io.k8s.api.apps.v1.DeploymentSpec) NotFoundException(com.marcnuri.yakc.api.NotFoundException) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

NotFoundException (com.marcnuri.yakc.api.NotFoundException)2 AppsV1Api (com.marcnuri.yakc.api.apps.v1.AppsV1Api)2 ListPodForAllNamespaces (com.marcnuri.yakc.api.core.v1.CoreV1Api.ListPodForAllNamespaces)2 Deployment (com.marcnuri.yakc.model.io.k8s.api.apps.v1.Deployment)2 PodList (com.marcnuri.yakc.model.io.k8s.api.core.v1.PodList)2 Test (org.junit.jupiter.api.Test)2 KC (com.marcnuri.yakc.KubernetesClientExtension.KC)1 KubernetesException (com.marcnuri.yakc.api.KubernetesException)1 Type (com.marcnuri.yakc.api.WatchEvent.Type)1 CoreV1Api (com.marcnuri.yakc.api.core.v1.CoreV1Api)1 DeploymentSpec (com.marcnuri.yakc.model.io.k8s.api.apps.v1.DeploymentSpec)1 ConfigMap (com.marcnuri.yakc.model.io.k8s.api.core.v1.ConfigMap)1 Container (com.marcnuri.yakc.model.io.k8s.api.core.v1.Container)1 Pod (com.marcnuri.yakc.model.io.k8s.api.core.v1.Pod)1 PodSpec (com.marcnuri.yakc.model.io.k8s.api.core.v1.PodSpec)1 PodTemplateSpec (com.marcnuri.yakc.model.io.k8s.api.core.v1.PodTemplateSpec)1 APIResourceList (com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.APIResourceList)1 DeleteOptions (com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.DeleteOptions)1 LabelSelector (com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector)1 ObjectMeta (com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta)1