Skip to content

Commit af4b626

Browse files
authored
feat: share security contexts globally (#30)
## Summary - add `global.securityContexts` defaults for pod/container security context inheritance - merge global + chart-level security contexts when rendering bootstrapper and node workloads - refresh chart docs to reflect the new global configuration knobs ## Testing - bun run check - bun run typecheck - bun run test
1 parent 12ddbb4 commit af4b626

File tree

8 files changed

+39
-14
lines changed

8 files changed

+39
-14
lines changed

charts/network/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ A Helm chart for a blockchain network on Kubernetes
2121

2222
| Key | Type | Default | Description |
2323
|-----|------|---------|-------------|
24-
| global | object | `{"networkNodes":{"faucetArtifactPrefix":"besu-faucet","genesisConfigMapName":"besu-genesis","podPrefix":"","serviceName":"","staticNodesConfigMapName":"besu-static-nodes"}}` | Global configuration shared across subcharts. |
24+
| global | object | `{"networkNodes":{"faucetArtifactPrefix":"besu-faucet","genesisConfigMapName":"besu-genesis","podPrefix":"","serviceName":"","staticNodesConfigMapName":"besu-static-nodes"},"securityContexts":{"container":{},"pod":{}}}` | Global configuration shared across subcharts. |
2525
| global.networkNodes | object | `{"faucetArtifactPrefix":"besu-faucet","genesisConfigMapName":"besu-genesis","podPrefix":"","serviceName":"","staticNodesConfigMapName":"besu-static-nodes"}` | Defaults consumed by Besu network node workloads. |
2626
| global.networkNodes.faucetArtifactPrefix | string | `"besu-faucet"` | Prefix used for faucet ConfigMaps and Secrets. |
2727
| global.networkNodes.genesisConfigMapName | string | `"besu-genesis"` | ConfigMap name storing the generated genesis.json artifact. |
2828
| global.networkNodes.podPrefix | string | `""` | StatefulSet prefix used for validator pod hostnames. |
2929
| global.networkNodes.serviceName | string | `""` | Kubernetes Service name fronting validator pods to align bootstrapper static-nodes output. |
3030
| global.networkNodes.staticNodesConfigMapName | string | `"besu-static-nodes"` | ConfigMap name storing static-nodes.json entries. |
31+
| global.securityContexts | object | `{"container":{},"pod":{}}` | Shared pod- and container-level security contexts applied when subcharts omit explicit overrides. |
32+
| global.securityContexts.container | object | `{}` | Container security context inherited by subcharts when set. |
33+
| global.securityContexts.pod | object | `{}` | Pod security context inherited by subcharts when set. |

charts/network/charts/network-bootstrapper/templates/job.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,23 @@ spec:
2727
{{- toYaml . | nindent 8 }}
2828
{{- end }}
2929
serviceAccountName: {{ include "network-bootstrapper.serviceAccountName" . }}
30-
{{- with .Values.podSecurityContext }}
30+
{{- $globalValues := (.Values.global | default (dict)) }}
31+
{{- $globalSecurityContexts := dig "securityContexts" $globalValues (dict) }}
32+
{{- $podSecurityContext := merge (deepCopy (default (dict) .Values.podSecurityContext)) (dig "pod" $globalSecurityContexts (dict)) }}
33+
{{- $containerSecurityContext := merge (deepCopy (default (dict) .Values.securityContext)) (dig "container" $globalSecurityContexts (dict)) }}
34+
{{- if $podSecurityContext }}
3135
securityContext:
32-
{{- toYaml . | nindent 8 }}
36+
{{- toYaml $podSecurityContext | nindent 8 }}
3337
{{- end }}
3438
{{- with .Values.initContainers }}
3539
initContainers:
3640
{{- include "network-bootstrapper.renderInitContainers" (dict "context" $ "containers" . "indent" 8) }}
3741
{{- end }}
3842
containers:
3943
- name: {{ .Chart.Name }}
40-
{{- with .Values.securityContext }}
44+
{{- if $containerSecurityContext }}
4145
securityContext:
42-
{{- toYaml . | nindent 12 }}
46+
{{- toYaml $containerSecurityContext | nindent 12 }}
4347
{{- end }}
4448
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
4549
imagePullPolicy: {{ .Values.image.pullPolicy }}

charts/network/charts/network-bootstrapper/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ podLabels: {}
4141
# Pod-level security context applied to all containers in the pod.
4242
podSecurityContext:
4343
{}
44+
# -- Leave empty to inherit from global.securityContexts.pod.
4445
# fsGroup: 2000
4546

4647
# Container security context applied to the bootstrapper container.
4748
securityContext:
4849
{}
50+
# -- Leave empty to inherit from global.securityContexts.container.
4951
# capabilities:
5052
# drop:
5153
# - ALL

charts/network/charts/network-nodes/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ A Helm chart for Kubernetes
107107
| openShiftRoute.wildcardPolicy | string | `""` | Wildcard policy controlling subdomain routing (None or Subdomain). |
108108
| persistence.accessModes | list | `["ReadWriteOnce"]` | Requested access modes for the PersistentVolumeClaim. |
109109
| persistence.annotations | object | `{}` | |
110-
| persistence.enabled | bool | `false` | Enable persistent volume claims for ledger data. |
110+
| persistence.enabled | bool | `true` | Enable persistent volume claims for ledger data. |
111111
| persistence.existingClaim | string | `""` | Name of an existing PersistentVolumeClaim to reuse instead of creating new PVCs. |
112112
| persistence.mountPath | string | `"/data"` | Container path where the persistent volume is mounted. |
113113
| persistence.readOnly | bool | `false` | Mount the volume read-only when true. |

charts/network/charts/network-nodes/templates/statefulset-rpc.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ spec:
3636
{{- $initContainers := .Values.initContainers | default (dict) }}
3737
{{- $sharedInitContainers := get $initContainers "shared" }}
3838
{{- $rpcInitContainers := get $initContainers "rpc" }}
39+
{{- $globalValues := (.Values.global | default (dict)) }}
40+
{{- $globalSecurityContexts := dig "securityContexts" $globalValues (dict) }}
41+
{{- $podSecurityContext := merge (deepCopy (default (dict) .Values.podSecurityContext)) (dig "pod" $globalSecurityContexts (dict)) }}
42+
{{- $containerSecurityContext := merge (deepCopy (default (dict) .Values.securityContext)) (dig "container" $globalSecurityContexts (dict)) }}
3943
podManagementPolicy: Parallel
4044
replicas: {{ .Values.rpcReplicaCount }}
4145
serviceName: {{ include "nodes.fullname" . }}-rpc
@@ -73,9 +77,9 @@ spec:
7377
{{- if $rpcPriorityClass }}
7478
priorityClassName: {{ $rpcPriorityClass | quote }}
7579
{{- end }}
76-
{{- with .Values.podSecurityContext }}
80+
{{- if $podSecurityContext }}
7781
securityContext:
78-
{{- toYaml . | nindent 8 }}
82+
{{- toYaml $podSecurityContext | nindent 8 }}
7983
{{- end }}
8084
{{- if or $sharedInitContainers $rpcInitContainers }}
8185
initContainers:
@@ -97,9 +101,9 @@ spec:
97101
{{- if $log4jEnv }}
98102
{{ $log4jEnv | nindent 12 }}
99103
{{- end }}
100-
{{- with .Values.securityContext }}
104+
{{- if $containerSecurityContext }}
101105
securityContext:
102-
{{- toYaml . | nindent 12 }}
106+
{{- toYaml $containerSecurityContext | nindent 12 }}
103107
{{- end }}
104108
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
105109
imagePullPolicy: {{ .Values.image.pullPolicy }}

charts/network/charts/network-nodes/templates/statefulset-validator.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ spec:
3737
{{- $initContainers := .Values.initContainers | default (dict) }}
3838
{{- $sharedInitContainers := get $initContainers "shared" }}
3939
{{- $validatorInitContainers := get $initContainers "validator" }}
40+
{{- $globalValues := (.Values.global | default (dict)) }}
41+
{{- $globalSecurityContexts := dig "securityContexts" $globalValues (dict) }}
42+
{{- $podSecurityContext := merge (deepCopy (default (dict) .Values.podSecurityContext)) (dig "pod" $globalSecurityContexts (dict)) }}
43+
{{- $containerSecurityContext := merge (deepCopy (default (dict) .Values.securityContext)) (dig "container" $globalSecurityContexts (dict)) }}
4044
podManagementPolicy: Parallel
4145
replicas: {{ $validatorReplicaBudget }}
4246
serviceName: {{ include "nodes.fullname" . }}
@@ -74,9 +78,9 @@ spec:
7478
{{- if $validatorPriorityClass }}
7579
priorityClassName: {{ $validatorPriorityClass | quote }}
7680
{{- end }}
77-
{{- with .Values.podSecurityContext }}
81+
{{- if $podSecurityContext }}
7882
securityContext:
79-
{{- toYaml . | nindent 8 }}
83+
{{- toYaml $podSecurityContext | nindent 8 }}
8084
{{- end }}
8185
{{- if or $sharedInitContainers $validatorInitContainers }}
8286
initContainers:
@@ -98,9 +102,9 @@ spec:
98102
{{- if $log4jEnv }}
99103
{{ $log4jEnv | nindent 12 }}
100104
{{- end }}
101-
{{- with .Values.securityContext }}
105+
{{- if $containerSecurityContext }}
102106
securityContext:
103-
{{- toYaml . | nindent 12 }}
107+
{{- toYaml $containerSecurityContext | nindent 12 }}
104108
{{- end }}
105109
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
106110
imagePullPolicy: {{ .Values.image.pullPolicy }}

charts/network/charts/network-nodes/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,13 @@ priorityClassNames:
169169
# Pod-level security context shared by all containers.
170170
podSecurityContext:
171171
{}
172+
# -- Leave empty to inherit from global.securityContexts.pod.
172173
# fsGroup: 2000
173174

174175
# Container-level security context applied to Besu containers.
175176
securityContext:
176177
{}
178+
# -- Leave empty to inherit from global.securityContexts.container.
177179
# capabilities:
178180
# drop:
179181
# - ALL

charts/network/values.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ global:
1414
staticNodesConfigMapName: besu-static-nodes
1515
# -- (string) Prefix used for faucet ConfigMaps and Secrets.
1616
faucetArtifactPrefix: besu-faucet
17+
# -- (object) Shared pod- and container-level security contexts applied when subcharts omit explicit overrides.
18+
securityContexts:
19+
# -- (object) Pod security context inherited by subcharts when set.
20+
pod: {}
21+
# -- (object) Container security context inherited by subcharts when set.
22+
container: {}

0 commit comments

Comments
 (0)