Skip to content

Commit

Permalink
Add reources management for nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
puppetninja committed Dec 19, 2022
1 parent b4b9401 commit 4e5357f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 40 deletions.
57 changes: 24 additions & 33 deletions charts/tezos/templates/_containers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
* with_config bring in the configMap defaults true only on utils.
* with_secret bring in the secrets map including the identities.
* localvars set env vars MY_* Defaults to true only on utils.
* resources set container resources management, i.e. request
* and limit, default value is an empty dict.
*/ -}}

{{- define "tezos.generic_container" }}
Expand Down Expand Up @@ -75,6 +77,9 @@
{{- $_ := set . "args" (list .type) }}
{{- end }}
{{- end }}
{{- if not (hasKey . "resources") }}
{{- $_ := set . "resources" dict }}
{{- end }}

{{- /*
* And, now, we generate the YAML:
Expand Down Expand Up @@ -167,6 +172,10 @@
port: 31732
{{- end }}
{{- end }}
{{- if .resources }}
resources:
{{ toYaml .resources | indent 4 }}
{{- end }}
{{- end }}


Expand Down Expand Up @@ -240,47 +249,29 @@

{{- define "tezos.container.sidecar" }}
{{- if or (not (hasKey $.node_vals "readiness_probe")) $.node_vals.readiness_probe }}
{{- include "tezos.generic_container" (dict "root" $
"type" "sidecar"
"image" "utils"
{{- $sidecarResources := dict "requests" (dict "memory" "80Mi") "limits" (dict "memory" "100Mi") -}}
{{- include "tezos.generic_container" (dict "root" $
"type" "sidecar"
"image" "utils"
"resources" $sidecarResources
) | nindent 0 }}
{{- end }}
{{- end }}

{{- define "tezos.getNodeImplementation" }}
{{- $containers := $.node_vals.runs }}
{{- if and (has "tezedge_node" $containers) (has "octez_node" $containers) }}
{{- fail "Only either tezedge_node or octez_node container can be specified in 'runs' field " }}
{{- else if (has "octez_node" $containers) }}
{{- "octez" }}
{{- else if (has "tezedge_node" $containers) }}
{{- "tezedge" }}
{{- else }}
{{- fail "No Tezos node container was specified in 'runs' field. Must specify tezedge_node or octez_node" }}
{{- end }}
{{- end }}

{{- define "tezos.container.node" }}
{{- if eq (include "tezos.getNodeImplementation" $) "octez" }}
{{- include "tezos.generic_container" (dict "root" $
"type" "octez-node"
"image" "octez"
"with_config" 0
) | nindent 0 }}
{{- end }}
{{- end }}
{{- $octezNodeParams := dict "root" $
"type" "octez-node"
"image" "octez"
"with_config" 0
-}}

{{- define "tezos.container.tezedge" }}
{{- if eq (include "tezos.getNodeImplementation" $) "tezedge" }}
{{- include "tezos.generic_container" (
dict "root" $
"type" "tezedge-node"
"image" "tezedge"
"with_config" 0
"command" "/light-node"
"args" (list "--config-file=/etc/tezos/tezedge.conf")
) | nindent 0 }}
{{- if hasKey $.node_vals "resources" }}
{{- $_ := set $octezNodeParams "resources" $.node_vals.resources -}}
{{- end }}

{{- include "tezos.generic_container" $octezNodeParams | nindent 0 }}
{{- end }}
{{- end }}

{{- define "tezos.container.bakers" }}
Expand Down
8 changes: 8 additions & 0 deletions charts/tezos/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ should_generate_unsafe_deterministic_data: false
# bakers and accusers, so "baker-011-pthangz2" is configured
# using just "baker".
# - "storage_size": the size of the PV
# - "resources": resources specifications for the node.
# - "images": Optional specification of images to use for the tezos node and
# baker. Options are "octez" with a tezos/tezos image or
# "tezedge" with a tezedge/tezedge image. If no images are provided,
Expand Down Expand Up @@ -192,6 +193,13 @@ should_generate_unsafe_deterministic_data: false
# - octez_node
# # - tezedge_node
# - baker
# # You can optionally set resources and limits for your octez node/baker
# # See: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
# resources:
# requests:
# memory: 16192Mi
# limits:
# memory: 16192Mi
# instances:
# - bake_using_account: baker0
# is_bootstrap_node: true
Expand Down
7 changes: 6 additions & 1 deletion test/charts/mainnet.expect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ spec:
- mountPath: /etc/tezos
name: config-volume
- mountPath: /var/tezos
name: var-volume
name: var-volume
resources:
limits:
memory: 100Mi
requests:
memory: 80Mi
initContainers:
- name: config-init
image: "tezos/tezos:v14-release"
Expand Down
14 changes: 12 additions & 2 deletions test/charts/mainnet2.expect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,12 @@ spec:
- mountPath: /etc/tezos
name: config-volume
- mountPath: /var/tezos
name: var-volume
name: var-volume
resources:
limits:
memory: 100Mi
requests:
memory: 80Mi
initContainers:
- name: config-init
image: "tezos/tezos:v14-release"
Expand Down Expand Up @@ -616,7 +621,12 @@ spec:
- mountPath: /etc/tezos
name: config-volume
- mountPath: /var/tezos
name: var-volume
name: var-volume
resources:
limits:
memory: 100Mi
requests:
memory: 80Mi
initContainers:
- name: config-init
image: "tezos/tezos:v14-release"
Expand Down
28 changes: 24 additions & 4 deletions test/charts/private-chain.expect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,12 @@ spec:
- mountPath: /etc/tezos
name: config-volume
- mountPath: /var/tezos
name: var-volume
name: var-volume
resources:
limits:
memory: 100Mi
requests:
memory: 80Mi
initContainers:
- name: config-generator
image: "ghcr.io/oxheadalpha/tezos-k8s-utils:master"
Expand Down Expand Up @@ -666,7 +671,12 @@ spec:
- mountPath: /etc/tezos
name: config-volume
- mountPath: /var/tezos
name: var-volume
name: var-volume
resources:
limits:
memory: 100Mi
requests:
memory: 80Mi
initContainers:
- name: config-generator
image: "ghcr.io/oxheadalpha/tezos-k8s-utils:master"
Expand Down Expand Up @@ -956,7 +966,12 @@ spec:
- mountPath: /etc/tezos
name: config-volume
- mountPath: /var/tezos
name: var-volume
name: var-volume
resources:
limits:
memory: 100Mi
requests:
memory: 80Mi
initContainers:
- name: config-generator
image: "ghcr.io/oxheadalpha/tezos-k8s-utils:master"
Expand Down Expand Up @@ -1217,7 +1232,12 @@ spec:
- mountPath: /etc/tezos
name: config-volume
- mountPath: /var/tezos
name: var-volume
name: var-volume
resources:
limits:
memory: 100Mi
requests:
memory: 80Mi
initContainers:
- name: config-generator
image: "ghcr.io/oxheadalpha/tezos-k8s-utils:master"
Expand Down

0 comments on commit 4e5357f

Please sign in to comment.