Skip to content

Commit 329e17d

Browse files
committed
update helm chart on creation of local config file from config map, #552 #543
Signed-off-by: Stefan Seide <[email protected]>
1 parent 6299ea0 commit 329e17d

13 files changed

+148
-121
lines changed

.github/workflows/chart-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
version: ${{ env.HELM_VERSION }}
4040
- uses: actions/setup-python@v5
4141
with:
42-
python-version: 3.9
42+
python-version: 3.10
4343
- name: Set up chart-testing
4444
uses: helm/[email protected]
4545
- name: Run chart-testing (lint)

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
.DS_Store
88
/docs/coverage/
99
.nyc_output/
10+
/test/test-ca/
11+
/test/local/
1012

1113
# files pulled by actions, no check in
1214
helm-docs

bin/redis-commander.js

+1
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ if(args['test']) {
375375

376376

377377
if (startServer) {
378+
console.log(`Starting with NODE_ENV=${process.env.NODE_ENV} and config NODE_APP_INSTANCE=${process.env.NODE_APP_INSTANCE}`);
378379
// check if old deprecated config exists and merge into current one
379380
if (myUtils.hasDeprecatedConfig()) {
380381
console.log('==================================================================================================');

k8s/helm-chart/example-manifest.yaml

-101
This file was deleted.
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
# example definition of a more complex json configuration files to mount it into the docker container via
3+
# helm chart - everything from the "local_production_json" key is written into the configmap generated by helm
4+
# and mounted as a file into the container from the configmap
5+
#
6+
# The data are written as file "local-production-docker.json" to not overwrite the file "local-production.json"
7+
# that gets create from within the docker startup script. Redis commander first evaluates the "local-production.json"
8+
# and afterward "local-production-docker.json" - keys defined here overwrite settings from "local-production.json".
9+
#
10+
# this example defines all data to write into the "local_production.json" file as JSON - the
11+
# data are written as-is into the config file without any conversion
12+
connections:
13+
local_production_json: >-
14+
{
15+
"noSave": false,
16+
"noLogData": false,
17+
"ui": {
18+
"foldingChar": "|"
19+
},
20+
"redis": {
21+
"readOnly": true
22+
},
23+
"server": {
24+
"clientMaxBodySize": "500kb",
25+
"httpAuth": {
26+
"username": "the-user",
27+
"password": "is-secret"
28+
}
29+
},
30+
"connections": [
31+
{
32+
"label": "redis-sentinel-service-x",
33+
"sentinels": "19.94.12.11:26379, 19.94.12.12:26379",
34+
"sentinelName": "mymaster",
35+
"dbIndex": 0
36+
},
37+
{
38+
"label": "redis-sentinel-service-y",
39+
"sentinels": "20.20.12.11:26379",
40+
"sentinelName": "mymaster",
41+
"dbIndex": 0
42+
},
43+
{
44+
"label": "redis-server-service-xz",
45+
"host": "19.94.12.11",
46+
"port": "6379",
47+
"dbIndex": 0
48+
}
49+
]
50+
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
# example definition of a more complex json configuration files to mount it into the docker container via
3+
# helm chart - everything from the "local_production_json" key is written into the configmap generated by helm
4+
# and mounted as a file into the container from the configmap
5+
#
6+
# The data are written as file "local-production-docker.json" to not overwrite the file "local-production.json"
7+
# that gets create from within the docker startup script. Redis commander first evaluates the "local-production.json"
8+
# and afterward "local-production-docker.json" - keys defined here overwrite settings from "local-production.json".
9+
#
10+
# this example defines all data to write into the "local-production-docker.json" file as YAML object
11+
# this YAML is converted into JSON before writing it into the docker container as JSON config file
12+
connections:
13+
local_production_json:
14+
noSave: false
15+
noLogData: false
16+
ui:
17+
foldingChar: "|"
18+
redis:
19+
readOnly: true
20+
server:
21+
clientMaxBodySize: "500kb"
22+
httpAuth:
23+
username: "the-user"
24+
password: "is-secret"
25+
connections:
26+
- label: "redis-sentinel-service-x"
27+
sentinels: "19.94.12.11:26379, 19.94.12.12:26379"
28+
sentinelName: "mymaster"
29+
dbIndex: 0
30+
- label: "redis-sentinel-service-y"
31+
sentinels: "20.20.12.11:26379"
32+
sentinelName: "mymaster"
33+
dbIndex": 0
34+
- label: "redis-server-service-xz"
35+
host: "19.94.12.11"
36+
port: "6379"
37+
dbIndex: 0

k8s/helm-chart/redis-commander/Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type: application
1111
# This is the chart version. This version number should be incremented each time you make changes
1212
# to the chart and its templates, including the app version.
1313
# Versions are expected to follow Semantic Versioning (https://semver.org/)
14-
version: 0.5.0
14+
version: 0.6.0
1515

1616
# This is the version number of the application being deployed. This version number should be
1717
# incremented each time you make changes to the application. Versions are not expected to

k8s/helm-chart/redis-commander/README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A Helm chart for redis-commander
44

5-
![Version: 0.5.0](https://img.shields.io/badge/Version-0.5.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: latest](https://img.shields.io/badge/AppVersion-latest-informational?style=flat-square)
5+
![Version: 0.6.0](https://img.shields.io/badge/Version-0.6.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: latest](https://img.shields.io/badge/AppVersion-latest-informational?style=flat-square)
66

77
## Install
88

@@ -20,7 +20,8 @@ helm -n myspace install redis-web-ui ./k8s/helm-chart/redis-commander --set redi
2020
|-----|------|---------|-------------|
2121
| affinity | object | `{}` | optional set pod affinity definitions for kubernetes |
2222
| autoscaling | object | `{"enabled":false,"maxReplicas":1,"minReplicas":1,"targetCPUUtilizationPercentage":80}` | Autoscaling configuration for k8s deployment |
23-
| connections | object | `{}` | optional object to set the "local_production_json" property to let Helm render a "local-production.json" file from a configmap to preconfigure more complex configuration examples with connection data too without the need to set all parameter via environment variables (where available). For a working example see file "example-manifest.yaml" |
23+
| configMapData | object | `{}` | optional data to add to the configmap generated by this helm chart. This might be useful if extra files shall be created inside the docker container which can be mounted defining the "volumeMounts" and "volumes" below. |
24+
| connections | object | `{}` | optional object to set the "local_production_json" property to let Helm render a "local-production.json" file from a configmap to preconfigure more complex configuration examples with connection data too without the need to set all parameter via environment variables (where available). For a working example see either file "example-values-as-json.yaml" where the file content is written as json formatted string or file "example-values-as-yml.yaml" with all config values for the file are defined as YAML. |
2425
| env | list | `[]` | Extra env vars for the main pod redis-commander in array structure ([{name: ... , value: ...}, {name: ... , value: ...}]). |
2526
| fullnameOverride | string | `""` | |
2627
| httpAuth.password | string | `""` | Specify http basic password for the web ui |
@@ -62,8 +63,8 @@ helm -n myspace install redis-web-ui ./k8s/helm-chart/redis-commander --set redi
6263
| serviceAccount.create | bool | `false` | Specifies whether a service account should be created When no service account is created the account credentials of the default account are also not automatically mounted into the pod (automountServiceAccountToken: false), tokens only mounted when service account is used but Redis-Commander itself does not use the k8s api server token |
6364
| serviceAccount.name | string | `""` | The name of the service account to use. If not set and create is true, a name is generated using the fullname template |
6465
| tolerations | list | `[]` | optional set pod toleration definitions for kubernetes |
65-
| volumeMounts | list | `[]` | optional list of volumes to mount into the docker deployment. This can either be a local storage volume or a configmap to mount data as file. Each list item needs a "name" and a "mountPath". Setting this will most time also require setting a "volumes" entry. For a working example see file "example-manifest.yaml" |
66-
| volumes | list | `[]` | optional list of volumes to mount into the docker deployment. This can either be a loca storage volume or a configmap to mount data as file. Each list item needs a "name" and a "mountPath". Setting this will most time also require setting a "volumeMounts" entry. For a working example see file "example-manifest.yaml" |
66+
| volumeMounts | list | `[]` | optional list of volumes to mount into the docker deployment. This can either be a local storage volume or a configmap to mount data as file. Each list item needs a "name" and a "mountPath". Setting this will most of the time also require setting a "volumes" entry. |
67+
| volumes | list | `[]` | optional list of volumes to mount into the docker deployment. This can either be a local storage volume or a configmap to mount data as file. Each list item needs a "name" and a "mountPath". Setting this will most of the time also require setting a "volumeMounts" entry. |
6768

6869
## Example
6970

@@ -102,4 +103,4 @@ Chart version 0.20 switches to use the `networking.k8s.io/v1` apiVersion by defa
102103
If you are using a version of kubernetes older than 1.19 or using OpenShift v3 you will need to set the `ingress.legacy` option to `true` to enable support for the deprecated Ingress versions.
103104

104105
----------------------------------------------
105-
Autogenerated from chart metadata using [helm-docs v1.7.0](https://github.com/norwoodj/helm-docs/releases/v1.7.0)
106+
Autogenerated from chart metadata using [helm-docs v1.7.0](https://github.com/norwoodj/helm-docs/releases/v1.7.0)

k8s/helm-chart/redis-commander/templates/_helpers.tpl

+12
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,15 @@ Create the name of the service account to use
6161
{{- default "default" .Values.serviceAccount.name }}
6262
{{- end }}
6363
{{- end }}
64+
65+
66+
{{/*
67+
Create the correctly formatted entry for the config map from either YAML object or JSON string
68+
*/}}
69+
{{- define "redis-commander.localProductionJson" }}
70+
{{- if eq (kindOf .Values.connections.local_production_json) "string" }}
71+
{{ .Values.connections.local_production_json }}
72+
{{- else }}
73+
{{ .Values.connections.local_production_json | toPrettyJson }}
74+
{{- end }}
75+
{{- end }}

k8s/helm-chart/redis-commander/templates/configmap.yaml

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@ kind: ConfigMap
44
metadata:
55
name: {{ .Release.Name }}-configmap
66
data:
7-
local-production.json: {{ .Values.connections.local_production_json | toJson }}
7+
{{- if .Values.connections.local_production_json }}
8+
local-production-docker.json: |-
9+
{{- include "redis-commander.localProductionJson" . | indent 4 }}
10+
{{- end }}
11+
{{ with .Values.configMapData }}
12+
{{- toYaml . | nindent 4 }}
13+
{{- end }}

k8s/helm-chart/redis-commander/templates/deployment.yaml

+17-4
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,15 @@ spec:
7676
{{- end }}
7777
- name: K8S_SIGTERM
7878
value: "1"
79-
{{- with .Values.volumeMounts }}
8079
volumeMounts:
80+
{{- if .Values.connections.local_production_json }}
81+
- name: production-local
82+
mountPath: /redis-commander/config/local-production-docker.json # This should be your final destination
83+
subPath: local-production-docker.json
84+
{{- end }}
85+
{{- with .Values.volumeMounts }}
8186
{{- toYaml . | default "" | nindent 12 }}
82-
{{- end }}
87+
{{- end }}
8388
livenessProbe:
8489
httpGet:
8590
path: /favicon.png
@@ -88,10 +93,18 @@ spec:
8893
timeoutSeconds: 5
8994
resources:
9095
{{- toYaml .Values.resources | nindent 12 }}
91-
{{- with .Values.volumes }}
9296
volumes:
97+
{{- if .Values.connections.local_production_json }}
98+
- name: production-local
99+
configMap:
100+
name: {{ .Release.Name }}-configmap
101+
items:
102+
- key: local-production-docker.json
103+
path: local-production-docker.json
104+
{{- end }}
105+
{{- with .Values.volumes }}
93106
{{- toYaml . | default "" | nindent 8 }}
94-
{{- end }}
107+
{{- end }}
95108
{{- with .Values.nodeSelector }}
96109
nodeSelector:
97110
{{- toYaml . | nindent 8 }}

k8s/helm-chart/redis-commander/values.yaml

+12-8
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,21 @@ affinity: {}
166166
# -- optional object to set the "local_production_json" property to let Helm render a "local-production.json"
167167
# file from a configmap to preconfigure more complex configuration examples with connection data too
168168
# without the need to set all parameter via environment variables (where available).
169-
# For a working example see file "example-manifest.yaml"
169+
# For a working example see either file "example-values-as-json.yaml" where the file content is written as json
170+
# formatted string or file "example-values-as-yml.yaml" with all config values for the file are defined as YAML.
170171
connections: {}
171172

173+
# -- optional data to add to the configmap generated by this helm chart.
174+
# This might be useful if extra files shall be created inside the docker container which can be mounted
175+
# defining the "volumeMounts" and "volumes" below.
176+
configMapData: {}
177+
172178
# -- optional list of volumes to mount into the docker deployment. This can either be a local storage volume
173-
# or a configmap to mount data as file. Each list item needs a "name" and a "mountPath". Setting this will most time
174-
# also require setting a "volumes" entry.
175-
# For a working example see file "example-manifest.yaml"
179+
# or a configmap to mount data as file. Each list item needs a "name" and a "mountPath". Setting this will most of
180+
# the time also require setting a "volumes" entry.
176181
volumeMounts: []
177182

178-
# -- optional list of volumes to mount into the docker deployment. This can either be a loca storage volume
179-
# or a configmap to mount data as file. Each list item needs a "name" and a "mountPath". Setting this will most time
180-
# also require setting a "volumeMounts" entry.
181-
# For a working example see file "example-manifest.yaml"
183+
# -- optional list of volumes to mount into the docker deployment. This can either be a local storage volume
184+
# or a configmap to mount data as file. Each list item needs a "name" and a "mountPath". Setting this will most of
185+
# the time also require setting a "volumeMounts" entry.
182186
volumes: []

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
"postinstall": "echo '==> INFO: Errors with module \"bcrypt\" can be ignored'",
7171
"snyk-protect": "snyk protect",
7272
"helm-doc": "helm-docs -c k8s/helm-chart",
73+
"helm-test": "helm template redis-commander -f k8s/helm-chart/redis-commander/values.yaml k8s/helm-chart/redis-commander -n redis | kubeval",
74+
"helm-lint": "docker run -it --workdir=/data --volume \"$(pwd)/k8s/helm-chart/redis-commander:/data\" quay.io/helmpack/chart-testing ct lint --charts . --validate-maintainers=false",
7375
"test": "mocha",
7476
"test-with-lcov": "nyc --reporter=lcov --report-dir ./docs/coverage/nodejs mocha --timeout 10000 --reporter mocha-junit-reporter --reporter-options mochaFile=./docs/coverage/junit.xml --exit",
7577
"sbom": "cyclonedx-npm --omit optional --mc-type application --output-format json --output-file ./sbom.json"

0 commit comments

Comments
 (0)