Skip to content

Commit

Permalink
feat: simplify helm chart (#75)
Browse files Browse the repository at this point in the history
* feat: simplify helm chart

* fix: remove -n

* fix: register healthcheck for e2e test

* feat: separate checks and sparrow config

* fix: e2e tests

* fix: bug where env variables would not be read correctly

* feat: allow mounting extra secrets as env variables

* docs: envfromSecrets
  • Loading branch information
niklastreml authored Jan 18, 2024
1 parent fc72395 commit 0d9de25
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 544 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/end2end.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ jobs:
helm upgrade -i sparrow \
--atomic \
--timeout 300s \
--set extraArgs.loaderType=file \
--set extraArgs.loaderFilePath=/runconfig/checks.yaml \
--set image.tag=${{ steps.version.outputs.value }} \
--set startupConfig.name=the-sparrow.com \
chart
--set image.tag=${{ steps.version.outputs.value }} \
--set sparrowConfig.name=the-sparrow.com \
--set sparrowConfig.loader.type=file \
--set sparrowConfig.loader.file.path=/config/.sparrow.yaml \
--set checksConfig.checks.health.interval=1s \
./chart
- name: Check Pods
run: |
kubectl get pods
Expand Down
7 changes: 4 additions & 3 deletions chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ A Helm chart to install Sparrow
| Key | Type | Default | Description |
|-----|------|---------|-------------|
| affinity | object | `{}` | |
| checksConfig | object | `{}` | |
| env | object | `{}` | |
| extraArgs | object | `{"loaderFilePath":"/runconfig/checks.yaml","loaderType":"file"}` | extra command line start parameters see: https://github.com/caas-team/sparrow/blob/main/docs/sparrow_run.md |
| envFromSecrets | list | `[]` | extra environment variables Allows you to set environment variables through secrets you defined outside of the helm chart Useful for sensitive information like the http loader token |
| extraArgs | object | `{}` | extra command line start parameters see: https://github.com/caas-team/sparrow/blob/main/docs/sparrow_run.md |
| fullnameOverride | string | `""` | |
| image.pullPolicy | string | `"IfNotPresent"` | |
| image.repository | string | `"ghcr.io/caas-team/sparrow"` | |
Expand All @@ -43,7 +45,6 @@ A Helm chart to install Sparrow
| podSecurityContext.supplementalGroups[0] | int | `1000` | |
| replicaCount | int | `1` | |
| resources | object | `{}` | |
| runtimeConfig | object | `{}` | runtime configuration of the Sparrow see: https://github.com/caas-team/sparrow#runtime |
| securityContext.allowPrivilegeEscalation | bool | `false` | |
| securityContext.capabilities.drop[0] | string | `"ALL"` | |
| securityContext.privileged | bool | `false` | |
Expand All @@ -61,6 +62,6 @@ A Helm chart to install Sparrow
| serviceMonitor.interval | string | `"30s"` | Sets the scrape interval |
| serviceMonitor.labels | object | `{}` | Additional label added to the service Monitor |
| serviceMonitor.scrapeTimeout | string | `"5s"` | Sets the scrape timeout |
| startupConfig | object | `{}` | startup configuration of the Sparrow see: https://github.com/caas-team/sparrow/blob/main/docs/sparrow_run.md |
| sparrowConfig | object | `{}` | startup configuration of the Sparrow see: https://github.com/caas-team/sparrow/blob/main/docs/sparrow_run.md |
| tolerations | list | `[]` | |

8 changes: 8 additions & 0 deletions chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@ Create the name of the service account to use
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{- define "sparrow.checksConfigName"}}
{{- include "sparrow.fullname" . }}-checks
{{- end }}

{{- define "sparrow.sparrowConfigName"}}
{{- include "sparrow.fullname" . }}-config
{{- end }}
37 changes: 0 additions & 37 deletions chart/templates/configmap.yaml

This file was deleted.

46 changes: 19 additions & 27 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
template:
metadata:
annotations:
checksum/config: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
checksum/config: {{ include (print $.Template.BasePath "/sparrowConfig.yaml") . | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand All @@ -30,25 +30,34 @@ spec:
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
{{- if or .Values.extraArgs .Values.startupConfig }}
- args:
{{- end }}
{{- if .Values.startupConfig}}
- --config
- /startupconfig/.sparrow.yaml
- /config/.sparrow.yaml
{{- if .Values.checksConfig }}
- --loaderFilePath
- /config/checks.yaml
{{- end }}
{{- if .Values.extraArgs }}
{{- range $key, $value := .Values.extraArgs }}
- --{{ $key }}
- {{ $value }}
{{- end }}
{{- end }}
{{- if .Values.env }}
{{- if or .Values.env .Values.envFromSecrets }}
env:
{{- range $key, $val := .Values.env }}
- name: {{ $key }}
value: {{ $val | quote }}
{{- end }}
{{- if .Values.envFromSecrets }}
{{- range $i,$s := .Values.envFromSecrets }}
- name: {{ $s.name }}
valueFrom:
secretKeyRef:
name: {{ $s.valueFrom.secretName }}
key: {{ $s.valueFrom.key }}
{{ end -}}
{{ end -}}
{{- end }}
name: {{ .Chart.Name }}
securityContext:
Expand All @@ -63,30 +72,13 @@ spec:
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- end }}
{{- if or .Values.runtimeConfig .Values.startupConfig}}
volumeMounts:
{{- end }}
{{- if .Values.startupConfig}}
- name: startup
mountPath: /startupconfig
{{- end }}
{{- if .Values.runtimeConfig}}
- name: runtime
mountPath: /runconfig
{{- end }}
{{- if or .Values.runtimeConfig .Values.startupConfig}}
- name: sparrow-config
mountPath: /config/
volumes:
{{- end }}
{{- if .Values.startupConfig}}
- name: startup
secret:
secretName: {{ include "sparrow.fullname" . }}
{{- end }}
{{- if .Values.runtimeConfig}}
- name: runtime
- name: sparrow-config
configMap:
name: {{ include "sparrow.fullname" . }}
{{- end }}
name: {{ include "sparrow.sparrowConfigName" . }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
6 changes: 1 addition & 5 deletions chart/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{{- if .Values.startupConfig }}
apiVersion: v1
kind: Secret
type: Opaque
Expand All @@ -7,7 +6,4 @@ metadata:
labels:
{{- include "sparrow.labels" . | nindent 4 }}
data:
{{- if .Values.startupConfig}}
.sparrow.yaml: {{ toYaml .Values.startupConfig | b64enc }}
{{- end }}
{{- end }}
.sparrow.yaml: {{ toYaml .Values.config | b64enc }}
13 changes: 13 additions & 0 deletions chart/templates/sparrowConfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "sparrow.sparrowConfigName" . }}
labels:
{{- include "sparrow.labels" . | nindent 4 }}
data:
.sparrow.yaml: |
{{- .Values.sparrowConfig | toYaml | nindent 4 }}
{{- if .Values.checksConfig }}
checks.yaml: |
{{- .Values.checksConfig | toYaml | nindent 4 }}
{{- end }}
58 changes: 32 additions & 26 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,21 @@ affinity: {}

# -- extra command line start parameters
# see: https://github.com/caas-team/sparrow/blob/main/docs/sparrow_run.md
extraArgs:
loaderFilePath: /runconfig/checks.yaml
loaderType: file
extraArgs: {}

# -- extra environment variables
# Allows you to set environment variables through secrets you defined outside of the helm chart
# Useful for sensitive information like the http loader token
envFromSecrets:
[]
# - name: SPARROW_LOADER_HTTP_TOKEN
# valueFrom:
# secretName: sparrow-auth
# key: SPARROW_LOADER_HTTP_TOKEN

# -- startup configuration of the Sparrow
# see: https://github.com/caas-team/sparrow/blob/main/docs/sparrow_run.md
startupConfig: {}
sparrowConfig: {}
# name: the-sparrow.com
# api:
# address:
Expand All @@ -122,28 +130,26 @@ startupConfig: {}
# token: ""
# baseUrl: https://gitlab.com
# projectId: ""

# -- runtime configuration of the Sparrow
# see: https://github.com/caas-team/sparrow#runtime
runtimeConfig: {}
# health:
# interval: 20s
# timeout: 10s
# retry:
# count: 3
# delay: 1s
# targets:
# - "https://www.example.com/"
# - "https://www.google.com/"
# latency:
# interval: 1s
# timeout: 3s
# retry:
# count: 3
# delay: 1s
# targets:
# - https://example.com/
# - https://google.com/
checksConfig: {}
# checks:
# health:
# interval: 20s
# timeout: 10s
# retry:
# count: 3
# delay: 1s
# targets:
# - "https://www.example.com/"
# - "https://www.google.com/"
# latency:
# interval: 1s
# timeout: 3s
# retry:
# count: 3
# delay: 1s
# targets:
# - https://example.com/
# - https://google.com/

# -- Configure a service monitor for prometheus-operator
serviceMonitor:
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func initConfig(cfgFile string) {

viper.SetEnvPrefix("sparrow")
dotreplacer := strings.NewReplacer(".", "_")
viper.EnvKeyReplacer(dotreplacer)
viper.SetEnvKeyReplacer(dotreplacer)
viper.AutomaticEnv()

if err := viper.ReadInConfig(); err == nil {
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ require (
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
Loading

0 comments on commit 0d9de25

Please sign in to comment.