From 4e5357f5f0f5d8b116450dcac63f8fc7747025a7 Mon Sep 17 00:00:00 2001 From: Chao Zhang Date: Fri, 28 Oct 2022 13:26:36 +0200 Subject: [PATCH] Add reources management for nodes --- charts/tezos/templates/_containers.tpl | 57 +++++++++++--------------- charts/tezos/values.yaml | 8 ++++ test/charts/mainnet.expect.yaml | 7 +++- test/charts/mainnet2.expect.yaml | 14 ++++++- test/charts/private-chain.expect.yaml | 28 +++++++++++-- 5 files changed, 74 insertions(+), 40 deletions(-) diff --git a/charts/tezos/templates/_containers.tpl b/charts/tezos/templates/_containers.tpl index 8008e5f11..597add77b 100644 --- a/charts/tezos/templates/_containers.tpl +++ b/charts/tezos/templates/_containers.tpl @@ -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" }} @@ -75,6 +77,9 @@ {{- $_ := set . "args" (list .type) }} {{- end }} {{- end }} +{{- if not (hasKey . "resources") }} + {{- $_ := set . "resources" dict }} +{{- end }} {{- /* * And, now, we generate the YAML: @@ -167,6 +172,10 @@ port: 31732 {{- end }} {{- end }} +{{- if .resources }} + resources: +{{ toYaml .resources | indent 4 }} +{{- end }} {{- end }} @@ -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" }} diff --git a/charts/tezos/values.yaml b/charts/tezos/values.yaml index 51557d5af..1682ee8dc 100644 --- a/charts/tezos/values.yaml +++ b/charts/tezos/values.yaml @@ -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, @@ -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 diff --git a/test/charts/mainnet.expect.yaml b/test/charts/mainnet.expect.yaml index 04e631445..6c5737f54 100644 --- a/test/charts/mainnet.expect.yaml +++ b/test/charts/mainnet.expect.yaml @@ -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" diff --git a/test/charts/mainnet2.expect.yaml b/test/charts/mainnet2.expect.yaml index 9477ccb0f..93e0028da 100644 --- a/test/charts/mainnet2.expect.yaml +++ b/test/charts/mainnet2.expect.yaml @@ -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" @@ -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" diff --git a/test/charts/private-chain.expect.yaml b/test/charts/private-chain.expect.yaml index b5331c987..b591816af 100644 --- a/test/charts/private-chain.expect.yaml +++ b/test/charts/private-chain.expect.yaml @@ -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" @@ -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" @@ -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" @@ -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"