Search in sources :

Example 1 with ApiClient

use of io.kubernetes.client.ApiClient in project weblogic-kubernetes-operator by oracle.

the class TestEnhancedAuthenticationAT method testCreateClientByServiceAccount.

@Test
public void testCreateClientByServiceAccount() throws Exception {
    try {
        // First authenticate using the default service account in default
        // namespace.  The resultant client is used to do a trivial call
        // to demonstrate that the rest API is available weith the new client.
        Authenticator auth1 = new Authenticator();
        ApiClient client = auth1.createClientByServiceAccountName("default", "default");
        CoreV1Api coreApi = new CoreV1Api(client);
        System.out.println("authenticated by service account");
        V1APIResourceList rslist = coreApi.getAPIResources();
        System.out.println(rslist);
        // Pickup the token from the first authentication and use it to
        // find the same service account that was just authenticated. Then
        // do a REST api call with the returned client to verify the API
        // is available through the new client.
        Authenticator auth2 = new Authenticator(client);
        client = auth2.createClientByToken(auth1.getServiceToken());
        coreApi = new CoreV1Api(client);
        System.out.println("authenticated by token");
        rslist = coreApi.getAPIResources();
        System.out.println(rslist);
        System.out.println("Successful end of this test");
    } catch (Exception e) {
        System.out.println("Test failed with exception - " + e);
        e.printStackTrace();
    }
}
Also used : V1APIResourceList(io.kubernetes.client.models.V1APIResourceList) ApiClient(io.kubernetes.client.ApiClient) Authenticator(oracle.kubernetes.operator.authentication.Authenticator) CoreV1Api(io.kubernetes.client.apis.CoreV1Api) Test(org.junit.Test)

Example 2 with ApiClient

use of io.kubernetes.client.ApiClient in project weblogic-kubernetes-operator by oracle.

the class CallBuilder method listIngress.

/* Ingress */
/**
 * List ingress
 * @param namespace Namespace
 * @return Listed ingress
 * @throws ApiException API Exception
 */
public V1beta1IngressList listIngress(String namespace) throws ApiException {
    String _continue = "";
    ApiClient client = helper.take();
    try {
        return new ExtensionsV1beta1Api(client).listNamespacedIngress(namespace, pretty, _continue, fieldSelector, includeUninitialized, labelSelector, limit, resourceVersion, timeoutSeconds, watch);
    } finally {
        helper.recycle(client);
    }
}
Also used : ExtensionsV1beta1Api(io.kubernetes.client.apis.ExtensionsV1beta1Api) ApiClient(io.kubernetes.client.ApiClient)

Example 3 with ApiClient

use of io.kubernetes.client.ApiClient in project weblogic-kubernetes-operator by oracle.

the class ClientPool method getApiClient.

private ApiClient getApiClient() {
    LOGGER.entering();
    ApiClient client = null;
    LOGGER.fine(MessageKeys.CREATING_API_CLIENT);
    try {
        client = Config.defaultClient();
        if (first.getAndSet(false)) {
            Configuration.setDefaultApiClient(client);
        }
    } catch (Throwable e) {
        LOGGER.warning(MessageKeys.EXCEPTION, e);
    }
    LOGGER.info(MessageKeys.K8S_MASTER_URL, client != null ? client.getBasePath() : null);
    // Ensure that client doesn't time out before call or watch
    client.getHttpClient().setReadTimeout(5, TimeUnit.MINUTES);
    LOGGER.exiting(client);
    return client;
}
Also used : ApiClient(io.kubernetes.client.ApiClient)

Example 4 with ApiClient

use of io.kubernetes.client.ApiClient in project weblogic-kubernetes-operator by oracle.

the class CallBuilder method listNamespace.

/* Namespaces */
/**
 * List namespaces
 * @return List of namespaces
 * @throws ApiException API Exception
 */
public V1NamespaceList listNamespace() throws ApiException {
    String _continue = "";
    ApiClient client = helper.take();
    try {
        return new CoreV1Api(client).listNamespace(pretty, _continue, fieldSelector, includeUninitialized, labelSelector, limit, resourceVersion, timeoutSeconds, watch);
    } finally {
        helper.recycle(client);
    }
}
Also used : ApiClient(io.kubernetes.client.ApiClient) CoreV1Api(io.kubernetes.client.apis.CoreV1Api)

Example 5 with ApiClient

use of io.kubernetes.client.ApiClient in project weblogic-kubernetes-operator by oracle.

the class CallBuilder method listPod.

/* Pods */
/**
 * List pods
 * @param namespace Namespace
 * @return Listed pods
 * @throws ApiException API Exception
 */
public V1PodList listPod(String namespace) throws ApiException {
    String _continue = "";
    ApiClient client = helper.take();
    try {
        return new CoreV1Api(client).listNamespacedPod(namespace, pretty, _continue, fieldSelector, includeUninitialized, labelSelector, limit, resourceVersion, timeoutSeconds, watch);
    } finally {
        helper.recycle(client);
    }
}
Also used : ApiClient(io.kubernetes.client.ApiClient) CoreV1Api(io.kubernetes.client.apis.CoreV1Api)

Aggregations

ApiClient (io.kubernetes.client.ApiClient)18 CoreV1Api (io.kubernetes.client.apis.CoreV1Api)9 ApiException (io.kubernetes.client.ApiException)4 IOException (java.io.IOException)4 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)3 CustomObjectsApi (io.kubernetes.client.apis.CustomObjectsApi)3 ExtensionsV1beta1Api (io.kubernetes.client.apis.ExtensionsV1beta1Api)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 TypeToken (com.google.gson.reflect.TypeToken)2 Watch (io.kubernetes.client.util.Watch)2 SocketTimeoutException (java.net.SocketTimeoutException)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonParser (com.fasterxml.jackson.core.JsonParser)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Response (com.squareup.okhttp.Response)1 TopologyRuntimeManagementException (com.twitter.heron.scheduler.TopologyRuntimeManagementException)1 ExtensionsV1beta1Deployment (io.kubernetes.client.models.ExtensionsV1beta1Deployment)1 ExtensionsV1beta1DeploymentList (io.kubernetes.client.models.ExtensionsV1beta1DeploymentList)1