Search in sources :

Example 26 with ApiException

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

the class CRDHelper method checkAndCreateCustomResourceDefinition.

/**
 * Validates and, if necessary, created domains.weblogic.oracle CRD.  No need
 * to be async as operator can not begin processing until CRD exists
 */
public static void checkAndCreateCustomResourceDefinition() {
    LOGGER.entering();
    V1beta1CustomResourceDefinition crd = new V1beta1CustomResourceDefinition();
    crd.setApiVersion("apiextensions.k8s.io/v1beta1");
    crd.setKind("CustomResourceDefinition");
    V1ObjectMeta om = new V1ObjectMeta();
    om.setName("domains.weblogic.oracle");
    crd.setMetadata(om);
    V1beta1CustomResourceDefinitionSpec crds = new V1beta1CustomResourceDefinitionSpec();
    crds.setGroup(KubernetesConstants.DOMAIN_GROUP);
    crds.setVersion(KubernetesConstants.DOMAIN_VERSION);
    crds.setScope("Namespaced");
    V1beta1CustomResourceDefinitionNames crdn = new V1beta1CustomResourceDefinitionNames();
    crdn.setPlural(KubernetesConstants.DOMAIN_PLURAL);
    crdn.setSingular(KubernetesConstants.DOMAIN_SINGULAR);
    crdn.setKind("Domain");
    crdn.setShortNames(Collections.singletonList(KubernetesConstants.DOMAIN_SHORT));
    crds.setNames(crdn);
    crd.setSpec(crds);
    CallBuilderFactory factory = ContainerResolver.getInstance().getContainer().getSPI(CallBuilderFactory.class);
    V1beta1CustomResourceDefinition existingCRD = null;
    try {
        existingCRD = factory.create().readCustomResourceDefinition(crd.getMetadata().getName());
    } catch (ApiException e) {
        if (e.getCode() != CallBuilder.NOT_FOUND) {
            LOGGER.warning(MessageKeys.EXCEPTION, e);
        }
    }
    try {
        if (existingCRD == null) {
            LOGGER.info(MessageKeys.CREATING_CRD, crd.toString());
            factory.create().createCustomResourceDefinition(crd);
        }
    } catch (ApiException e) {
        LOGGER.warning(MessageKeys.EXCEPTION, e);
    }
    LOGGER.exiting();
}
Also used : V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) V1beta1CustomResourceDefinitionNames(io.kubernetes.client.models.V1beta1CustomResourceDefinitionNames) V1beta1CustomResourceDefinitionSpec(io.kubernetes.client.models.V1beta1CustomResourceDefinitionSpec) V1beta1CustomResourceDefinition(io.kubernetes.client.models.V1beta1CustomResourceDefinition) ApiException(io.kubernetes.client.ApiException)

Example 27 with ApiException

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

the class SecretHelperTest method createInvalidSecret.

// Create a named secret with no username / password in specified namespace
private V1Secret createInvalidSecret(String name, String namespace) throws Exception {
    CallBuilderFactory factory = new CallBuilderFactory(null);
    try {
        V1Secret existing = factory.create().readSecret(name, namespace);
        if (existing != null)
            return existing;
    } catch (ApiException ignore) {
    // Just ignore and try to create it
    }
    if (isVersion18)
        return null;
    V1Secret body = new V1Secret();
    // Set the required api version and kind of resource
    body.setApiVersion("v1");
    body.setKind("Secret");
    // Setup the standard object metadata
    V1ObjectMeta meta = new V1ObjectMeta();
    meta.setName(name);
    meta.setNamespace(namespace);
    body.setMetadata(meta);
    return factory.create().createSecret(namespace, body);
}
Also used : V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) CallBuilderFactory(oracle.kubernetes.operator.helpers.CallBuilderFactory) V1Secret(io.kubernetes.client.models.V1Secret) ApiException(io.kubernetes.client.ApiException)

Example 28 with ApiException

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

the class ServiceHelperTest method startClean.

@Before
public void startClean() throws Exception {
    CallBuilderFactory factory = new CallBuilderFactory(null);
    // Delete the service if left around.
    System.out.println("Deleting service pre-test");
    try {
        factory.create().deleteService("domain-uid-admin", "tests");
    } catch (ApiException e) {
        if (e.getCode() != CallBuilder.NOT_FOUND) {
            throw e;
        }
    }
}
Also used : CallBuilderFactory(oracle.kubernetes.operator.helpers.CallBuilderFactory) ApiException(io.kubernetes.client.ApiException) Before(org.junit.Before)

Example 29 with ApiException

use of io.kubernetes.client.ApiException in project twister2 by DSC-SPIDAL.

the class WorkerController method buildWorkerList.

/**
 * build worker list by getting the pod list from the kubernetes master
 */
private void buildWorkerList() {
    String namespace = KubernetesContext.namespace(config);
    String servicelabel = KubernetesUtils.createServiceLabelWithApp(jobName);
    int basePort = KubernetesContext.workerBasePort(config);
    V1PodList list = null;
    try {
        list = coreApi.listNamespacedPod(namespace, null, null, null, null, servicelabel, null, null, null, null);
    } catch (ApiException e) {
        String logMessage = "Exception when getting the pod list for the job: " + jobName + "\n" + "exCode: " + e.getCode() + "\n" + "responseBody: " + e.getResponseBody();
        LOG.log(Level.SEVERE, logMessage, e);
        throw new RuntimeException(e);
    }
    workerList.clear();
    for (V1Pod pod : list.getItems()) {
        String podName = pod.getMetadata().getName();
        if (!podName.startsWith(jobName)) {
            LOG.warning("A pod received that does not belong to this job. PodName: " + podName);
            continue;
        }
        InetAddress podIP = convertStringToIP(pod.getStatus().getPodIP());
        for (int i = 0; i < workersPerPod; i++) {
            int containerIndex = i;
            int workerID = calculateWorkerID(podName, containerIndex);
            WorkerNetworkInfo workerNetworkInfo = new WorkerNetworkInfo(podIP, basePort + containerIndex, workerID);
            workerList.add(workerNetworkInfo);
        }
    }
}
Also used : V1PodList(io.kubernetes.client.models.V1PodList) WorkerNetworkInfo(edu.iu.dsc.tws.rsched.bootstrap.WorkerNetworkInfo) V1Pod(io.kubernetes.client.models.V1Pod) InetAddress(java.net.InetAddress) ApiException(io.kubernetes.client.ApiException)

Aggregations

ApiException (io.kubernetes.client.ApiException)29 IOException (java.io.IOException)11 CallBuilderFactory (oracle.kubernetes.operator.helpers.CallBuilderFactory)9 V1ObjectMeta (io.kubernetes.client.models.V1ObjectMeta)7 Response (com.squareup.okhttp.Response)5 ApiClient (io.kubernetes.client.ApiClient)5 TopologyRuntimeManagementException (com.twitter.heron.scheduler.TopologyRuntimeManagementException)4 V1DeleteOptions (io.kubernetes.client.models.V1DeleteOptions)3 V1Secret (io.kubernetes.client.models.V1Secret)3 V1beta1StatefulSet (io.kubernetes.client.models.V1beta1StatefulSet)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 JSON (io.kubernetes.client.JSON)2 CustomObjectsApi (io.kubernetes.client.apis.CustomObjectsApi)2 V1Namespace (io.kubernetes.client.models.V1Namespace)2 V1Pod (io.kubernetes.client.models.V1Pod)2 V1PodList (io.kubernetes.client.models.V1PodList)2 V1ServiceAccount (io.kubernetes.client.models.V1ServiceAccount)2 V1ServiceAccountList (io.kubernetes.client.models.V1ServiceAccountList)2