Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make it possible to customize k8s resources #686

Merged
merged 1 commit into from
Jun 28, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Every user-facing change should have an entry in this changelog. Please respect
-->

## Unreleased
- [Improvement] Make it possible to override k8s resources in plugins using `k8s-override` patch. (by @foadlind)

## v14.0.2 (2022-06-27)

Expand Down
27 changes: 27 additions & 0 deletions docs/k8s.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,30 @@ Updating docker images
Kubernetes does not provide a single command for updating docker images out of the box. A `commonly used trick <https://github.com/kubernetes/kubernetes/issues/33664>`__ is to modify an innocuous label on all resources::

kubectl patch -k "$(tutor config printroot)/env" --patch "{\"spec\": {\"template\": {\"metadata\": {\"labels\": {\"date\": \"`date +'%Y%m%d-%H%M%S'`\"}}}}}"


.. _customizing_kubernetes_sources:

Customizing Kubernetes resources
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Plugins can customize any Kubernetes resource in Tutor by overriding the definition of the resource with a :patch:`k8s-override` patch. For example, to change the volume size for MongoDB from ``5Gi`` to ``10Gi``, add the following to the plugin:

::

# myplugin/tutormyplugin/patches/k8s-override

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mongodb
labels:
app.kubernetes.io/component: volume
app.kubernetes.io/name: mongodb
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi

18 changes: 18 additions & 0 deletions docs/reference/patches.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ File: ``k8s/deployments.yml``

File: ``k8s/jobs.yml``

.. patch:: k8s-override

``k8s-override``
================

File: ``k8s/override.yml``

Any Kubernetes resource definition in this patch will override the resource defined by Tutor, provided that their names match. See :ref:`Customizing Kubernetes resources <customizing_kubernetes_sources>` for an example.

.. patch:: k8s-services

``k8s-services``
Expand Down Expand Up @@ -125,6 +134,15 @@ File: ``kustomization.yml``

File: ``kustomization.yml``

.. patch:: kustomization-patches-strategic-merge

``kustomization-patches-strategic-merge``
=========================================

File: ``kustomization.yml``

This can be used to add more Kustomization patches that make use of the `strategic merge mechanism <https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/#customizing>`__.

.. patch:: kustomization-resources

``kustomization-resources``
Expand Down
1 change: 1 addition & 0 deletions tutor/templates/k8s/override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ patch("k8s-override") }}
4 changes: 4 additions & 0 deletions tutor/templates/kustomization.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@ configMapGenerator:
app.kubernetes.io/name: redis
{{ patch("kustomization-configmapgenerator") }}

patchesStrategicMerge:
- k8s/override.yml
{{ patch("kustomization-patches-strategic-merge") }}

{{ patch("kustomization") }}