fix(common): limit default emptydir size for memory emptyDir (#604)

**Description**
Currently emptyDir ramdisks are set to have unlimited size.
This puts a limit to that, sized in accordance to
.values.resources.limits.memory

Yes this means an App consuming all space in an emptyDir can exceed the
limits, but at least it prevents attacks where host OOMs can be
triggered by oversaturating a memory-backed emptyDir

⚒️ Fixes  #602 

**⚙️ Type of change**

- [ ] ⚙️ Feature/App addition
- [x] 🪛 Bugfix
- [ ] ⚠️ Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] 🔃 Refactor of current code

**🧪 How Has This Been Tested?**
<!--
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration
-->

**📃 Notes:**
<!-- Please enter any other relevant information here -->

**✔️ Checklist:**

- [ ] ⚖️ My code follows the style guidelines of this project
- [ ] 👀 I have performed a self-review of my own code
- [ ] #️⃣ I have commented my code, particularly in hard-to-understand
areas
- [ ] 📄 I have made corresponding changes to the documentation
- [ ] ⚠️ My changes generate no new warnings
- [ ] 🧪 I have added tests to this description that prove my fix is
effective or that my feature works
- [ ] ⬆️ I increased versions for any altered app according to semantic
versioning

** App addition**

If this PR is an app addition please make sure you have done the
following.

- [ ] 🪞 I have opened a PR on
[truecharts/containers](https://github.com/truecharts/containers) adding
the container to TrueCharts mirror repo.
- [ ] 🖼️ I have added an icon in the Chart's root directory called
`icon.png`

---

_Please don't blindly check all the boxes. Read them and only check
those that apply.
Those checkboxes are there for the reviewer to see what is this all
about and
the status of this PR with a quick glance._

---------

Co-authored-by: Stavros kois <s.kois@outlook.com>
Co-authored-by: Stavros Kois <47820033+stavros-k@users.noreply.github.com>
This commit is contained in:
Kjeld Schouten
2023-11-18 12:01:16 +01:00
committed by GitHub
parent 5078e0dfcd
commit 128b52ca6d
4 changed files with 68 additions and 0 deletions

View File

@@ -175,6 +175,7 @@ tests:
name: tmp
emptyDir:
medium: Memory
sizeLimit: 8Gi
- documentIndex: *jobDoc
contains:
path: spec.template.spec.containers[0].volumeMounts
@@ -511,6 +512,7 @@ tests:
name: tmp
emptyDir:
medium: Memory
sizeLimit: 8Gi
- documentIndex: *jobDoc
contains:
path: spec.template.spec.containers[0].volumeMounts

View File

@@ -90,17 +90,21 @@ tests:
- name: devshm
emptyDir:
medium: Memory
sizeLimit: 8Gi
- name: shared
emptyDir: {}
- name: tmp
emptyDir:
medium: Memory
sizeLimit: 8Gi
- name: varlogs
emptyDir:
medium: Memory
sizeLimit: 8Gi
- name: varrun
emptyDir:
medium: Memory
sizeLimit: 8Gi
- documentIndex: *deploymentDoc
isSubset:
path: spec.template.spec.containers[0]

View File

@@ -81,6 +81,7 @@ tests:
name: emptyDir-vol
emptyDir:
medium: Memory
sizeLimit: 8Gi
- it: should pass with emptyDir volume with size set
set:
@@ -107,6 +108,65 @@ tests:
emptyDir:
sizeLimit: 3Gi
- it: should pass with emptyDir volume with medium Memory and size from resource limits
set:
resources:
limits:
memory: 500Mi
workload:
workload-name1:
enabled: true
primary: true
type: Deployment
podSpec: {}
persistence:
emptyDir-vol:
enabled: true
type: emptyDir
medium: Memory
asserts:
- documentIndex: &deploymentDoc 0
isKind:
of: Deployment
- documentIndex: *deploymentDoc
contains:
path: spec.template.spec.volumes
content:
name: emptyDir-vol
emptyDir:
medium: Memory
sizeLimit: 500Mi
- it: should pass with emptyDir volume with medium Memory and size override
set:
resources:
limits:
memory: 500Mi
workload:
workload-name1:
enabled: true
primary: true
type: Deployment
podSpec: {}
persistence:
emptyDir-vol:
enabled: true
type: emptyDir
medium: Memory
size: 1Gi
asserts:
- documentIndex: &deploymentDoc 0
isKind:
of: Deployment
- documentIndex: *deploymentDoc
contains:
path: spec.template.spec.volumes
content:
name: emptyDir-vol
emptyDir:
medium: Memory
sizeLimit: 1Gi
# Failures
- it: should fail with invalid medium in emptyDir
set:

View File

@@ -23,6 +23,8 @@ objectData: The object data to be used to render the volume.
{{- $formats := "(Suffixed with E/P/T/G/M/K - eg. 1G), (Suffixed with Ei/Pi/Ti/Gi/Mi/Ki - eg. 1Gi), (Plain Integer in bytes - eg. 1024), (Exponent - eg. 134e6)" -}}
{{- fail (printf "Persistence Expected [size] to have one of the following formats [%s], but got [%s]" $formats $size) -}}
{{- end -}}
{{- else if eq $medium "Memory" -}}
{{- $size = $rootCtx.Values.resources.limits.memory -}}
{{- end -}}
{{- if and $medium (ne $medium "Memory") -}}