Skip to content

Commit

Permalink
refactor: update resource limits and requests to use cpuOverride and …
Browse files Browse the repository at this point in the history
…memoryOverride; modify imagePullSecret handling in templates

On-behalf-of: @SAP angel.kafazov@sap.com
Signed-off-by: Angel Kafazov <akafazov@cst-bg.net>
  • Loading branch information
akafazov committed Nov 27, 2024
1 parent c98efbb commit dff2053
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.vscode/settings.json
bin/
**/*.tgz
16 changes: 8 additions & 8 deletions charts/account-operator/tests/deployment_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ tests:
deployment:
resources:
limits:
cpu: 260m
memory: 512Mi
cpuOverride: 260m
memoryOverride: 512Mi
requests:
cpu: 150m
memory: 128Mi
cpuOverride: 150m
memoryOverride: 128Mi
asserts:
- matchSnapshot: {}
- it: operator match the snapshot (with kubeconfigSecret)
Expand All @@ -34,11 +34,11 @@ tests:
deployment:
resources:
limits:
cpu: 260m
memory: 512Mi
cpuOverride: 260m
memoryOverride: 512Mi
requests:
cpu: 150m
memory: 128Mi
cpuOverride: 150m
memoryOverride: 128Mi
asserts:
- matchSnapshot: {}
- it: deployment with security context
Expand Down
11 changes: 4 additions & 7 deletions charts/account-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ image:
# @param image.tag The image tag
tag: latest

# @param imagePullSecret The secret used to pull the image
imagePullSecret: "github"

# @param crds.enabled Enable CRDs
crds:
enabled: true
Expand Down Expand Up @@ -61,11 +58,11 @@ deployment:
revisionHistoryLimit: 3
resources:
limits:
cpu: 260m
memory: 512Mi
cpuOverride: 260m
memoryOverride: 512Mi
requests:
cpu: 150m
memory: 128Mi
cpuOverride: 150m
memoryOverride: 128Mi

# The KCP configuration
## @param kcp.enabled Enable KCP
Expand Down
24 changes: 8 additions & 16 deletions charts/common/templates/_deploymentHelpers.tpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{- define "common.deploymentBasics" }}
strategy:
rollingUpdate:
maxSurge: {{ (and .Values.deployment .Values.deployment.maxSurge) | default 5 }}
maxUnavailable: {{ (and .Values.deployment .Values.deployment.maxUnavailable) | default 0 }}
type: {{ .Values.deployment.strategy }}
maxSurge: {{ include "common.getKeyValue" (dict "Values" .Values "key" "deployment.maxSurge") }}
maxUnavailable: {{ include "common.getKeyValue" (dict "Values" .Values "key" "deployment.maxUnavailable") }}
type: {{ include "common.getKeyValue" (dict "Values" .Values "key" "deployment.strategy") }}
revisionHistoryLimit: 3
selector:
matchLabels:
Expand All @@ -18,13 +18,11 @@ image: "{{ .Values.image.name }}:{{ .Values.image.tag }}"
{{- define "common.resources" }}
resources:
limits:
{{- if (((.Values.deployment).resources).limits).cpu }}
cpu: {{ (((.Values.deployment).resources).limits).cpu | quote }}
{{- end }}
memory: {{ (((.Values.deployment).resources).limits).memory | default "512Mi" | quote }}
cpu: {{ include "common.getKeyValue" (dict "Values" .Values "key" "deployment.resources.limits.cpu") }}
memory: {{ include "common.getKeyValue" (dict "Values" .Values "key" "deployment.resources.limits.memory") }}
requests:
cpu: {{ (((.Values.deployment).resources).requests).cpu | default "40m" }}
memory: {{ (((.Values.deployment).resources).requests).memory | default "50Mi" | quote }}
cpu: {{ include "common.getKeyValue" (dict "Values" .Values "key" "deployment.resources.requests.cpu") }}
memory: {{ include "common.getKeyValue" (dict "Values" .Values "key" "deployment.resources.requests.memory") }}
{{- end }}
{{- define "common.ports" }}
ports:
Expand Down Expand Up @@ -122,13 +120,7 @@ automountServiceAccountToken: {{ not (eq (.Values.security).mountServiceAccountT
{{ .Values.terminationGracePeriodSeconds | default 10 }}
{{- end }}
{{- define "common.imagePullPolicy" -}}
{{- if and .Values.global (.Values.global.imagePullPolicy) -}}
{{ .Values.global.imagePullPolicy }}
{{- else if .Values.imagePullPolicy -}}
{{ .Values.imagePullPolicy }}
{{- else -}}
Always
{{- end -}}
{{ include "common.getKeyValue" (dict "Values" .Values "key" "imagePullPolicy") }}
{{- end }}
{{- define "common.PortsMetricsHealth" -}}
- name: metrics
Expand Down
2 changes: 1 addition & 1 deletion charts/common/templates/_imagePullSecret.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- define "common.imagePullSecret" }}
imagePullSecrets:
- name: {{ include "common.certManagerEnabled" (dict "Values" .Values "key" "imagePullSecret") }}
- name: {{ include "common.getKeyValue" (dict "Values" .Values "key" "imagePullSecret") }}
{{- end -}}
14 changes: 13 additions & 1 deletion charts/common/values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
defaults:
certManager:
enabled: false
imagePullSecret: "github"
imagePullSecret: "github"
imagePullPolicy: Always
deployment:
resources:
limits:
cpu: "100m"
memory: "512Mi"
requests:
cpu: "40m"
memory: "50Mi"
maxSurge: 5
maxUnavailable: 0
strategy: RollingUpdate

Check failure on line 16 in charts/common/values.yaml

View workflow job for this annotation

GitHub Actions / pipeline / testChart / lint

16:28 [new-line-at-end-of-file] no new line character at the end of file

Check failure on line 16 in charts/common/values.yaml

View workflow job for this annotation

GitHub Actions / pipeline / testChart / lint

16:28 [new-line-at-end-of-file] no new line character at the end of file

Check failure on line 16 in charts/common/values.yaml

View workflow job for this annotation

GitHub Actions / pipeline / testChart / lint

16:28 [new-line-at-end-of-file] no new line character at the end of file
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ operator match the snapshot:
periodSeconds: 10
resources:
limits:
cpu: 260m
cpu: 100m
memory: 512Mi
requests:
cpu: 40m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ tests:
- it: test imagePullPolicy override
template: deployment.yaml
set:
imagePullPolicy: IfNotPresent
imagePullPolicyOverride: IfNotPresent
asserts:
- equal:
path: spec.template.spec.containers[0].imagePullPolicy
Expand Down

0 comments on commit dff2053

Please sign in to comment.