0

I've started work on a little Discord bot hosted OpenShift Online, and I've gotten to the point where I'm trying to persist data across deployments. As far as I can tell, I should be able to create persistent volume, claim it and mount it in my deployment config, and then be able to read from and write to it.

I cannot for the life of me get past an issue with permissions though. The closest answer I've found is setting the OPENSHIFT_DATA_DIR environment variable to the mounted volume's directory, as discussed tangentially here, but I still get access denied when trying to write to that directory.

Repository: https://github.com/Solesaver/Alfred-Discord-Bot

Text Dump of Deployment Config: https://dumptext.com/RBDbnfcP

I've made a persistent volume and claim with Access Modes Read-Write-Once, the deployment configuration has it mounted at /data in read-write mode. I've added to the deployment's environment a variable with name OPENSHIFT_DATA_DIR and value /data.

No matter what combination I've tried so far, I always end up with access denied when I hit line 123 of bot.js:

fs.writeFileSync(howmanyPath, JSON.stringify(howmanyObj, null, 4), 'utf8');

At the end of the day all I really need to figure out is how to specify a directory that the arbitrary user OpenShift launches my app as has read/write permissions to. I'm pretty sure once I figure that out I can mount the persistent volume to whatever that ends up being.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134

1 Answers1

0

If you mount a persistent volume under a directory path (by specifying this in the deployment config), the arbitrary user that OpenShift is using to launch your container would have access to that directory. You can check it by opening a remote shell in the running container (oc get po, check the pod name and use it in oc rsh <pod_name>, then ls -la <mount_path>).

The problem could be in how you specify the actual path in your source code. It looks like it should have worked in this commit (providing the deployment config was the same at that time). In more recent commits, the path looks to be hardcoded to be relative to the current dir, so these should throw permission denied when attempting to create a directory with the referenced deployment config that mounts the persistent volume under the /data path, but should work with /opt/app-root/src/data mount path.

If this does not help you troubleshoot the situation, consider adding full error message with a stack trace to your question.

Jiri Fiala
  • 1,400
  • 7
  • 10