Search in sources :

Example 1 with V1beta1CustomResourceDefinitionNames

use of io.kubernetes.client.models.V1beta1CustomResourceDefinitionNames 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)

Aggregations

ApiException (io.kubernetes.client.ApiException)1 V1ObjectMeta (io.kubernetes.client.models.V1ObjectMeta)1 V1beta1CustomResourceDefinition (io.kubernetes.client.models.V1beta1CustomResourceDefinition)1 V1beta1CustomResourceDefinitionNames (io.kubernetes.client.models.V1beta1CustomResourceDefinitionNames)1 V1beta1CustomResourceDefinitionSpec (io.kubernetes.client.models.V1beta1CustomResourceDefinitionSpec)1