Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(base-cluster/limitrange-quotas): add limitrange and resource quota #673

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions charts/base-cluster/ci/limitrange-resourcequota-values.yaml
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions charts/base-cluster/templates/global/namespaces.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
cwrau marked this conversation as resolved.
Show resolved Hide resolved
{{- $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 -}}
cwrau marked this conversation as resolved.
Show resolved Hide resolved
{{- $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 -}}
cwrau marked this conversation as resolved.
Show resolved Hide resolved
{{- $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 -}}
32 changes: 32 additions & 0 deletions charts/base-cluster/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions charts/base-cluster/values.yaml
marvinWolff marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down