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);
}
}
Aggregations