Search in sources :

Example 1 with AppsV1Api

use of com.marcnuri.yakc.api.apps.v1.AppsV1Api 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)

Aggregations

NotFoundException (com.marcnuri.yakc.api.NotFoundException)1 AppsV1Api (com.marcnuri.yakc.api.apps.v1.AppsV1Api)1 ListPodForAllNamespaces (com.marcnuri.yakc.api.core.v1.CoreV1Api.ListPodForAllNamespaces)1 Deployment (com.marcnuri.yakc.model.io.k8s.api.apps.v1.Deployment)1 PodList (com.marcnuri.yakc.model.io.k8s.api.core.v1.PodList)1 Test (org.junit.jupiter.api.Test)1