Search in sources :

Example 41 with CoreV1Api

use of io.kubernetes.client.openapi.apis.CoreV1Api in project java by kubernetes-client.

the class LogsExample method main.

public static void main(String[] args) throws IOException, ApiException, InterruptedException {
    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);
    CoreV1Api coreApi = new CoreV1Api(client);
    PodLogs logs = new PodLogs();
    V1Pod pod = coreApi.listNamespacedPod("default", "false", null, null, null, null, null, null, null, null, null).getItems().get(0);
    InputStream is = logs.streamNamespacedPodLog(pod);
    Streams.copy(is, System.out);
}
Also used : PodLogs(io.kubernetes.client.PodLogs) InputStream(java.io.InputStream) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ApiClient(io.kubernetes.client.openapi.ApiClient) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api)

Example 42 with CoreV1Api

use of io.kubernetes.client.openapi.apis.CoreV1Api in project java by kubernetes-client.

the class PagerExample method main.

public static void main(String[] args) throws IOException {
    ApiClient client = Config.defaultClient();
    OkHttpClient httpClient = client.getHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build();
    client.setHttpClient(httpClient);
    Configuration.setDefaultApiClient(client);
    CoreV1Api api = new CoreV1Api();
    int i = 0;
    Pager<V1Namespace, V1NamespaceList> pager = new Pager<V1Namespace, V1NamespaceList>((Pager.PagerParams param) -> {
        try {
            return api.listNamespaceCall(null, null, param.getContinueToken(), null, null, param.getLimit(), null, null, 1, null, null);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }, client, 10, V1NamespaceList.class);
    for (V1Namespace namespace : pager) {
        System.out.println(namespace.getMetadata().getName());
    }
    System.out.println("------------------");
}
Also used : V1NamespaceList(io.kubernetes.client.openapi.models.V1NamespaceList) OkHttpClient(okhttp3.OkHttpClient) Pager(io.kubernetes.client.extended.pager.Pager) V1Namespace(io.kubernetes.client.openapi.models.V1Namespace) ApiClient(io.kubernetes.client.openapi.ApiClient) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) IOException(java.io.IOException)

Example 43 with CoreV1Api

use of io.kubernetes.client.openapi.apis.CoreV1Api in project java by kubernetes-client.

the class ExampleTest method exactUrlOnly.

@Test
public void exactUrlOnly() throws IOException, ApiException {
    ApiClient client = new ApiClient();
    client.setBasePath("http://localhost:" + PORT);
    Configuration.setDefaultApiClient(client);
    V1Namespace ns1 = new V1Namespace().metadata(new V1ObjectMeta().name("name"));
    stubFor(get(urlEqualTo("/api/v1/namespaces/name")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(client.getJSON().serialize(ns1))));
    CoreV1Api api = new CoreV1Api();
    V1Namespace ns2 = api.readNamespace("name", null);
    assertEquals(ns1, ns2);
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Namespace(io.kubernetes.client.openapi.models.V1Namespace) ApiClient(io.kubernetes.client.openapi.ApiClient) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) Test(org.junit.Test)

Example 44 with CoreV1Api

use of io.kubernetes.client.openapi.apis.CoreV1Api in project java by kubernetes-client.

the class Example method main.

public static void main(String[] args) throws IOException, ApiException {
    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);
    CoreV1Api api = new CoreV1Api();
    V1PodList list = api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null);
    for (V1Pod item : list.getItems()) {
        System.out.println(item.getMetadata().getName());
    }
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ApiClient(io.kubernetes.client.openapi.ApiClient) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api)

Example 45 with CoreV1Api

use of io.kubernetes.client.openapi.apis.CoreV1Api in project java by kubernetes-client.

the class ExpandedExample method main.

/**
 * Main method
 *
 * @param args
 */
public static void main(String[] args) {
    try {
        ApiClient client = Config.defaultClient();
        // To change the context of k8s cluster, you can use
        // io.kubernetes.client.util.KubeConfig
        Configuration.setDefaultApiClient(client);
        COREV1_API = new CoreV1Api(client);
        // ScaleUp/ScaleDown the Deployment pod
        // Please change the name of Deployment?
        System.out.println("----- Scale Deployment Start -----");
        scaleDeployment("account-service", 5);
        // List all of the namaspaces and pods
        List<String> nameSpaces = getAllNameSpaces();
        nameSpaces.stream().forEach(namespace -> {
            try {
                System.out.println("----- " + namespace + " -----");
                getNamespacedPod(namespace).stream().forEach(System.out::println);
            } catch (ApiException ex) {
                LOGGER.warn("Couldn't get the pods in namespace:" + namespace, ex);
            }
        });
        // Print all of the Services
        System.out.println("----- Print list all Services Start -----");
        List<String> services = getServices();
        services.stream().forEach(System.out::println);
        System.out.println("----- Print list all Services End -----");
        // Print log of specific pod. In this example show the first pod logs.
        System.out.println("----- Print Log of Specific Pod Start -----");
        String firstPodName = getPods().get(0);
        printLog(DEFAULT_NAME_SPACE, firstPodName);
        System.out.println("----- Print Log of Specific Pod End -----");
    } catch (ApiException | IOException ex) {
        LOGGER.warn("Exception had occured ", ex);
    }
}
Also used : IOException(java.io.IOException) ApiClient(io.kubernetes.client.openapi.ApiClient) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) ApiException(io.kubernetes.client.openapi.ApiException)

Aggregations

CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)48 V1Pod (io.kubernetes.client.openapi.models.V1Pod)18 ApiClient (io.kubernetes.client.openapi.ApiClient)16 Test (org.junit.Test)16 ApiException (io.kubernetes.client.openapi.ApiException)13 V1PodList (io.kubernetes.client.openapi.models.V1PodList)13 SneakyThrows (lombok.SneakyThrows)12 IOException (java.io.IOException)11 V1Namespace (io.kubernetes.client.openapi.models.V1Namespace)10 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)10 CallGeneratorParams (io.kubernetes.client.util.CallGeneratorParams)9 Watch (io.kubernetes.client.util.Watch)9 SharedInformerFactory (io.kubernetes.client.informer.SharedInformerFactory)8 JSON (io.kubernetes.client.openapi.JSON)6 V1Status (io.kubernetes.client.openapi.models.V1Status)6 OkHttpClient (okhttp3.OkHttpClient)6 V1Patch (io.kubernetes.client.custom.V1Patch)5 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)5 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5