elegant way to enable cross origin resource sharing?
Hi guys,
First of all thanks for everybody working on this operator, it was quite easy to use even for a Solr noob like me :)
I need to access my solr cloud from an angular Application and am running into cross origin errors. The easiest way to enable cross origin resource sharing seems to be to edit the web.xml / webdefault.xml: http://laurenthinoul.com/how-to-enable-cors-in-solr/
On a regular deployment directly in Docker or on a VM this is easily done, but using Kubernetes and the operator it seems there is no easy way to do this and I might have to build a custom solr image.
Figured I asked if somebody else is running the operator and found an elegant solution to enable CORS?
Thanks in advance, Thomas
I have not done this, but you might be able to use a custom volume in the Solr container and overwrite the web.xml / webdefault.xml.
The option you want to look at is SolrCloud.Spec.customSolrKubeOptions.podOptions.volumes
For anyone interested in a guide.
-
Create a custom
web.xml- Get the default web.xml from solr's repository or from your container at
/opt/solr-9.7.0/server/solr-webapp/webapp/WEB-INF/web.xml( make sure to put the correct version ) - follow https://laurenthinoul.com/how-to-enable-cors-in-solr/ to do the required changes
- Get the default web.xml from solr's repository or from your container at
-
Create a ConfigMap that contains the new web.xml file. You can do this by running the following command:
kubectl create configmap custom-web-xml --from-file=web.xml={{path/to/your/web.xml on machine running kubectl}}
- Attach a volume to solr containers
In SolrCloud resource file, create a new volume under SolrCloud.spec.customSolrKubeOptions.podOptions.volumes as follows:
# specs: https://apache.github.io/solr-operator/docs/solr-cloud/solr-cloud-crd.html
apiVersion: solr.apache.org/v1beta1
kind: SolrCloud
metadata:
name: search-cluster
spec:
# <new config>
customSolrKubeOptions:
podOptions:
# override /opt/solr-9.7.0/server/solr-webapp/webapp/WEB-INF/web.xml with custom web.xml to enable CORS
volumes:
- name: custom-web-xml-volume
source:
configMap:
name: custom-web-xml
items:
- key: web.xml
path: web.xml
defaultContainerMount:
name: custom-web-xml-volume
mountPath: /opt/solr-9.7.0/server/solr-webapp/webapp/WEB-INF/web.xml # ! match solr version
subPath: web.xml
readOnly: true
# </new config>
# rest of the file ....
replicas: 2
solrJavaMem: -Xms512M -Xmx1G
solrImage:
tag: 9.7.0
- Apply changes
- Verify
get one of your pods' names, and verify that it has the new xml file:
kubectl exec -it <solr-pod-name> -- cat /opt/solr-9.7.0/server/solr-webapp/webapp/WEB-INF/web.xml
We really need a better way to support CORS than hacking web.xml. We need some environment or solr.xml or something settings!