Skip to content

Commit

Permalink
Merge pull request #149 from jontze/chore/update-helm-chart
Browse files Browse the repository at this point in the history
chore(helm): Update helm chart and make it modular and easier to use
  • Loading branch information
jontze authored Apr 4, 2024
2 parents 65b23f6 + 251397e commit 50c2a37
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 28 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/main-helm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Publish Helm Chart
on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'helm/**'

permissions:
contents: read
packages: write

env:
OCI_MANIFESTS_BASE_URL: "oci://ghcr.io/jontze/manifests"
OCI_MANIFESTS_PATH: "./helm/cadency"

jobs:
publish:
runs-on: ubuntu-latest
name: Publish
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Helm Login
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io --username ${{ github.repository_owner }} --password-stdin
- name: Login to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup flux cli
uses: fluxcd/flux2/action@main
- name: Push Helm Manifests to OCI Image
run: |
export CHART_NAME=$(helm show chart $OCI_MANIFESTS_PATH | yq e '.name' -)
export CHART_VERSION=$(helm show chart $OCI_MANIFESTS_PATH | yq e '.version' -)
helm package $OCI_MANIFESTS_PATH
helm push $CHART_NAME-$CHART_VERSION.tgz $OCI_MANIFESTS_BASE_URL
flux tag artifact $OCI_MANIFESTS_BASE_URL/cadency_rs:$CHART_VERSION \
--tag latest \
--tag $(git rev-parse --short HEAD)
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ on:
push:
branches:
- main
paths-ignore:
- 'helm/**'

jobs:
test_branch:
Expand Down
6 changes: 3 additions & 3 deletions helm/cadency/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: v2
name: cadency
description: Helm chart for the cadency discord bot
version: 0.1.0
appVersion: "0.3.3"
description: Helm chart to deploy the cadency discord bot.
version: 0.2.0
appVersion: "0.5.1"
type: application
maintainers:
- name: Jontze
Expand Down
11 changes: 10 additions & 1 deletion helm/cadency/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,13 @@ Be aware that {{ .Chart.Name }} is still in early development. It might eat your
To learn more about the release, try:

$ helm status {{ .Release.Name }}
$ helm get all {{ .Release.Name }}
$ helm get all {{ .Release.Name }}

Check the running pod with `kubectl get pod {{ include "cadency.fullname" . }} -n {{ .Release.Namespace }}`.

{{- if .Values.cadency.discordToken.createSecret }}
A new secret was created to store your discord token: `kubectl get secret {{ include "cadency.fullname" . }} -n {{ .Release.Namespace }}`.
{{- else }}
Cadency tries to use the discord token stored in this secret: `kubectl get secret {{ .Values.cadency.discordToken.existingSecretRef.name }} -n {{ .Release.Namespace }}` with key `{{ .Values.cadency.discordToken.existingSecretRef.key }}`.
{{- end }}

29 changes: 20 additions & 9 deletions helm/cadency/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ Create chart name and version as used by the chart label.
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Selector labels
*/}}
{{- define "cadency.selectorLabels" -}}
app.kubernetes.io/name: {{ include "cadency.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{/*
Common labels
*/}}
Expand All @@ -48,4 +40,23 @@ helm.sh/chart: {{ include "cadency.chart" . }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{ end -}}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}
{{- end -}}

{{/*
Selector labels
*/}}
{{- define "cadency.selectorLabels" -}}
app.kubernetes.io/name: {{ include "cadency.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{/*
Create the name of the service account to use
*/}}
{{- define "cadency.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "cadency.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
8 changes: 6 additions & 2 deletions helm/cadency/templates/config-map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "cadency.fullname" . }}-config
name: {{ include "cadency.fullname" . }}
labels:
{{- include "cadency.labels" . | nindent 4 }}
data:
logLevel: {{ .Values.cadency.logLevel }}
{{- with .Values.cadency.config }}
logLevel: {{ .logLevel }}
playlistSongLimit: {{ .playlistSongLimit }}
songLengthLimit: {{ .songLengthLimit }}
{{- end }}
56 changes: 50 additions & 6 deletions helm/cadency/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,73 @@ spec:
replicas: 1
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{ toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "cadency.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.podLabels }}
{{ toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "cadency.serviceAccountName" . }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.name }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: RUST_LOG
- name: "RUST_LOG"
valueFrom:
configMapKeyRef:
name: {{ include "cadency.fullname" . }}-config
name: {{ include "cadency.fullname" . }}
key: logLevel
optional: true
- name: "CADENCY_PLAYLIST_SONG_LIMIT"
valueFrom:
configMapKeyRef:
name: {{ include "cadency.fullname" . }}
key: playlistSongLimit
optional: true
- name: "CADENCY_SONG_LENGTH_LIMIT"
valueFrom:
configMapKeyRef:
name: {{ include "cadency.fullname" . }}
key: songLengthLimit
optional: true
{{- $createdSecretName := include "cadency.fullname" . -}}
{{- with .Values.cadency.discordToken }}
- name: DISCORD_TOKEN
valueFrom:
secretKeyRef:
name: {{ include "cadency.fullname" . }}-secrets
key: token
optional: false
{{- if .createSecret }}
name: {{ $createdSecretName }}
key: token
{{- else }}
name: {{ .existingSecretRef.name }}
key: {{ .existingSecretRef.key}}
{{- end }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 10 }}
{{- toYaml .Values.resources | nindent 10 }}
7 changes: 4 additions & 3 deletions helm/cadency/templates/secrets.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
{{- if .Values.cadency.discordToken.createSecret -}}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "cadency.fullname" . }}-secrets
name: {{ include "cadency.fullname" . }}
labels:
{{- include "cadency.labels" . | nindent 4 }}
type: Opaque
data:
token: {{ .Values.cadency.discordToken | b64enc }}
token: {{ .Values.cadency.discordToken.token | b64enc }}
{{- end }}
13 changes: 13 additions & 0 deletions helm/cadency/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "cadency.serviceAccountName" . }}
labels:
{{- include "cadency.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
{{- end }}
50 changes: 46 additions & 4 deletions helm/cadency/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,57 @@ image:
# tag Overrides the image tag whose default is the chart appVersion.
tag: ""

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

podAnnotations: {}
podLabels: {}

podSecurityContext: {}
securityContext: {}

nodeSelector: {}
tolerations: []
affinity: {}
resources:
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

serviceAccount:
# Specifies whether a service account should be created
create: true
# Automatically mount a ServiceAccount's API credentials?
automount: true
# Annotations to add to the service account
annotations: {}
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""

cadency:
config:
# logLevel of the cadency application
logLevel: cadency=info
logLevel: cadency=info
playlistSongLimit: ""
songLengthLimit: ""
# discordToken that is used to connect to discord
# This variable is required to use the chart.
discordToken:

resources: {}
nodeSelector: {}
# Use `existingSecretRef` to tell the chart fin which secret the
# discord token is referenced.
# Or set `createSecret` to `true` and pass the discord token
# via `token` to the helm chart.
existingSecretRef:
name: ""
key: ""
createSecret: false
token: ""

0 comments on commit 50c2a37

Please sign in to comment.