Skip to content

Commit

Permalink
feat: define extra app config which generates ConfigMap (#23)
Browse files Browse the repository at this point in the history
* feat: define extra app config which generates ConfigMap

* change appConfig from multiline string to dict

* docs: document the usage of appConfig key to generate ConfigMap automatically

* chore: load ConfigMap with tplvalues from Bitnami common instead of just toYaml

* tests: appConfig and extraVolumes

* docs: warn about appConfig vs extraAppConfig priority

* docs: reference section with MarkDown link

Co-authored-by: Tom Coufal <7453394+tumido@users.noreply.github.com>

* docs: reference Backstage config docs and template to clarify config priority

* docs: typo

Co-authored-by: Tom Coufal <7453394+tumido@users.noreply.github.com>

* fix: run helm-docs

* fix: do not use specific drivers on CI tests

* chore: bump minor version

Co-authored-by: Tom Coufal <7453394+tumido@users.noreply.github.com>
  • Loading branch information
froblesmartin and tumido authored Dec 16, 2022
1 parent 3f3a618 commit ff60712
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 3 deletions.
2 changes: 1 addition & 1 deletion charts/backstage/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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.9.0
version: 0.10.0

dependencies:
- name: common
Expand Down
18 changes: 17 additions & 1 deletion charts/backstage/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Backstage Helm Chart

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

A Helm chart for deploying a Backstage application

Expand Down Expand Up @@ -85,6 +85,7 @@ The command removes all the Kubernetes components associated with the chart and

| Key | Description | Type | Default |
|-----|-------------|------|---------|
| backstage.appConfig | Generates ConfigMap and configures it in the Backstage pods | object | `{}` |
| backstage.args | | list | `[]` |
| backstage.command[0] | | string | `"node"` |
| backstage.command[1] | | string | `"packages/backend"` |
Expand Down Expand Up @@ -239,6 +240,21 @@ Now that the ConfigMap has been created on your Kubernetes cluster, you can refe

The chart will mount the content of the ConfigMap as a new `app-config.extra.yaml` file and automatically pass the extra configuration to your instance.

### Pass configuration to be stored in a ConfigMap

> :warning: In case of using both appConfig and extraAppConfig, appConfig will have higher priority over extraAppConfig. For more information you can check the [Backstage docs](https://backstage.io/docs/conf/writing#configuration-files) and how this [Helm Chart configures the Backstage arguments](templates/backstage-deployment.yaml)

In addition to following the [previous step "Pass extra configuration files"](#pass-extra-configuration-files), you can get the Config Map automatically deployed with this Helm Chart by defining the key `appConfig`:

```diff
backstage:
+ appConfig:
+ app:
+ baseUrl: https://somedomain.tld
```

The chart will mount the content of the ConfigMap as a new `app-config-from-configmap.yaml` file and automatically pass the extra configuration to your instance.

### Configuring Chart PostgreSQL

With the Backstage Helm Chart, it offers - as a subchart - a Bitnami PostgreSQL database. This can be enabled by switching `postgresql.enabled` to true (it is `false` by default). If switched on, the Helm Chart, on deployment, will automatically deploy a PostgreSQL instance and configure it with the credentials you specify. There are multiple ways of doing this that will be detailed below.
Expand Down
15 changes: 15 additions & 0 deletions charts/backstage/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@ Now that the ConfigMap has been created on your Kubernetes cluster, you can refe

The chart will mount the content of the ConfigMap as a new `app-config.extra.yaml` file and automatically pass the extra configuration to your instance.

### Pass configuration to be stored in a ConfigMap

> :warning: In case of using both appConfig and extraAppConfig, appConfig will have higher priority over extraAppConfig. For more information you can check the [Backstage docs](https://backstage.io/docs/conf/writing#configuration-files) and how this [Helm Chart configures the Backstage arguments](templates/backstage-deployment.yaml)

In addition to following the [previous step "Pass extra configuration files"](#pass-extra-configuration-files), you can get the Config Map automatically deployed with this Helm Chart by defining the key `appConfig`:

```diff
backstage:
+ appConfig:
+ app:
+ baseUrl: https://somedomain.tld
```

The chart will mount the content of the ConfigMap as a new `app-config-from-configmap.yaml` file and automatically pass the extra configuration to your instance.

### Configuring Chart PostgreSQL

With the Backstage Helm Chart, it offers - as a subchart - a Bitnami PostgreSQL database. This can be enabled by switching `postgresql.enabled` to true (it is `false` by default). If switched on, the Helm Chart, on deployment, will automatically deploy a PostgreSQL instance and configure it with the credentials you specify. There are multiple ways of doing this that will be detailed below.
Expand Down
10 changes: 10 additions & 0 deletions charts/backstage/ci/appConfig-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
backstage:
appConfig:
app:
# Let's test that everything is fine with comments
title: The very best Backstage Helm Chart! :D
baseUrl: https://somedomain.tl
backend:
baseUrl: https://somedomain.tl
listen:
port: 12345
File renamed without changes.
9 changes: 9 additions & 0 deletions charts/backstage/ci/extraVolumes-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
backstage:
extraVolumeMounts:
- name: test
mountPath: /somepath
readOnly: true
extraVolumes:
- name: test
emptyDir:
sizeLimit: 5Mi
9 changes: 9 additions & 0 deletions charts/backstage/templates/app-config-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- if .Values.backstage.appConfig }}
apiVersion: v1
kind: ConfigMap
metadata:
name: backstage-app-config
data:
app-config.yaml: |
{{- include "common.tplvalues.render" ( dict "value" .Values.backstage.appConfig "context" $) | nindent 4 }}
{{- end }}
16 changes: 15 additions & 1 deletion charts/backstage/templates/backstage-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ spec:
{{- include "common.tplvalues.render" ( dict "value" .Values.backstage.extraVolumes "context" $ ) | nindent 8 }}
{{- end }}
{{- end }}
{{- if .Values.backstage.appConfig }}
- name: backstage-app-config
configMap:
name: backstage-app-config
{{- end }}
{{- if .Values.backstage.image.pullSecrets }}
imagePullSecrets:
{{- range .Values.backstage.image.pullSecrets }}
Expand Down Expand Up @@ -83,6 +88,10 @@ spec:
- {{ .filename | quote }}
{{- end }}
{{- end }}
{{- if .Values.backstage.appConfig }}
- "--config"
- "app-config-from-configmap.yaml"
{{- end }}
{{- end }}
{{- if .Values.backstage.extraEnvVarsSecrets }}
envFrom:
Expand Down Expand Up @@ -114,13 +123,18 @@ spec:
- name: backend
containerPort: {{ .Values.backstage.containerPorts.backend }}
protocol: TCP
{{- if (or .Values.backstage.extraAppConfig (and .Values.backstage.extraVolumeMounts .Values.backstage.extraVolumes)) }}
{{- if (or .Values.backstage.extraAppConfig .Values.backstage.appConfig (and .Values.backstage.extraVolumeMounts .Values.backstage.extraVolumes)) }}
volumeMounts:
{{- range .Values.backstage.extraAppConfig }}
- name: {{ .configMapRef }}
mountPath: "/app/{{ .filename }}"
subPath: {{ .filename }}
{{- end }}
{{- if .Values.backstage.appConfig }}
- name: backstage-app-config
mountPath: /app/app-config-from-configmap.yaml
subPath: app-config.yaml
{{- end }}
{{- if .Values.backstage.extraVolumeMounts }}
{{- include "common.tplvalues.render" ( dict "value" .Values.backstage.extraVolumeMounts "context" $ ) | nindent 12 }}
{{- end }}
Expand Down
10 changes: 10 additions & 0 deletions charts/backstage/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ backstage:
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container
containerSecurityContext: {}

# Allows to define the appConfig as a multiline string that generates a ConfigMap
# automatically, not requiring to have it pre provisioned as with the extraAppConfig key.
# DO NOT USE if you need to put sensitive data in the appConfig.
# E.g:
# appConfig:
# app:
# baseUrl: https://somedomain.tld
# -- Generates ConfigMap and configures it in the Backstage pods
appConfig: {}

## @section Traffic Exposure parameters

## Service parameters
Expand Down

0 comments on commit ff60712

Please sign in to comment.