How do I ignore the error MountVolume.SetUp failed for volume "cofigmap-volume" : configmaps "configmap" not found

9/30/2019

I've mounted the configmap in my deployment file but conditionally create a configmap through oc create configmap command during deployment. Is there a way I could mount the path in my deployment.yaml but when configmap is not there it can ignore that error and bring up the pods any how.

-- Abc
kubernetes
openshift

2 Answers

9/30/2019

Writing CRD and CRD controller for your app can solve this. You can deploy the yaml for your crd, the controller will check whether there exist a configmap or not. Depending on the result, the controller will change the deployment yaml and deploy it.

-- Kamol Hasan
Source: StackOverflow

9/30/2019

Please refer to ConfigMapVolumeSource and ValidatingWebhookConfiguration you can find optional parameter:

Specify whether the ConfigMap or it's keys must be define

So please try and add "optional: true" in your volumes configmap properties:

volumes:
    - name: config-volume
      configMap:
        # Provide the name of the ConfigMap containing the files you want
        # to add to the container
        name: special-config
        optional: true

Note:

Restrictions:

You must create a ConfigMap before referencing it in a Pod specification (unless you mark the ConfigMap as “optional”). If you reference a ConfigMap that doesn’t exist, the Pod won’t start. Likewise, references to keys that don’t exist in the ConfigMap will prevent the pod from starting.

Please let me know if it helped.

-- Hanx
Source: StackOverflow