I have a Python code deployed as Knative-functions in which I would like to read a file saved in the local machine under the path '/app/uploads/file.csv'. The Knative cluster is deployed localy using Kind. I would like to have read access of all the files inside '/app/uploads' folder.
What I have so far is:
- python code that attemps to read the file
# (...)
df = csv.read_csv("/app/uploads/file.csv")
# (...)
- func.yaml
specVersion: 0.35.0
name: func-demo
runtime: python
registry: docker.io/<user>
image: docker.io/<user>/func-demo:latest
imageDigest: sha256:aa0b6e014726916253b2b37b83044a8d2b94b362b1087dcb189e2465e13663c6
created: 2023-05-09T13:08:08.390261821+01:00
build:
buildpacks: []
builder: pack
buildEnvs: []
run:
volumes: []
envs: []
deploy:
namespace: default
remote: false
annotations: {}
options: {}
labels: []
healthEndpoints:
liveness: /health/liveness
readiness: /health/readiness
After deploying the python function to the knative local cluster and invoking it I get this error:
Function raised [Errno 2] No such file or directory: '/app/uploads/file.csv'
I also tried definning PersistentVolume and PersistentVolumeClaim in my cluster:
pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: uploads
labels:
type: local
spec:
storageClassName: standard
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
hostPath:
path: "/app/uploads"
pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: uploads-claim
spec:
accessModes:
- ReadWriteOnce
storageClassName: standard
resources:
requests:
storage: 1Gi
and defined the previous func.yaml as:
(...)
run:
volumes:
- persistentVolumeClaim:
claimName: uploads-claim
path: /app/uploads
(...)
but when I deploy the function I get this error:
Error: 'func.yaml' contains errors:
volume entry #0 is missing secret or configMap field, only path '/app/uploads' is set
You need to define mounts and volumes
https://kind.sigs.k8s.io/docs/user/configuration/#extra-mounts