Skip to content

Commit

Permalink
[node] add params validation (#353)
Browse files Browse the repository at this point in the history
add params validation
  • Loading branch information
BulatSaif authored Aug 21, 2024
1 parent cdfef89 commit 24e00cf
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion charts/node/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: node
description: A Helm chart to deploy Substrate/Polkadot nodes
type: application
version: 5.11.1
version: 5.12.0
maintainers:
- name: Parity
url: https://github.com/paritytech/helm-charts
Expand Down
2 changes: 1 addition & 1 deletion charts/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This is intended behaviour. Make sure to run `git add -A` once again to stage ch

# Substrate/Polkadot node Helm chart

![Version: 5.11.1](https://img.shields.io/badge/Version-5.11.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
![Version: 5.12.0](https://img.shields.io/badge/Version-5.12.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)

## Overview
The Polkadot Helm Chart provides a convenient way to deploy and manage a Polkadot blockchain node in a Kubernetes cluster.
Expand Down
41 changes: 41 additions & 0 deletions charts/node/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,44 @@ Return true if we have a Relaychain, a single Relaychain, or if it's part of a c
{{- else -}}
{{- end -}}
{{- end -}}
{{/*
Function to validate that exclusive keys are defined only once
Parameters:
- $params: list of parameters to validate
*/}}
{{- define "validateExclusiveKeys" -}}
{{- $params := .params -}}
{{- $global := .global -}}
{{- $countSet := 0 -}}
{{- $setKeys := "" -}}
{{- range $param := $params -}}
{{- $isSet := tpl (printf "{{ if %s }}true{{ end }}" $param) $global -}}
{{- if $isSet -}}
{{- $countSet = add1 $countSet -}}
{{- $setKeys = printf "%s %s" $setKeys $param -}}
{{- end -}}
{{- end -}}
{{- if gt $countSet 1 -}}
{{- fail (printf "Error: Only one of [%s] can be set." $setKeys) -}}
{{- end -}}
{{- end -}}
{{/*
validate node keys params
*/}}
{{- define "validateNodeKeys" -}}
{{- $nodeKeysParams := list ".Values.node.persistGeneratedNodeKey" ".Values.node.vault.nodeKey" ".Values.node.existingSecrets.nodeKey" ".Values.node.customNodeKey" -}}
{{- include "validateExclusiveKeys" (dict "params" $nodeKeysParams "global" . ) -}}
{{- end -}}
{{/*
validate keys params
*/}}
{{- define "validateKeys" -}}
{{- $keysParams := list ".Values.node.vault.keys" ".Values.node.existingSecrets.keys" ".Values.node.keys" -}}
{{- include "validateExclusiveKeys" (dict "params" $keysParams "global" . ) -}}
{{- end -}}
2 changes: 2 additions & 0 deletions charts/node/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
{{ $serviceAccountName := include "node.serviceAccountName" . }}
{{ $databasePath := include "node.databasePath" . }}
{{ $chartManagedFlagsRegex := include "node.chartManagedFlagsRegex" . }}
{{ include "validateNodeKeys" . }}
{{ include "validateKeys" . }}
apiVersion: apps/v1
kind: StatefulSet
metadata:
Expand Down

0 comments on commit 24e00cf

Please sign in to comment.