Search in sources :

Example 1 with Pod

use of io.kubernetes.client.proto.V1.Pod 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.ApiClient) Namespace(io.kubernetes.client.proto.V1.Namespace) ProtoClient(io.kubernetes.client.ProtoClient)

Aggregations

ApiClient (io.kubernetes.client.ApiClient)1 ProtoClient (io.kubernetes.client.ProtoClient)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