Skip to content

Commit

Permalink
add size limit to emptydir (#228)
Browse files Browse the repository at this point in the history
* add size limit to emptydir

Signed-off-by: vsoch <[email protected]>
  • Loading branch information
vsoch authored Jun 29, 2024
1 parent aaf6ec9 commit 2412b6e
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 2 deletions.
4 changes: 4 additions & 0 deletions api/v1alpha2/minicluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ type ContainerVolume struct {
// +optional
EmptyDirMedium string `json:"emptyDirMedium,omitempty"`

// Add an empty directory sizeLimit
// +optional
EmptyDirSizeLimit string `json:"emptyDirSizeLimit,omitempty"`

// +kubebuilder:default=false
// +default=false
// +optional
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha2/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@
"description": "Add an empty directory custom type",
"type": "string"
},
"emptyDirSizeLimit": {
"description": "Add an empty directory sizeLimit",
"type": "string"
},
"hostPath": {
"description": "An existing hostPath to bind to path",
"type": "string"
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha2/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions chart/templates/minicluster-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ spec:
emptyDirMedium:
description: Add an empty directory custom type
type: string
emptyDirSizeLimit:
description: Add an empty directory sizeLimit
type: string
hostPath:
description: An existing hostPath to bind to path
type: string
Expand Down Expand Up @@ -732,6 +735,9 @@ spec:
emptyDirMedium:
description: Add an empty directory custom type
type: string
emptyDirSizeLimit:
description: Add an empty directory sizeLimit
type: string
hostPath:
description: An existing hostPath to bind to path
type: string
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/flux-framework.org_miniclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ spec:
emptyDirMedium:
description: Add an empty directory custom type
type: string
emptyDirSizeLimit:
description: Add an empty directory sizeLimit
type: string
hostPath:
description: An existing hostPath to bind to path
type: string
Expand Down Expand Up @@ -735,6 +738,9 @@ spec:
emptyDirMedium:
description: Add an empty directory custom type
type: string
emptyDirSizeLimit:
description: Add an empty directory sizeLimit
type: string
hostPath:
description: An existing hostPath to bind to path
type: string
Expand Down
5 changes: 5 additions & 0 deletions controllers/flux/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
api "github.com/flux-framework/flux-operator/api/v1alpha2"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
)

// Shared function to return consistent set of volume mounts
Expand Down Expand Up @@ -147,6 +148,10 @@ func getExistingVolumes(existing map[string]api.ContainerVolume) []corev1.Volume
},
},
}
if volumeMeta.EmptyDirSizeLimit != "" {
sizeLimit := resource.MustParse(volumeMeta.EmptyDirSizeLimit)
newVolume.VolumeSource.EmptyDir.SizeLimit = &sizeLimit
}

} else if volumeMeta.HostPath != "" {
newVolume = corev1.Volume{
Expand Down
11 changes: 10 additions & 1 deletion docs/getting_started/custom-resource-definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,16 @@ spec:
```

The default binds to the path `/dev/shm` and is not customizable. This can be changed if needed. When you have the "memory" medium added,
you should see all the shared memory from the host, which is [calculated here](https://github.com/kubernetes/kubernetes/blob/e6616033cb844516b1e91b3ec7cd30f8c5d1ea50/pkg/volume/emptydir/empty_dir.go#L148-L157).
you should see all the shared memory from the host, which is [calculated here](https://github.com/kubernetes/kubernetes/blob/e6616033cb844516b1e91b3ec7cd30f8c5d1ea50/pkg/volume/emptydir/empty_dir.go#L148-L157). In addition, you can set a sizeLimit:

```yaml
# must be lowercase!
my-empty-dir:
emptyDir: true
emptyDirMedium: "memory"
sizeLimit: "64Gi"
```

As an example, here is output from a local run with kind when shared memory is added:

```console
Expand Down
6 changes: 6 additions & 0 deletions examples/dist/flux-operator-arm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ spec:
emptyDirMedium:
description: Add an empty directory custom type
type: string
emptyDirSizeLimit:
description: Add an empty directory sizeLimit
type: string
hostPath:
description: An existing hostPath to bind to path
type: string
Expand Down Expand Up @@ -741,6 +744,9 @@ spec:
emptyDirMedium:
description: Add an empty directory custom type
type: string
emptyDirSizeLimit:
description: Add an empty directory sizeLimit
type: string
hostPath:
description: An existing hostPath to bind to path
type: string
Expand Down
6 changes: 6 additions & 0 deletions examples/dist/flux-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ spec:
emptyDirMedium:
description: Add an empty directory custom type
type: string
emptyDirSizeLimit:
description: Add an empty directory sizeLimit
type: string
hostPath:
description: An existing hostPath to bind to path
type: string
Expand Down Expand Up @@ -741,6 +744,9 @@ spec:
emptyDirMedium:
description: Add an empty directory custom type
type: string
emptyDirSizeLimit:
description: Add an empty directory sizeLimit
type: string
hostPath:
description: An existing hostPath to bind to path
type: string
Expand Down
1 change: 1 addition & 0 deletions sdk/python/v1alpha2/docs/ContainerVolume.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Name | Type | Description | Notes
**config_map_name** | **str** | Config map name if the existing volume is a config map You should also define items if you are using this | [optional]
**empty_dir** | **bool** | | [optional] [default to False]
**empty_dir_medium** | **str** | Add an empty directory custom type | [optional]
**empty_dir_size_limit** | **str** | Add an empty directory sizeLimit | [optional]
**host_path** | **str** | An existing hostPath to bind to path | [optional]
**items** | **dict[str, str]** | Items (key and paths) for the config map | [optional]
**path** | **str** | Path and claim name are always required if a secret isn&#39;t defined | [optional]
Expand Down
30 changes: 29 additions & 1 deletion sdk/python/v1alpha2/fluxoperator/models/container_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ContainerVolume(object):
'config_map_name': 'str',
'empty_dir': 'bool',
'empty_dir_medium': 'str',
'empty_dir_size_limit': 'str',
'host_path': 'str',
'items': 'dict[str, str]',
'path': 'str',
Expand All @@ -52,14 +53,15 @@ class ContainerVolume(object):
'config_map_name': 'configMapName',
'empty_dir': 'emptyDir',
'empty_dir_medium': 'emptyDirMedium',
'empty_dir_size_limit': 'emptyDirSizeLimit',
'host_path': 'hostPath',
'items': 'items',
'path': 'path',
'read_only': 'readOnly',
'secret_name': 'secretName'
}

def __init__(self, claim_name=None, config_map_name=None, empty_dir=False, empty_dir_medium=None, host_path=None, items=None, path=None, read_only=False, secret_name=None, local_vars_configuration=None): # noqa: E501
def __init__(self, claim_name=None, config_map_name=None, empty_dir=False, empty_dir_medium=None, empty_dir_size_limit=None, host_path=None, items=None, path=None, read_only=False, secret_name=None, local_vars_configuration=None): # noqa: E501
"""ContainerVolume - a model defined in OpenAPI""" # noqa: E501
if local_vars_configuration is None:
local_vars_configuration = Configuration.get_default_copy()
Expand All @@ -69,6 +71,7 @@ def __init__(self, claim_name=None, config_map_name=None, empty_dir=False, empty
self._config_map_name = None
self._empty_dir = None
self._empty_dir_medium = None
self._empty_dir_size_limit = None
self._host_path = None
self._items = None
self._path = None
Expand All @@ -84,6 +87,8 @@ def __init__(self, claim_name=None, config_map_name=None, empty_dir=False, empty
self.empty_dir = empty_dir
if empty_dir_medium is not None:
self.empty_dir_medium = empty_dir_medium
if empty_dir_size_limit is not None:
self.empty_dir_size_limit = empty_dir_size_limit
if host_path is not None:
self.host_path = host_path
if items is not None:
Expand Down Expand Up @@ -185,6 +190,29 @@ def empty_dir_medium(self, empty_dir_medium):

self._empty_dir_medium = empty_dir_medium

@property
def empty_dir_size_limit(self):
"""Gets the empty_dir_size_limit of this ContainerVolume. # noqa: E501
Add an empty directory sizeLimit # noqa: E501
:return: The empty_dir_size_limit of this ContainerVolume. # noqa: E501
:rtype: str
"""
return self._empty_dir_size_limit

@empty_dir_size_limit.setter
def empty_dir_size_limit(self, empty_dir_size_limit):
"""Sets the empty_dir_size_limit of this ContainerVolume.
Add an empty directory sizeLimit # noqa: E501
:param empty_dir_size_limit: The empty_dir_size_limit of this ContainerVolume. # noqa: E501
:type empty_dir_size_limit: str
"""

self._empty_dir_size_limit = empty_dir_size_limit

@property
def host_path(self):
"""Gets the host_path of this ContainerVolume. # noqa: E501
Expand Down

0 comments on commit 2412b6e

Please sign in to comment.