jupyterhub / kubespawner

Kubernetes spawner for JupyterHub
https://jupyterhub-kubespawner.readthedocs.io
BSD 3-Clause "New" or "Revised" License
550 stars 304 forks source link

Failing to override volume_mounts with readOnly set to True #344

Closed fersarr closed 5 years ago

fersarr commented 5 years ago

I am trying to use kubespawner_override to mount a volume with readOnly set to true. But I cannot seem to get it right after trying different possibilities:

c.KubeSpawner.profile_list.append({
    'kubespawner_override': {
        'volumes': [
            {
                'name': 'mytest',
                'hostPath': {
                    'path': '/my/path',
                    'type': 'Directory',
                    'readOnly': 'true' # tried True, 'true', 1, etc.
                }
            }
        ],
        volume_mounts: [
            {
                'name': 'mytest',
                'mountPath': '/my/path',
            }
        ]
    }
})

readOnly is one of the options mentioned in the kubernetes docs

According to kubespawner_override docs, these options are passed to kubernetes but how exactly should this be done?

The error I keep getting is:

spec.containers[0].volumeMounts[1].readOnly: Invalid value: false: must be read-only

Indicating that the True value is not being set.

manics commented 5 years ago

In the docs you linked readOnly is under volumeMounts not volumes, does that make a difference?

fersarr commented 5 years ago

You are absolutely right! it made all the difference! Sorry and Thank you!

it worked by using:

              'volume_mounts': [
                  {
                      'mountPath': '/mytest',
                      'name': 'mytest',
                      'readOnly': True
                  },
skabbit commented 7 months ago

more details regarding the bug - KubeSpawner is based on kubernetes_asyncio specification. I checked their docs and it has this difference: https://kubernetes-asyncio.readthedocs.io/en/latest/kubernetes_asyncio.client.models.v1_volume_mount.html - has read_only https://kubernetes-asyncio.readthedocs.io/en/latest/kubernetes_asyncio.client.models.v1_volume.html - no read_only

Even when Kube API supports read_only in both interfaces, with this package it only works for volume_mount attribute.