use of io.kubernetes.client.models.V1beta1CustomResourceDefinition 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();
}
Aggregations