Skip to content

Commit

Permalink
Backport of feat(helm): add configurable server-acl-init and cleanup …
Browse files Browse the repository at this point in the history
…resource limits into release/1.0.x (#2438)

* backport of commit 3709823

* backport of commit d50e056

* backport of commit f091ff7

* backport of commit 9bdb469

---------

Co-authored-by: DanStough <dan.stough@hashicorp.com>
  • Loading branch information
hc-github-team-consul-core and DanStough authored Jun 23, 2023
1 parent 513930f commit ffffd1b
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .changelog/2416.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:feature
helm: Adds `acls.resources` field which can be configured to override the `resource` settings for the `server-acl-init` and `server-acl-init-cleanup` Jobs.
```
9 changes: 3 additions & 6 deletions charts/consul/templates/server-acl-init-cleanup-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,10 @@ spec:
- -log-json={{ .Values.global.logJSON }}
- -k8s-namespace={{ .Release.Namespace }}
- {{ template "consul.fullname" . }}-server-acl-init
{{- if .Values.global.acls.resources }}
resources:
requests:
memory: "50Mi"
cpu: "50m"
limits:
memory: "50Mi"
cpu: "50m"
{{- toYaml .Values.global.acls.resources | nindent 12 }}
{{- end }}
{{- if .Values.global.acls.tolerations }}
tolerations:
{{ tpl .Values.global.acls.tolerations . | indent 8 | trim }}
Expand Down
9 changes: 3 additions & 6 deletions charts/consul/templates/server-acl-init-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,10 @@ spec:
{{- end }}
{{- end }}
{{- end }}
{{- if .Values.global.acls.resources }}
resources:
requests:
memory: "50Mi"
cpu: "50m"
limits:
memory: "50Mi"
cpu: "50m"
{{- toYaml .Values.global.acls.resources | nindent 10 }}
{{- end }}
{{- if .Values.global.acls.tolerations }}
tolerations:
{{ tpl .Values.global.acls.tolerations . | indent 8 | trim }}
Expand Down
24 changes: 24 additions & 0 deletions charts/consul/test/unit/server-acl-init-cleanup-job.bats
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,27 @@ load _helpers
[ "${actualTemplateFoo}" = "bar" ]
[ "${actualTemplateBaz}" = "qux" ]
}

#--------------------------------------------------------------------
# resources

@test "serverACLInitCleanup/Job: resources defined by default" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-acl-init-cleanup-job.yaml \
--set 'global.acls.manageSystemACLs=true' \
. | tee /dev/stderr |
yq -rc '.spec.template.spec.containers[0].resources' | tee /dev/stderr)
[ "${actual}" = '{"limits":{"cpu":"50m","memory":"50Mi"},"requests":{"cpu":"50m","memory":"50Mi"}}' ]
}

@test "serverACLInitCleanup/Job: resources can be overridden" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-acl-init-cleanup-job.yaml \
--set 'global.acls.manageSystemACLs=true' \
--set 'global.acls.resources.foo=bar' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].resources.foo' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}
24 changes: 24 additions & 0 deletions charts/consul/test/unit/server-acl-init-job.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2210,3 +2210,27 @@ load _helpers
[ "${actualTemplateFoo}" = "bar" ]
[ "${actualTemplateBaz}" = "qux" ]
}

#--------------------------------------------------------------------
# resources

@test "serverACLInit/Job: resources defined by default" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-acl-init-job.yaml \
--set 'global.acls.manageSystemACLs=true' \
. | tee /dev/stderr |
yq -rc '.spec.template.spec.containers[0].resources' | tee /dev/stderr)
[ "${actual}" = '{"limits":{"cpu":"50m","memory":"50Mi"},"requests":{"cpu":"50m","memory":"50Mi"}}' ]
}

@test "serverACLInit/Job: resources can be overridden" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-acl-init-job.yaml \
--set 'global.acls.manageSystemACLs=true' \
--set 'global.acls.resources.foo=bar' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].resources.foo' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}
27 changes: 27 additions & 0 deletions charts/consul/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,33 @@ global:
# @type: string
secretKey: null

# The resource requests (CPU, memory, etc.) for the server-acl-init and server-acl-init-cleanup pods.
# This should be a YAML map corresponding to a Kubernetes
# [`ResourceRequirements``](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.27/#resourcerequirements-v1-core)
# object.
#
# Example:
#
# ```yaml
# resources:
# requests:
# memory: '200Mi'
# cpu: '100m'
# limits:
# memory: '200Mi'
# cpu: '100m'
# ```
#
# @recurse: false
# @type: map
resources:
requests:
memory: "50Mi"
cpu: "50m"
limits:
memory: "50Mi"
cpu: "50m"

# partitionToken references a Vault secret containing the ACL token to be used in non-default partitions.
# This value should only be provided in the default partition and only when setting
# the `global.secretsBackend.vault.enabled` value to true.
Expand Down

0 comments on commit ffffd1b

Please sign in to comment.