0

I have a weird issue and I am running out of ideas. I have an OpenShift deployment but unfortunately I don't hava RBAC access so any rsync and other goodies are not fine for me. Let's sum up... I have a storage created which is shared between 2 applications with path /usr/local/tomcat/fop and I have a build based on image. The image used for the build is previously build as binary build locally on my machine and in its Dockerfile I am adding several files there like:

COPY fop.xconf /usr/local/tomcat/fop/conf/fop.xconf
COPY ExperianPDF2016.gif /usr/local/tomcat/fop/img/
COPY PDF_Transformation.xslt /usr/local/tomcat/fop/transformation/

RUN [ -d /usr/local/tomcat/fop/xml ] || mkdir -p /usr/local/tomcat/fop/xml
RUN [ -d /usr/local/tomcat/fop/reports ] || mkdir -p /usr/local/tomcat/fop/reports
RUN [ -d /usr/local/tomcat/fop/output ] || mkdir -p /usr/local/tomcat/fop/output

So what happens here if I deploy the image without adding storage - it is fine, all files are there but I don't have permission the read/write files and also this won't be shared with the other application. However if I map storage and say that I have mount path of /usr/local/tomcat/fop then I have the folder and it's shared between the apps but it is empty, nothing from the image has gone there.

In our DEV environment I used oc rsync to add the missing files in the folder but in the next environment I don't have RBAC permission and I don't have 'Terminal' access nor rsync.

Any directions for solving this would be much appreciated.

[UPDATE]

As I was advised I can use the Init container approach. Here is my deploy config:

spec:
  containers:
    - image: >-
        docker-registry.default.svc:5000/ob-orc-dev/pdf-maker@sha256:a4eadb602e4afb5bf25cc17b916b848cecc06a05d1cd69000cd84feb70df63bd
      imagePullPolicy: Always
      name: bat-dancho
      ports:
        - containerPort: 8080
          protocol: TCP
      resources: {}
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
      volumeMounts:
        - mountPath: /usr/local/tomcat/fop123
          name: pdf-tst
          subPath: xml
  dnsPolicy: ClusterFirst
  initContainers:
    - command:
        - /bin/sh
        - '-c'
        - cp -R ~/usr/local/tomcat/fop/* ~/usr/local/tomcat/fop123
      image: >-
        docker-registry.default.svc:5000/ob-orc-dev/pdf-maker@sha256:a4eadb602e4afb5bf25cc17b916b848cecc06a05d1cd69000cd84feb70df63bd
      imagePullPolicy: Always
      name: init-myservice
      resources: {}
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
      volumeMounts:
        - mountPath: /usr/local/tomcat/fop123
          name: pdf-tst
          subPath: xml
dnmitev
  • 71
  • 10
  • 2
    A couple of things. Mounting a volume to a directory makes the directory empty (or only contains the pvc files), so this expected. There's no way for kubernetes to merge files into a PV. You could see if you're allowed to define an init_container. This is a container that runs before your _normal_ containers, and can do things like move files, DB migrations, etc. You could try putting your files in a different folder than where you want to mount the PV, then define an init_container that moves the files over as necessary. – Will Gordon May 11 '20 at 14:09
  • Is it correct that I need to point my Init container to the very same image containing my files? – dnmitev May 11 '20 at 16:03
  • 1
    Yes, and you would just override the commands and provide the necessary `mv` or `cp` commands. – Will Gordon May 11 '20 at 20:11
  • Hi, @WillGordon! Thanks a lot for your help, it did the trick. – dnmitev May 12 '20 at 07:29

0 Answers0