Java Code Examples for io.fabric8.kubernetes.client.ResourceHandler#create()

The following examples show how to use io.fabric8.kubernetes.client.ResourceHandler#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableImpl.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Override
public HasMetadata createOrReplace() {
  HasMetadata meta = acceptVisitors(asHasMetadata(item), visitors);
  ResourceHandler<HasMetadata, HasMetadataVisitiableBuilder> h = handlerOf(meta);
  HasMetadata r = h.reload(client, config, meta.getMetadata().getNamespace(), meta);
  String namespaceToUse = meta.getMetadata().getNamespace();

  if (r == null) {
    return h.create(client, config, namespaceToUse, meta);
  } else if (deletingExisting) {
    Boolean deleted = h.delete(client, config, namespaceToUse, propagationPolicy, meta);
    if (!deleted) {
      throw new KubernetesClientException("Failed to delete existing item:" + meta);
    }
    return h.create(client, config, namespaceToUse, meta);
  } else if (ResourceCompare.equals(r, meta)) {
    LOGGER.debug("Item has not changed. Skipping");
    return meta;
  } else {
    return h.replace(client, config, namespaceToUse, meta);
  }
}
 
Example 2
Source File: KubernetesListOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
private <T extends HasMetadata, V extends VisitableBuilder<T, V>> T create(T resource) {
  ResourceHandler<T, V> handler = Handlers.get(resource.getKind(), resource.getApiVersion());
  if (handler != null) {
    return handler.create(client, config, namespace, resource);
  }
  throw new IllegalStateException("Could not find handler");
}