Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -517,21 +517,33 @@ Then add your static files using volume patches. For local deployments, use the
)
)

For Kubernetes deployments, use the ``mfe-k8s-volumes`` patch:
For Kubernetes deployments, use the ``mfe-k8s-volumes`` patch to define the volumes you need, and mount them using the ``mfe-k8s-volume-mounts`` patch:

For example, to mount a ConfigMap at ``/usr/share/caddy/myfiles`` so it’s served at ``/myfiles/*``:

.. code-block:: python

hooks.Filters.ENV_PATCHES.add_item(
(
"mfe-k8s-volumes",
"""
# Add your custom volume definition here. This can be any valid Kubernetes volume type.
- name: myfiles-volume
configMap:
name: myfiles-configmap
...
"""
)
from tutor import hooks

hooks.Filters.ENV_PATCHES.add_items(
[
(
"mfe-k8s-volumes",
"""
- name: myfiles-volume
configMap:
name: myfiles-configmap
"""
),
(
"mfe-k8s-volume-mounts",
"""
- name: myfiles-volume
mountPath: /usr/share/caddy/myfiles
readOnly: true
"""
),
]
)

Your static files will be accessible at ``http(s)://{{ MFE_HOST }}/myfiles/``.
Expand Down Expand Up @@ -847,6 +859,14 @@ Add volumes to the mfe deployment in Kubernetes.
File changed: ``k8s/deployments.yml``


mfe-k8s-volume-mounts
~~~~~~~~~~~~~~~~~~~~~

Add volume mounts to the ``mfe`` container in the Kubernetes deployment. Use this together with ``mfe-k8s-volumes`` to attach and mount custom volumes (e.g., ConfigMaps, PVCs) inside the container.

File changed: ``k8s/deployments.yml``


caddyfile-mfe-proxy
~~~~~~~~~~~~~~~~~~~

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- [Feature] Add `mfe-k8s-volume-mounts` patch to mount volumes in the MFE Kubernetes Deployment, complementing `mfe-k8s-volumes`. (by @andres.giraldo)
3 changes: 3 additions & 0 deletions tutormfe/patches/k8s-deployments
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ spec:
volumeMounts:
- mountPath: /etc/caddy/
name: config
{%- if MFE_HOST_EXTRA_FILES %}
{{ patch("mfe-k8s-volume-mounts") | indent(12) }}
{%- endif %}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can mfe-k8s-volume-mounts and mfe-k8s-volumes be merged in a single patch?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DawoudSheraz, thanks for your quick review!

I don’t think it’s really possible to unify them, since the volumes and volumeMounts blocks live in different parts of the Deployment spec. Each patch hook only injects into a single position, so combining them wouldn’t work. Also, they cover two different concerns, so keeping them separate helps maintain a clear separation of responsibilities.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. If you look at deployments.yml template in tutor, it has a k8s-deployments patch applied at the end of file (https://github.com/overhangio/tutor/blob/release/tutor/templates/k8s/deployments.yml#L483). The idea is that if one wants to customize the deployment, they can do so using this patch. Won't a similar pattern work here? In the new patch, we can define the volume and volume mount. Sorry if I am missing some k8s technical context here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DawoudSheraz The pattern you mentioned is designed for injecting complete resources through patches like k8s-deployments. That works when we’re defining entire Deployments or sections of the spec, but here, our goal is simply to add to the MFE deployment.

The two patches target different parts of the Deployment spec:

  • mfe-k8s-volumes injects volume definitions under spec.template.spec.volumes
  • mfe-k8s-volume-mounts injects mounts under spec.template.spec.containers[].volumeMounts

A merge could theoretically work if the sections were adjacent but we have the config volume defined in between.
Even if they were next to each other, they still require different indentation and context (one at the pod level, the other inside a container).

It would be ideal to declare volumes and mount them together, but given Kubernetes’s structure, it’s necessary to keep them separated.

Let me know if I’ve captured your idea correctly, or if there’s anything else you’d like to comment on!

volumes:
- name: config
configMap:
Expand Down