Skip to content

Commit

Permalink
update helm chart on creation of local config file from config map, j…
Browse files Browse the repository at this point in the history
…oeferner#552 joeferner#543

Signed-off-by: Stefan Seide <account-github@seide.st>
  • Loading branch information
sseide committed Jan 26, 2024
1 parent 6299ea0 commit 329e17d
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/chart-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
version: ${{ env.HELM_VERSION }}
- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.10
- name: Set up chart-testing
uses: helm/chart-testing-action@v2.6.1
- name: Run chart-testing (lint)
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
.DS_Store
/docs/coverage/
.nyc_output/
/test/test-ca/
/test/local/

# files pulled by actions, no check in
helm-docs
Expand Down
1 change: 1 addition & 0 deletions bin/redis-commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ if(args['test']) {


if (startServer) {
console.log(`Starting with NODE_ENV=${process.env.NODE_ENV} and config NODE_APP_INSTANCE=${process.env.NODE_APP_INSTANCE}`);
// check if old deprecated config exists and merge into current one
if (myUtils.hasDeprecatedConfig()) {
console.log('==================================================================================================');
Expand Down
101 changes: 0 additions & 101 deletions k8s/helm-chart/example-manifest.yaml

This file was deleted.

50 changes: 50 additions & 0 deletions k8s/helm-chart/example-values-as-json.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
# example definition of a more complex json configuration files to mount it into the docker container via
# helm chart - everything from the "local_production_json" key is written into the configmap generated by helm
# and mounted as a file into the container from the configmap
#
# The data are written as file "local-production-docker.json" to not overwrite the file "local-production.json"
# that gets create from within the docker startup script. Redis commander first evaluates the "local-production.json"
# and afterward "local-production-docker.json" - keys defined here overwrite settings from "local-production.json".
#
# this example defines all data to write into the "local_production.json" file as JSON - the
# data are written as-is into the config file without any conversion
connections:
local_production_json: >-
{
"noSave": false,
"noLogData": false,
"ui": {
"foldingChar": "|"
},
"redis": {
"readOnly": true
},
"server": {
"clientMaxBodySize": "500kb",
"httpAuth": {
"username": "the-user",
"password": "is-secret"
}
},
"connections": [
{
"label": "redis-sentinel-service-x",
"sentinels": "19.94.12.11:26379, 19.94.12.12:26379",
"sentinelName": "mymaster",
"dbIndex": 0
},
{
"label": "redis-sentinel-service-y",
"sentinels": "20.20.12.11:26379",
"sentinelName": "mymaster",
"dbIndex": 0
},
{
"label": "redis-server-service-xz",
"host": "19.94.12.11",
"port": "6379",
"dbIndex": 0
}
]
}
37 changes: 37 additions & 0 deletions k8s/helm-chart/example-values-as-yml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
# example definition of a more complex json configuration files to mount it into the docker container via
# helm chart - everything from the "local_production_json" key is written into the configmap generated by helm
# and mounted as a file into the container from the configmap
#
# The data are written as file "local-production-docker.json" to not overwrite the file "local-production.json"
# that gets create from within the docker startup script. Redis commander first evaluates the "local-production.json"
# and afterward "local-production-docker.json" - keys defined here overwrite settings from "local-production.json".
#
# this example defines all data to write into the "local-production-docker.json" file as YAML object
# this YAML is converted into JSON before writing it into the docker container as JSON config file
connections:
local_production_json:
noSave: false
noLogData: false
ui:
foldingChar: "|"
redis:
readOnly: true
server:
clientMaxBodySize: "500kb"
httpAuth:
username: "the-user"
password: "is-secret"
connections:
- label: "redis-sentinel-service-x"
sentinels: "19.94.12.11:26379, 19.94.12.12:26379"
sentinelName: "mymaster"
dbIndex: 0
- label: "redis-sentinel-service-y"
sentinels: "20.20.12.11:26379"
sentinelName: "mymaster"
dbIndex": 0
- label: "redis-server-service-xz"
host: "19.94.12.11"
port: "6379"
dbIndex: 0
2 changes: 1 addition & 1 deletion k8s/helm-chart/redis-commander/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.5.0
version: 0.6.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
11 changes: 6 additions & 5 deletions k8s/helm-chart/redis-commander/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A Helm chart for redis-commander

![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)
![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)

## Install

Expand All @@ -20,7 +20,8 @@ helm -n myspace install redis-web-ui ./k8s/helm-chart/redis-commander --set redi
|-----|------|---------|-------------|
| affinity | object | `{}` | optional set pod affinity definitions for kubernetes |
| autoscaling | object | `{"enabled":false,"maxReplicas":1,"minReplicas":1,"targetCPUUtilizationPercentage":80}` | Autoscaling configuration for k8s deployment |
| 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" |
| 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. |
| 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. |
| env | list | `[]` | Extra env vars for the main pod redis-commander in array structure ([{name: ... , value: ...}, {name: ... , value: ...}]). |
| fullnameOverride | string | `""` | |
| httpAuth.password | string | `""` | Specify http basic password for the web ui |
Expand Down Expand Up @@ -62,8 +63,8 @@ helm -n myspace install redis-web-ui ./k8s/helm-chart/redis-commander --set redi
| 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 |
| 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 |
| tolerations | list | `[]` | optional set pod toleration definitions for kubernetes |
| 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" |
| 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" |
| 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. |
| 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. |

## Example

Expand Down Expand Up @@ -102,4 +103,4 @@ Chart version 0.20 switches to use the `networking.k8s.io/v1` apiVersion by defa
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.

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.7.0](https://github.com/norwoodj/helm-docs/releases/v1.7.0)
Autogenerated from chart metadata using [helm-docs v1.7.0](https://github.com/norwoodj/helm-docs/releases/v1.7.0)
12 changes: 12 additions & 0 deletions k8s/helm-chart/redis-commander/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,15 @@ Create the name of the service account to use
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}


{{/*
Create the correctly formatted entry for the config map from either YAML object or JSON string
*/}}
{{- define "redis-commander.localProductionJson" }}
{{- if eq (kindOf .Values.connections.local_production_json) "string" }}
{{ .Values.connections.local_production_json }}
{{- else }}
{{ .Values.connections.local_production_json | toPrettyJson }}
{{- end }}
{{- end }}
8 changes: 7 additions & 1 deletion k8s/helm-chart/redis-commander/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
local-production.json: {{ .Values.connections.local_production_json | toJson }}
{{- if .Values.connections.local_production_json }}
local-production-docker.json: |-
{{- include "redis-commander.localProductionJson" . | indent 4 }}
{{- end }}
{{ with .Values.configMapData }}
{{- toYaml . | nindent 4 }}
{{- end }}
21 changes: 17 additions & 4 deletions k8s/helm-chart/redis-commander/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,15 @@ spec:
{{- end }}
- name: K8S_SIGTERM
value: "1"
{{- with .Values.volumeMounts }}
volumeMounts:
{{- if .Values.connections.local_production_json }}
- name: production-local
mountPath: /redis-commander/config/local-production-docker.json # This should be your final destination
subPath: local-production-docker.json
{{- end }}
{{- with .Values.volumeMounts }}
{{- toYaml . | default "" | nindent 12 }}
{{- end }}
{{- end }}
livenessProbe:
httpGet:
path: /favicon.png
Expand All @@ -88,10 +93,18 @@ spec:
timeoutSeconds: 5
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.volumes }}
volumes:
{{- if .Values.connections.local_production_json }}
- name: production-local
configMap:
name: {{ .Release.Name }}-configmap
items:
- key: local-production-docker.json
path: local-production-docker.json
{{- end }}
{{- with .Values.volumes }}
{{- toYaml . | default "" | nindent 8 }}
{{- end }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
20 changes: 12 additions & 8 deletions k8s/helm-chart/redis-commander/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,21 @@ affinity: {}
# -- 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"
# 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.
connections: {}

# -- 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.
configMapData: {}

# -- 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"
# 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.
volumeMounts: []

# -- 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"
# -- 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.
volumes: []
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
"postinstall": "echo '==> INFO: Errors with module \"bcrypt\" can be ignored'",
"snyk-protect": "snyk protect",
"helm-doc": "helm-docs -c k8s/helm-chart",
"helm-test": "helm template redis-commander -f k8s/helm-chart/redis-commander/values.yaml k8s/helm-chart/redis-commander -n redis | kubeval",
"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",
"test": "mocha",
"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",
"sbom": "cyclonedx-npm --omit optional --mc-type application --output-format json --output-file ./sbom.json"
Expand Down

0 comments on commit 329e17d

Please sign in to comment.