Search in sources :

Example 1 with KubectlCreate

use of io.kubernetes.client.spring.extended.manifests.annotation.KubectlCreate in project java by kubernetes-client.

the class KubernetesKubectlCreateProcessor method postProcessAfterInitialization.

public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    if (!(bean instanceof KubernetesObject)) {
        // no-op
        return bean;
    }
    KubectlCreate create = beanFactory.findAnnotationOnBean(beanName, KubectlCreate.class);
    if (create == null) {
        return bean;
    }
    Class<? extends KubernetesObject> apiTypeClass = (Class<? extends KubernetesObject>) bean.getClass();
    try {
        log.info("@KubectlCreate ensuring resource upon bean {}", beanName);
        return create(apiTypeClass, bean);
    } catch (KubectlException e) {
        if (e.getCause() instanceof ApiException) {
            ApiException apiException = (ApiException) e.getCause();
            if (HttpURLConnection.HTTP_CONFLICT == apiException.getCode()) {
                // already exists
                log.info("Skipped processing {} @KubectlCreate resource already exists", beanName);
                return bean;
            }
        }
        log.error("Failed ensuring resource from @KubectlCreate", e);
        throw new BeanCreationException("Failed ensuring resource from @KubectlCreate", e);
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) KubernetesObject(io.kubernetes.client.common.KubernetesObject) KubectlException(io.kubernetes.client.extended.kubectl.exception.KubectlException) KubectlCreate(io.kubernetes.client.spring.extended.manifests.annotation.KubectlCreate) ApiException(io.kubernetes.client.openapi.ApiException)

Aggregations

KubernetesObject (io.kubernetes.client.common.KubernetesObject)1 KubectlException (io.kubernetes.client.extended.kubectl.exception.KubectlException)1 ApiException (io.kubernetes.client.openapi.ApiException)1 KubectlCreate (io.kubernetes.client.spring.extended.manifests.annotation.KubectlCreate)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1