Simplifying namespaces chart (#46)

This commit is contained in:
Laszlo Fogas
2022-06-23 13:54:37 +02:00
committed by GitHub
parent 285a6cca10
commit 95b686d20c
12 changed files with 179 additions and 964 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.2.1
version: 0.3.0
+18
View File
@@ -0,0 +1,18 @@
namespaces:
- name: staging
quota:
cpu: 32
memory: "64Gi"
storage: "500Gi"
overcommit:
cpu: 1
memory: 1
podMaximumResources:
cpu: 4
memory: "8Gi"
podDefaultResources:
cpu: "200m"
memory: "200Mi"
podResourceOvercommit:
cpu: 2
memory: 1
+19 -29
View File
@@ -1,22 +1,5 @@
{{- 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 }}
{{- if and .podMaximumResources (and .podDefaultResources .podResourceOvercommit) }}
---
apiVersion: v1
kind: LimitRange
@@ -26,19 +9,26 @@ metadata:
spec:
limits:
- type: Container
{{- if .podMaximumResources }}
max:
cpu: 4
memory: "8Gi"
min:
cpu: "100m"
memory: "50Mi"
cpu: {{ .podMaximumResources.cpu }}
memory: {{ .podMaximumResources.memory }}
{{- end }}
{{- if .podDefaultResources }}
default:
cpu: {{ $defaults.cpu }}
memory: {{ $defaults.memory }}
cpu: {{ .podDefaultResources.cpu }}
memory: {{ .podDefaultResources.memory }}
defaultRequest:
cpu: {{ $defaults.cpu }}
memory: {{ $defaults.memory }}
cpu: {{ .podDefaultResources.cpu }}
memory: {{ .podDefaultResources.memory }}
{{- end }}
maxLimitRequestRatio:
cpu: {{ $overcommit.cpu }}
memory: {{ $overcommit.memory }}
{{- if .podResourceOvercommit }}
cpu: {{ .podResourceOvercommit.cpu }}
memory: {{ .podResourceOvercommit.memory }}
{{ else }}
cpu: 1
memory: 1
{{- end }}
{{- end }}
{{- end }}
@@ -1,16 +1,5 @@
{{- range .Values.namespaces }}
{{- $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 }}
{{- if and .quota .overcommit }}
---
apiVersion: v1
kind: ResourceQuota
@@ -18,9 +7,10 @@ metadata:
name: {{ .name }}
spec:
hard:
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 }}
limits.cpu: {{ .quota.cpu | mul .overcommit.cpu }}
limits.memory: {{ .quota.memory | regexFind "[1-9]+" | mul .overcommit.memory }}{{ .quota.memory | regexFind "[a-zA-Z]+" }}
requests.cpu: {{ .quota.cpu }}
requests.memory: {{ .quota.memory }}
requests.storage: {{ .quota.storage }}
{{- end }}
{{- end -}}
+11 -47
View File
@@ -2,52 +2,19 @@ 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
podMaximumResources:
cpu: 4
memory: "8Gi"
podDefaultResources:
cpu: "200m"
memory: "200Mi"
podResourceOvercommit:
cpu: 2
memory: 1
asserts:
- equal:
path: spec.limits
@@ -56,9 +23,6 @@ tests:
max:
cpu: 4
memory: "8Gi"
min:
cpu: "100m"
memory: "50Mi"
default:
cpu: "200m"
memory: "200Mi"
@@ -66,5 +30,5 @@ tests:
cpu: "200m"
memory: "200Mi"
maxLimitRequestRatio:
cpu: 10
memory: 2
cpu: 2
memory: 1
+3
View File
@@ -11,6 +11,9 @@ tests:
path: metadata.name
value: staging
- it: Should not set annotations if none provided in values
set:
namespaces:
- name: staging
asserts:
- isNull:
path: metadata.annotations
@@ -2,16 +2,37 @@ suite: test deployment
templates:
- resource-quota.yaml
tests:
- it: Should set default quota values
- it: Should set namespace specific quotas
set:
namespace:
budget:
cpu: 32
memory: "64Gi"
storage: "500Gi"
overcommit:
cpu: 2
memory: 1
namespaces:
- name: staging
quota:
cpu: 32
memory: "64Gi"
storage: "500Gi"
overcommit:
cpu: 1
memory: 1
asserts:
- equal:
path: spec.hard
value:
limits.cpu: 32
limits.memory: "64Gi"
requests.cpu: 32
requests.memory: "64Gi"
requests.storage: "500Gi"
- it: Should handle overcommit
set:
namespaces:
- name: staging
quota:
cpu: 32
memory: "64Gi"
storage: "500Gi"
overcommit:
cpu: 2
memory: 1
asserts:
- equal:
path: spec.hard
@@ -21,29 +42,3 @@ tests:
requests.cpu: 32
requests.memory: "64Gi"
requests.storage: "500Gi"
- it: Should set namespace specific quotas
set:
namespaces:
- name: staging
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
value:
limits.cpu: 16
limits.memory: "16Gi"
requests.cpu: 8
requests.memory: "16Gi"
requests.storage: "100Gi"
-715
View File
@@ -1,715 +0,0 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "http://example.com/example.json",
"type": "object",
"title": "The root schema",
"description": "The root schema comprises the entire JSON document.",
"default": {},
"examples": [
{
"namespaces": [
{
"name": "staging",
"namespace": {
"budget": {
"cpu": 32,
"memory": "64Gi",
"storage": "500Gi"
},
"overcommit": {
"cpu": 2,
"memory": 1
}
},
"pod": {
"limits": {
"cpu": 4,
"memory": "8Gi"
},
"defaults": {
"cpu": "200m",
"memory": "200Mi"
},
"overcommit": {
"cpu": 10,
"memory": 2
}
}
}
],
"namespace": {
"budget": {
"cpu": 32,
"memory": "64Gi",
"storage": "500Gi"
},
"overcommit": {
"cpu": 2,
"memory": 1
}
},
"pod": {
"limits": {
"cpu": 4,
"memory": "8Gi"
},
"defaults": {
"cpu": "200m",
"memory": "200Mi"
},
"overcommit": {
"cpu": 10,
"memory": 2
}
}
}
],
"required": [
"namespaces",
"namespace",
"pod"
],
"properties": {
"namespaces": {
"$id": "#/properties/namespaces",
"type": "array",
"title": "The namespaces schema",
"description": "An explanation about the purpose of this instance.",
"default": [],
"examples": [
[
{
"name": "staging",
"namespace": {
"budget": {
"cpu": 32,
"memory": "64Gi",
"storage": "500Gi"
},
"overcommit": {
"cpu": 2,
"memory": 1
}
},
"pod": {
"limits": {
"cpu": 4,
"memory": "8Gi"
},
"defaults": {
"cpu": "200m",
"memory": "200Mi"
},
"overcommit": {
"cpu": 10,
"memory": 2
}
}
}
]
],
"additionalItems": true,
"items": {
"$id": "#/properties/namespaces/items",
"anyOf": [
{
"$id": "#/properties/namespaces/items/anyOf/0",
"type": "object",
"title": "The first anyOf schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"name": "staging",
"namespace": {
"budget": {
"cpu": 32,
"memory": "64Gi",
"storage": "500Gi"
},
"overcommit": {
"cpu": 2,
"memory": 1
}
},
"pod": {
"limits": {
"cpu": 4,
"memory": "8Gi"
},
"defaults": {
"cpu": "200m",
"memory": "200Mi"
},
"overcommit": {
"cpu": 10,
"memory": 2
}
}
}
],
"required": [
"name",
"namespace",
"pod"
],
"properties": {
"name": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/name",
"type": "string",
"title": "The name schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"staging"
]
},
"namespace": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/namespace",
"type": "object",
"title": "The namespace schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"budget": {
"cpu": 32,
"memory": "64Gi",
"storage": "500Gi"
},
"overcommit": {
"cpu": 2,
"memory": 1
}
}
],
"required": [
"budget",
"overcommit"
],
"properties": {
"budget": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/namespace/properties/budget",
"type": "object",
"title": "The budget schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"cpu": 32,
"memory": "64Gi",
"storage": "500Gi"
}
],
"required": [
"cpu",
"memory",
"storage"
],
"properties": {
"cpu": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/namespace/properties/budget/properties/cpu",
"type": "integer",
"title": "The cpu schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
32
]
},
"memory": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/namespace/properties/budget/properties/memory",
"type": "string",
"title": "The memory schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"64Gi"
]
},
"storage": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/namespace/properties/budget/properties/storage",
"type": "string",
"title": "The storage schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"500Gi"
]
}
},
"additionalProperties": true
},
"overcommit": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/namespace/properties/overcommit",
"type": "object",
"title": "The overcommit schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"cpu": 2,
"memory": 1
}
],
"required": [
"cpu",
"memory"
],
"properties": {
"cpu": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/namespace/properties/overcommit/properties/cpu",
"type": "integer",
"title": "The cpu schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
2
]
},
"memory": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/namespace/properties/overcommit/properties/memory",
"type": "integer",
"title": "The memory schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
1
]
}
},
"additionalProperties": true
}
},
"additionalProperties": true
},
"pod": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/pod",
"type": "object",
"title": "The pod schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"limits": {
"cpu": 4,
"memory": "8Gi"
},
"defaults": {
"cpu": "200m",
"memory": "200Mi"
},
"overcommit": {
"cpu": 10,
"memory": 2
}
}
],
"required": [
"limits",
"defaults",
"overcommit"
],
"properties": {
"limits": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/pod/properties/limits",
"type": "object",
"title": "The limits schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"cpu": 4,
"memory": "8Gi"
}
],
"required": [
"cpu",
"memory"
],
"properties": {
"cpu": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/pod/properties/limits/properties/cpu",
"type": "integer",
"title": "The cpu schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
4
]
},
"memory": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/pod/properties/limits/properties/memory",
"type": "string",
"title": "The memory schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"8Gi"
]
}
},
"additionalProperties": true
},
"defaults": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/pod/properties/defaults",
"type": "object",
"title": "The defaults schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"cpu": "200m",
"memory": "200Mi"
}
],
"required": [
"cpu",
"memory"
],
"properties": {
"cpu": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/pod/properties/defaults/properties/cpu",
"type": "string",
"title": "The cpu schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"200m"
]
},
"memory": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/pod/properties/defaults/properties/memory",
"type": "string",
"title": "The memory schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"200Mi"
]
}
},
"additionalProperties": true
},
"overcommit": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/pod/properties/overcommit",
"type": "object",
"title": "The overcommit schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"cpu": 10,
"memory": 2
}
],
"required": [
"cpu",
"memory"
],
"properties": {
"cpu": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/pod/properties/overcommit/properties/cpu",
"type": "integer",
"title": "The cpu schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
10
]
},
"memory": {
"$id": "#/properties/namespaces/items/anyOf/0/properties/pod/properties/overcommit/properties/memory",
"type": "integer",
"title": "The memory schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
2
]
}
},
"additionalProperties": true
}
},
"additionalProperties": true
}
},
"additionalProperties": true
}
]
}
},
"namespace": {
"$id": "#/properties/namespace",
"type": "object",
"title": "The namespace schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"budget": {
"cpu": 32,
"memory": "64Gi",
"storage": "500Gi"
},
"overcommit": {
"cpu": 2,
"memory": 1
}
}
],
"required": [
"budget",
"overcommit"
],
"properties": {
"budget": {
"$id": "#/properties/namespace/properties/budget",
"type": "object",
"title": "The budget schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"cpu": 32,
"memory": "64Gi",
"storage": "500Gi"
}
],
"required": [
"cpu",
"memory",
"storage"
],
"properties": {
"cpu": {
"$id": "#/properties/namespace/properties/budget/properties/cpu",
"type": "integer",
"title": "The cpu schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
32
]
},
"memory": {
"$id": "#/properties/namespace/properties/budget/properties/memory",
"type": "string",
"title": "The memory schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"64Gi"
]
},
"storage": {
"$id": "#/properties/namespace/properties/budget/properties/storage",
"type": "string",
"title": "The storage schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"500Gi"
]
}
},
"additionalProperties": true
},
"overcommit": {
"$id": "#/properties/namespace/properties/overcommit",
"type": "object",
"title": "The overcommit schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"cpu": 2,
"memory": 1
}
],
"required": [
"cpu",
"memory"
],
"properties": {
"cpu": {
"$id": "#/properties/namespace/properties/overcommit/properties/cpu",
"type": "integer",
"title": "The cpu schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
2
]
},
"memory": {
"$id": "#/properties/namespace/properties/overcommit/properties/memory",
"type": "integer",
"title": "The memory schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
1
]
}
},
"additionalProperties": true
}
},
"additionalProperties": true
},
"pod": {
"$id": "#/properties/pod",
"type": "object",
"title": "The pod schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"limits": {
"cpu": 4,
"memory": "8Gi"
},
"defaults": {
"cpu": "200m",
"memory": "200Mi"
},
"overcommit": {
"cpu": 10,
"memory": 2
}
}
],
"required": [
"limits",
"defaults",
"overcommit"
],
"properties": {
"limits": {
"$id": "#/properties/pod/properties/limits",
"type": "object",
"title": "The limits schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"cpu": 4,
"memory": "8Gi"
}
],
"required": [
"cpu",
"memory"
],
"properties": {
"cpu": {
"$id": "#/properties/pod/properties/limits/properties/cpu",
"type": "integer",
"title": "The cpu schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
4
]
},
"memory": {
"$id": "#/properties/pod/properties/limits/properties/memory",
"type": "string",
"title": "The memory schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"8Gi"
]
}
},
"additionalProperties": true
},
"defaults": {
"$id": "#/properties/pod/properties/defaults",
"type": "object",
"title": "The defaults schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"cpu": "200m",
"memory": "200Mi"
}
],
"required": [
"cpu",
"memory"
],
"properties": {
"cpu": {
"$id": "#/properties/pod/properties/defaults/properties/cpu",
"type": "string",
"title": "The cpu schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"200m"
]
},
"memory": {
"$id": "#/properties/pod/properties/defaults/properties/memory",
"type": "string",
"title": "The memory schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"200Mi"
]
}
},
"additionalProperties": true
},
"overcommit": {
"$id": "#/properties/pod/properties/overcommit",
"type": "object",
"title": "The overcommit schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"cpu": 10,
"memory": 2
}
],
"required": [
"cpu",
"memory"
],
"properties": {
"cpu": {
"$id": "#/properties/pod/properties/overcommit/properties/cpu",
"type": "integer",
"title": "The cpu schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
10
]
},
"memory": {
"$id": "#/properties/pod/properties/overcommit/properties/memory",
"type": "integer",
"title": "The memory schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
2
]
}
},
"additionalProperties": true
}
},
"additionalProperties": true
}
},
"additionalProperties": true
}
+1 -40
View File
@@ -1,40 +1 @@
namespaces:
- name: staging
namespace:
budget:
cpu: 32
memory: "64Gi"
storage: "500Gi"
overcommit:
cpu: 2
memory: 1
pod:
limits:
cpu: 4
memory: "8Gi"
defaults:
cpu: "200m"
memory: "200Mi"
overcommit:
cpu: 10
memory: 2
namespace:
budget:
cpu: 32
memory: "64Gi"
storage: "500Gi"
overcommit:
cpu: 2
memory: 1
pod:
limits:
cpu: 4
memory: "8Gi"
defaults:
cpu: "200m"
memory: "200Mi"
overcommit:
cpu: 10
memory: 2
namespaces: []