diff --git a/charts/base-cluster/ci/limitrange-resourcequota-values.yaml b/charts/base-cluster/ci/limitrange-resourcequota-values.yaml new file mode 100644 index 000000000..96bc77c0c --- /dev/null +++ b/charts/base-cluster/ci/limitrange-resourcequota-values.yaml @@ -0,0 +1,59 @@ +global: + serviceLevelAgreement: None + namespaces: + main0: + resources: + defaults: + requests: + cpu: 50m + memory: 100Mi + limits: + cpu: 500m + memory: 300Mi + quotas: + limits.cpu: "1" + limits.memory: 1Gi + main1: + resources: + defaults: + requests: + cpu: 50m + memory: 100Mi + limits: + cpu: 500m + memory: 300Mi + main2: + resources: + defaults: + requests: + cpu: 50m + memory: 100Mi + quotas: + limits.cpu: "1" + limits.memory: 1Gi + main3: + resources: + defaults: + requests: + cpu: 50m + memory: 100Mi + main4: + resources: + defaults: + limits: + cpu: 500m + memory: 300Mi + quotas: + limits.cpu: "1" + limits.memory: 1Gi + main5: + resources: + defaults: + limits: + cpu: 500m + memory: 300Mi + main6: + resources: + quotas: + limits.cpu: "1" + limits.memory: 1Gi diff --git a/charts/base-cluster/templates/global/namespaces.yaml b/charts/base-cluster/templates/global/namespaces.yaml index d1d3b90b6..b4bff157d 100644 --- a/charts/base-cluster/templates/global/namespaces.yaml +++ b/charts/base-cluster/templates/global/namespaces.yaml @@ -8,4 +8,53 @@ metadata: {{- . | toYaml | nindent 4 -}} {{- end }} --- +apiVersion: v1 +kind: LimitRange +metadata: + name: {{ $name }} + namespace: {{ $name }} + labels: {{- include "common.labels.standard" $ | nindent 4 }} +spec: + {{- $limits := dict "type" "Container" "defaultRequest" (dict "cpu" "100m" "memory" "100Mi") -}} + {{ if $namespace.resources }} + {{- if $namespace.resources.defaults -}} + {{/* this section defines default limits */}} + {{- with $namespace.resources.defaults.limits -}} + {{- $defaultLimits := dict -}} + {{- range $resource, $limit := . -}} + {{- $defaultLimits = set $defaultLimits $resource (include "common.tplvalues.render" (dict "value" $limit "context" $)) -}} + {{- end -}} + {{- $limits = set $limits "default" $defaultLimits -}} + {{- end -}} + {{/* this section defines default requests */}} + {{- with $namespace.resources.defaults.requests -}} + {{- $defaultRequests := dict -}} + {{- range $resource, $request := . -}} + {{- $defaultRequests = set $defaultRequests $resource (include "common.tplvalues.render" (dict "value" $request "context" $)) -}} + {{- end -}} + {{- $limits = set $limits "defaultRequest" $defaultRequests -}} + {{- end -}} + {{- end }} + {{- end }} + limits: {{- list $limits | toYaml | nindent 4 }} +{{ if $namespace.resources }} +{{ if $namespace.resources.quotas }} +--- +apiVersion: v1 +kind: ResourceQuota +metadata: + name: {{ $name }} + namespace: {{ $name }} + labels: {{- include "common.labels.standard" $ | nindent 4 }} +spec: + {{- with $namespace.resources.quotas -}} + {{- $quotas := dict -}} + {{- range $resource, $quota := . -}} + {{- $quotas = set $quotas $resource (include "common.tplvalues.render" (dict "value" $quota "context" $)) -}} + {{- end }} + hard: {{- $quotas | toYaml | nindent 4 }} + {{- end }} +{{- end }} +{{- end }} +--- {{ end -}} \ No newline at end of file diff --git a/charts/base-cluster/values.schema.json b/charts/base-cluster/values.schema.json index 88b64461f..cbe08cf4d 100644 --- a/charts/base-cluster/values.schema.json +++ b/charts/base-cluster/values.schema.json @@ -232,6 +232,38 @@ }, "condition": { "$ref": "#/$defs/condition" + }, + "resources": { + "type": "object", + "properties": { + "defaults": { + "type": "object", + "minProperties": 1, + "properties": { + "requests": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/quantity" + } + }, + "limits": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/quantity" + } + } + }, + "additionalProperties": false + }, + "quotas": { + "type": "object", + "description": "See https://kubernetes.io/docs/concepts/policy/resource-quotas/", + "additionalProperties": { + "$ref": "#/$defs/quantity" + } + } + }, + "additionalProperties": false } }, "additionalProperties": false diff --git a/charts/base-cluster/values.yaml b/charts/base-cluster/values.yaml index c75f38d48..5332e790f 100644 --- a/charts/base-cluster/values.yaml +++ b/charts/base-cluster/values.yaml @@ -13,6 +13,17 @@ global: cert-manager: additionalLabels: app.kubernetes.io/component: cert-manager + resources: + defaults: + requests: + cpu: 50m + memory: 100Mi + limits: + cpu: 500m + memory: 300Mi + quotas: + limits.cpu: "1" + limits.memory: 1Gi ingress-nginx: condition: "{{ .Values.ingress.enabled }}" additionalLabels: @@ -25,6 +36,11 @@ global: condition: "{{ or .Values.monitoring.prometheus.enabled .Values.monitoring.metricsServer.enabled }}" additionalLabels: app.kubernetes.io/component: monitoring + resources: + defaults: + requests: + cpu: 20m + memory: 100Mi loki: condition: "{{ .Values.monitoring.loki.enabled }}" additionalLabels: