Search in sources :

Example 1 with PodList

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.PodList 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 PodList

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.PodList in project java by kubernetes-client.

the class ProtoExample method main.

public static void main(String[] args) throws IOException, ApiException, InterruptedException {
    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);
    ProtoClient pc = new ProtoClient(client);
    ObjectOrStatus<PodList> list = pc.list(PodList.newBuilder(), "/api/v1/namespaces/default/pods");
    if (list.object.getItemsCount() > 0) {
        Pod p = list.object.getItems(0);
        System.out.println(p);
    }
    Namespace namespace = Namespace.newBuilder().setMetadata(ObjectMeta.newBuilder().setName("test").build()).build();
    ObjectOrStatus<Namespace> ns = pc.create(namespace, "/api/v1/namespaces", "v1", "Namespace");
    System.out.println(ns);
    if (ns.object != null) {
        namespace = ns.object.toBuilder().setSpec(NamespaceSpec.newBuilder().addFinalizers("test").build()).build();
        // This is how you would update an object, but you can't actually
        // update namespaces, so this returns a 405
        ns = pc.update(namespace, "/api/v1/namespaces/test", "v1", "Namespace");
        System.out.println(ns.status);
    }
    ns = pc.delete(Namespace.newBuilder(), "/api/v1/namespaces/test");
    System.out.println(ns);
}
Also used : PodList(io.kubernetes.client.proto.V1.PodList) Pod(io.kubernetes.client.proto.V1.Pod) ApiClient(io.kubernetes.client.openapi.ApiClient) Namespace(io.kubernetes.client.proto.V1.Namespace) ProtoClient(io.kubernetes.client.ProtoClient)

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 ProtoClient (io.kubernetes.client.ProtoClient)1 ApiClient (io.kubernetes.client.openapi.ApiClient)1 Namespace (io.kubernetes.client.proto.V1.Namespace)1 Pod (io.kubernetes.client.proto.V1.Pod)1 PodList (io.kubernetes.client.proto.V1.PodList)1 Test (org.junit.jupiter.api.Test)1