Limit Ranges, global setting and per namespace

This commit is contained in:
Laszlo Fogas
2020-11-03 12:53:28 +01:00
parent a0f85ca45f
commit 58e05050b7
11 changed files with 185 additions and 68 deletions
+1 -1
View File
@@ -15,4 +15,4 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0
version: 0.2.0
+27 -8
View File
@@ -1,25 +1,44 @@
{{- range .Values.namespaces }}
{{- $limits := $.Values.pod.limits }}
{{- if .pod }}
{{- if .pod.limits }}
{{- $limits = .pod.limits }}
{{- end }}
{{- end }}
{{- $overcommit := $.Values.pod.overcommit }}
{{- if .pod }}
{{- if .pod.overcommit }}
{{- $overcommit = .pod.overcommit }}
{{- end }}
{{- end }}
{{- $defaults := $.Values.pod.defaults }}
{{- if .pod }}
{{- if .pod.defaults }}
{{- $defaults = .pod.defaults }}
{{- end }}
{{- end }}
---
apiVersion: v1
kind: LimitRange
metadata:
name: resource-limits
name: {{ .name }}
namespace: {{ .name }}
spec:
limits:
- type: Container
max:
cpu: "4"
cpu: 4
memory: "8Gi"
min:
cpu: "100m"
memory: "50Mi"
default:
cpu: "300m"
memory: "200Mi"
cpu: {{ $defaults.cpu }}
memory: {{ $defaults.memory }}
defaultRequest:
cpu: "200m"
memory: "200Mi"
cpu: {{ $defaults.cpu }}
memory: {{ $defaults.memory }}
maxLimitRequestRatio:
cpu: "10"
memory: "1"
cpu: {{ $overcommit.cpu }}
memory: {{ $overcommit.memory }}
{{- end }}
@@ -1,7 +1,15 @@
{{- range .Values.namespaces }}
{{- $budget := $.Values.budget }}
{{- if .budget }}
{{- $budget = .budget }}
{{- $budget := $.Values.namespace.budget }}
{{- if .namespace }}
{{- if .namespace.budget }}
{{- $budget = .namespace.budget }}
{{- end }}
{{- end }}
{{- $overcommit := $.Values.namespace.overcommit }}
{{- if .namespace }}
{{- if .namespace.overcommit }}
{{- $overcommit = .namespace.overcommit }}
{{- end }}
{{- end }}
---
apiVersion: v1
@@ -10,8 +18,8 @@ metadata:
name: {{ .name }}
spec:
hard:
limits.cpu: {{ $budget.cpu | mul $.Values.overcommit.cpu }}
limits.memory: {{ $budget.memory | regexFind "[1-9]+" | mul $.Values.overcommit.memory }}{{ $budget.memory | regexFind "[a-zA-Z]+" }}
limits.cpu: {{ $budget.cpu | mul $overcommit.cpu }}
limits.memory: {{ $budget.memory | regexFind "[1-9]+" | mul $overcommit.memory }}{{ $budget.memory | regexFind "[a-zA-Z]+" }}
requests.cpu: {{ $budget.cpu }}
requests.memory: {{ $budget.memory }}
requests.storage: {{ $budget.storage }}
@@ -0,0 +1,70 @@
suite: test deployment
templates:
- limit-range.yaml
tests:
- it: Should set default limits
set:
pod:
limits:
cpu: 4
memory: "8Gi"
defaults:
cpu: "200m"
memory: "200Mi"
overcommit:
cpu: 10
memory: 2
asserts:
- equal:
path: spec.limits
value:
- type: Container
max:
cpu: 4
memory: "8Gi"
min:
cpu: "100m"
memory: "50Mi"
default:
cpu: "200m"
memory: "200Mi"
defaultRequest:
cpu: "200m"
memory: "200Mi"
maxLimitRequestRatio:
cpu: 10
memory: 2
- it: Should set namespace specific limits
set:
namespaces:
- name: staging
pod:
limits:
cpu: 4
memory: "8Gi"
defaults:
cpu: "200m"
memory: "200Mi"
overcommit:
cpu: 10
memory: 2
asserts:
- equal:
path: spec.limits
value:
- type: Container
max:
cpu: 4
memory: "8Gi"
min:
cpu: "100m"
memory: "50Mi"
default:
cpu: "200m"
memory: "200Mi"
defaultRequest:
cpu: "200m"
memory: "200Mi"
maxLimitRequestRatio:
cpu: 10
memory: 2
@@ -4,13 +4,14 @@ templates:
tests:
- it: Should set default quota values
set:
budget:
cpu: 32
memory: "64Gi"
storage: "500Gi"
overcommit:
cpu: 2
memory: 1
namespace:
budget:
cpu: 32
memory: "64Gi"
storage: "500Gi"
overcommit:
cpu: 2
memory: 1
asserts:
- equal:
path: spec.hard
@@ -24,17 +25,19 @@ tests:
set:
namespaces:
- name: staging
budget:
cpu: 8
memory: "16Gi"
storage: "100Gi"
budget:
cpu: 32
memory: "64Gi"
storage: "500Gi"
overcommit:
cpu: 2
memory: 1
namespace:
budget:
cpu: 8
memory: "16Gi"
storage: "100Gi"
namespace:
budget:
cpu: 32
memory: "64Gi"
storage: "500Gi"
overcommit:
cpu: 2
memory: 1
asserts:
- equal:
path: spec.hard
+18 -11
View File
@@ -1,15 +1,22 @@
namespaces:
- name: staging
budget:
cpu: 32
memory: "64Gi"
storage: "500Gi"
namespace:
budget:
cpu: 32
memory: "64Gi"
storage: "500Gi"
overcommit:
cpu: 2
memory: 1
overcommit:
cpu: 2
memory: 1
podOvercommit:
cpu: 10
memory: 2
pod:
limits:
cpu: 4
memory: "8Gi"
defaults:
cpu: "200m"
memory: "200Mi"
overcommit:
cpu: 10
memory: 2