Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
[id="mounting-additional-files-in-your-custom-configuration-using-rhdh-operator"]
= Mounting additional files in your custom configuration by using the {product} Operator

You can use the {product-short} Operator to mount extra files, such as a ConfigMap or Secret, to the container in a preferred location.
You can mount extra files, such as a ConfigMaps, Secrets or PVCs and inject environment variables into your {product-very-short} containers by configuring the `extraFiles` and `extraEnvs` fields in your `{product-custom-resource-type}` custom resource (CR).

By default, files mount only to the `backstage-backend` container, but you can target other containers explicitly using the `containers` field.

The `mountPath` field specifies the location where a ConfigMap or Secret is mounted.
The behavior of the mount, whether it includes or excludes a `subPath`, depends on the specification of the `key` or `mountPath` fields.
Expand Down Expand Up @@ -55,27 +57,124 @@ StringData:
+
For more information, see xref:provisioning-your-custom-configuration[Provisioning and using your custom {product} configuration].

. Set the value of the `configMaps name` to the name of the ConfigMap or `secrets name` to the name of the Secret in your `{product-custom-resource-type}` CR.
For example:
. Apply the configuration to your `{product-custom-resource-type}` CR by setting the values for `extraFiles` and `extraEnvs`.
+
[source,yaml,subs="+attributes,+quotes"]
[source,yaml]
----
spec:
application:
extraFiles:
mountPath: /my/path
mountPath: _<default_mount_path>_
configMaps:
- name: {my-extra-file-configmap}
key: file12.txt
mountPath: /my/my-rhdh-config-map/path
- name: _<configmap_name_all_entries>_
- name: _<configmap_name_single_key>_
key: _<specific_file_key>_
containers:
- "*"
- name: _<configmap_name_custom_path>_
mountPath: _<custom_cm_mount_path>_
containers:
- backstage-backend
- install-dynamic-plugins
secrets:
- name: `_<my_product_secrets>_`
key: secret11.txt
mountPath: /my/my-rhdh-secret/path
- name: _<secret_name_single_key>_
key: _<specific_secret_key>_
containers:
- install-dynamic-plugins
- name: _<secret_name_custom_path>_
mountPath: _<custom_secret_mount_path>_
pvcs:
- name: _<pvc_name_default_path>_
- name: _<pvc_name_custom_path>_
mountPath: _<custom_pvc_mount_path>_
extraEnvs:
configMaps:
- name: _<configmap_name_env_var>_
key: _<env_var_key>_
containers:
- "*"
secrets:
- name: _<secret_name_all_envs>_
envs:
- name: _<static_env_var_name>_
value: "_<static_env_var_value>_"
containers:
- install-dynamic-plugins
----
where:

`spec.application.extraFiles.mountPath`:: Specifies the default base mount path for files if no specific `mountPath` is set for a resource (for example, `/<default_mount_path>`).
`spec.application.extraFiles.configMaps.name`:: Mounts all entries from `<configmap_name_all_entries>` to the default mount path.
`spec.application.extraFiles.configMaps.key`:: Mounts **only the specified key (for example, `<specific_file_key>.txt`) from the ConfigMap.
`spec.application.extraFiles.configMaps.containers`:: Targets all containers (`"*"`) for mounting.
`spec.application.extraFiles.configMaps.mountPath`:: Overrides the default and mounts all ConfigMap entries as a directory at the specified path (for example, `/<custom_cm_mount_path>`).
`spec.application.extraFiles.secrets.key`:: Mounts only a specific key from the Secret.
`spec.application.extraFiles.secrets.mountPath`:: Overrides the default and mounts all Secret entries as a directory at the specified path (for example, `/<custom_secret_mount_path>`).
`spec.application.extraFiles.pvcs.name`:: Mounts the PVC to the default mount path, appending the PVC name (for example, `/<default_mount_path>/<pvc_name_default_path>`).
`spec.application.extraFiles.pvcs.mountPath`:: Overrides the default and mounts the PVC to the specified path (for example, `/<custom_pvc_mount_path>`).
`spec.application.extraEnvs.configMaps.containers`:: Injects the specified ConfigMap key as an environment variable into all containers (`"*"`).
`spec.application.extraEnvs.secrets.name`:: Injects all keys from the Secret as environment variables into the default container.
`spec.application.envs.containers`:: Targets only the listed container for the static environment variable injection.
+
[NOTE]
====
`_<my_product_secrets>_` is your preferred {product-short} secret name, specifying the identifier for your secret configuration within {product-short}.
**Container Targeting:**
* **No** or an empty `containers` field: Targets the `backstage-backend` container (default).
* `*` (asterisk): Targets all containers.
* Explicit container names (e.g., `install-dynamic-plugins`): Targets only the listed containers.
====

.Verification

Verify that the files are mounted with the following correct paths and container targets:

[cols="1,2,3,2", options="header"]
|===
| Resource | Target Type | Path(s) or Name(s) | Container(s)

| ConfigMap (`<configmap_name_all_entries>`)
| File
| `/<default_mount_path>/<file_1_key>`, `/<default_mount_path>/<file_2_key>`
| `backstage-backend`

| ConfigMap (`<configmap_name_single_key>`)
| File
| `/<default_mount_path>/<specific_file_key>.txt`
| All

| ConfigMap (`<configmap_name_custom_path>`)
| Directory
| `/<custom_cm_mount_path>/`
| `backstage-backend`, `install-dynamic-plugins`

| Secret (`<secret_name_single_key>`)
| File
| `/<default_mount_path>/<specific_secret_key>.txt`
| `install-dynamic-plugins`

| Secret (`<secret_name_custom_path>`)
| Directory
| `/<custom_secret_mount_path>/`
| `backstage-backend`

| PVC (`<pvc_name_default_path>`)
| Directory
| `/<default_mount_path>/<pvc_name_default_path>`
| `backstage-backend`

| ConfigMap (`<configmap_name_env_var>`)
| Env Var
| `<env_var_key>`
| All

| Secret (`<secret_name_all_envs>`)
| Env Var
| `<secret_key_a>`, `<secret_key_b>`
| `backstage-backend`

| CRD (`envs`)
| Env Var
| `<static_env_var_name> = <static_env_var_value>`
| `install-dynamic-plugins`
|===