Skip to content

Commit 2412b6e

Browse files
authored
add size limit to emptydir (#228)
* add size limit to emptydir Signed-off-by: vsoch <[email protected]>
1 parent aaf6ec9 commit 2412b6e

File tree

11 files changed

+84
-2
lines changed

11 files changed

+84
-2
lines changed

api/v1alpha2/minicluster_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ type ContainerVolume struct {
255255
// +optional
256256
EmptyDirMedium string `json:"emptyDirMedium,omitempty"`
257257

258+
// Add an empty directory sizeLimit
259+
// +optional
260+
EmptyDirSizeLimit string `json:"emptyDirSizeLimit,omitempty"`
261+
258262
// +kubebuilder:default=false
259263
// +default=false
260264
// +optional

api/v1alpha2/swagger.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@
129129
"description": "Add an empty directory custom type",
130130
"type": "string"
131131
},
132+
"emptyDirSizeLimit": {
133+
"description": "Add an empty directory sizeLimit",
134+
"type": "string"
135+
},
132136
"hostPath": {
133137
"description": "An existing hostPath to bind to path",
134138
"type": "string"

api/v1alpha2/zz_generated.openapi.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chart/templates/minicluster-crd.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ spec:
233233
emptyDirMedium:
234234
description: Add an empty directory custom type
235235
type: string
236+
emptyDirSizeLimit:
237+
description: Add an empty directory sizeLimit
238+
type: string
236239
hostPath:
237240
description: An existing hostPath to bind to path
238241
type: string
@@ -732,6 +735,9 @@ spec:
732735
emptyDirMedium:
733736
description: Add an empty directory custom type
734737
type: string
738+
emptyDirSizeLimit:
739+
description: Add an empty directory sizeLimit
740+
type: string
735741
hostPath:
736742
description: An existing hostPath to bind to path
737743
type: string

config/crd/bases/flux-framework.org_miniclusters.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ spec:
232232
emptyDirMedium:
233233
description: Add an empty directory custom type
234234
type: string
235+
emptyDirSizeLimit:
236+
description: Add an empty directory sizeLimit
237+
type: string
235238
hostPath:
236239
description: An existing hostPath to bind to path
237240
type: string
@@ -735,6 +738,9 @@ spec:
735738
emptyDirMedium:
736739
description: Add an empty directory custom type
737740
type: string
741+
emptyDirSizeLimit:
742+
description: Add an empty directory sizeLimit
743+
type: string
738744
hostPath:
739745
description: An existing hostPath to bind to path
740746
type: string

controllers/flux/volumes.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
api "github.com/flux-framework/flux-operator/api/v1alpha2"
1717

1818
corev1 "k8s.io/api/core/v1"
19+
"k8s.io/apimachinery/pkg/api/resource"
1920
)
2021

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

151156
} else if volumeMeta.HostPath != "" {
152157
newVolume = corev1.Volume{

docs/getting_started/custom-resource-definition.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,16 @@ spec:
12131213
```
12141214

12151215
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,
1216-
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).
1216+
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:
1217+
1218+
```yaml
1219+
# must be lowercase!
1220+
my-empty-dir:
1221+
emptyDir: true
1222+
emptyDirMedium: "memory"
1223+
sizeLimit: "64Gi"
1224+
```
1225+
12171226
As an example, here is output from a local run with kind when shared memory is added:
12181227

12191228
```console

examples/dist/flux-operator-arm.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ spec:
238238
emptyDirMedium:
239239
description: Add an empty directory custom type
240240
type: string
241+
emptyDirSizeLimit:
242+
description: Add an empty directory sizeLimit
243+
type: string
241244
hostPath:
242245
description: An existing hostPath to bind to path
243246
type: string
@@ -741,6 +744,9 @@ spec:
741744
emptyDirMedium:
742745
description: Add an empty directory custom type
743746
type: string
747+
emptyDirSizeLimit:
748+
description: Add an empty directory sizeLimit
749+
type: string
744750
hostPath:
745751
description: An existing hostPath to bind to path
746752
type: string

examples/dist/flux-operator.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ spec:
238238
emptyDirMedium:
239239
description: Add an empty directory custom type
240240
type: string
241+
emptyDirSizeLimit:
242+
description: Add an empty directory sizeLimit
243+
type: string
241244
hostPath:
242245
description: An existing hostPath to bind to path
243246
type: string
@@ -741,6 +744,9 @@ spec:
741744
emptyDirMedium:
742745
description: Add an empty directory custom type
743746
type: string
747+
emptyDirSizeLimit:
748+
description: Add an empty directory sizeLimit
749+
type: string
744750
hostPath:
745751
description: An existing hostPath to bind to path
746752
type: string

sdk/python/v1alpha2/docs/ContainerVolume.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Name | Type | Description | Notes
88
**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]
99
**empty_dir** | **bool** | | [optional] [default to False]
1010
**empty_dir_medium** | **str** | Add an empty directory custom type | [optional]
11+
**empty_dir_size_limit** | **str** | Add an empty directory sizeLimit | [optional]
1112
**host_path** | **str** | An existing hostPath to bind to path | [optional]
1213
**items** | **dict[str, str]** | Items (key and paths) for the config map | [optional]
1314
**path** | **str** | Path and claim name are always required if a secret isn&#39;t defined | [optional]

0 commit comments

Comments
 (0)