Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Helm Chart Support #12189

Open
wants to merge 38 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d0a54b7
helm: init
stevefan1999-personal Nov 27, 2023
ef16f0a
chart: fix managed config not being included in jq
stevefan1999-personal Dec 3, 2023
36f6ef4
docker: add jq to image
stevefan1999-personal Dec 3, 2023
5c2ba03
charts: fix ingree host reference
stevefan1999-personal Dec 3, 2023
ff09655
charts: add admin account creation
stevefan1999-personal Dec 3, 2023
60bf883
charts: add init setup container
stevefan1999-personal Dec 3, 2023
978c3f5
charts: rephrase mongodb to mongo for config compatibility
stevefan1999-personal Dec 3, 2023
4ff9408
charts: fix chart app version
stevefan1999-personal Dec 3, 2023
7ac9365
charts: redis should not have password and auth
stevefan1999-personal Dec 3, 2023
cf2038d
charts: fix wrong image repo
stevefan1999-personal Dec 3, 2023
ab53b70
fixup! charts: redis should not have password and auth
stevefan1999-personal Dec 3, 2023
e0f6db9
charts: add liveness, readiness and startup probe
stevefan1999-personal Dec 3, 2023
33696d0
charts: fix setup process to load json file into argument instead
stevefan1999-personal Dec 3, 2023
05e3044
charts: add single mode
stevefan1999-personal Dec 3, 2023
d820073
charts: add basic required config variables
stevefan1999-personal Dec 3, 2023
0251c1b
charts: should use stateful set instead to avoid concurrency bootstra…
stevefan1999-personal Dec 3, 2023
f8c2168
charts: use ping for liveness check, lower initial delay time
stevefan1999-personal Dec 3, 2023
8af41c1
charts: add message to indicate generated config
stevefan1999-personal Dec 3, 2023
a5d9e0a
charts: add env option
stevefan1999-personal Dec 3, 2023
d972dd5
charts: move database from configmap to secret for a json hack
stevefan1999-personal Dec 3, 2023
e72c79e
charts: add sa suffix to prevent name collision with redis
stevefan1999-personal Dec 3, 2023
a3db1f7
charts: only enable database section when needed in config
stevefan1999-personal Dec 3, 2023
6c528c5
fixup! charts: add sa suffix to prevent name collision with redis
stevefan1999-personal Dec 3, 2023
854827c
charts: disable managed database by default and add examples
stevefan1999-personal Dec 3, 2023
6efca29
actions: add a basic chart releaser
stevefan1999-personal Dec 4, 2023
1cf1aa5
charts: update chart lock
stevefan1999-personal Dec 4, 2023
1d8ca0f
actions: add helm repository
stevefan1999-personal Dec 4, 2023
56c5ea1
actions: add pull_request to test workflow
stevefan1999-personal Dec 4, 2023
c558088
fixup! actions: add pull_request to test workflow
stevefan1999-personal Dec 4, 2023
dc1f9db
charts: hpa should reference StatefulSet as scale target
stevefan1999-personal Dec 4, 2023
af1d663
actions: integration test for k8s (wip)
stevefan1999-personal Dec 4, 2023
ca15fd6
charts: add serviceName back
stevefan1999-personal Dec 4, 2023
e0fa1d9
charts: remove restart policy
stevefan1999-personal Dec 4, 2023
1ab0f7d
actions: add k8s integration test for nodebb charts
stevefan1999-personal Dec 4, 2023
730eb0b
actions: wait until the charts are fully deleted
stevefan1999-personal Dec 4, 2023
d3527a5
actions: segregate the integration tests to different namespaces
stevefan1999-personal Dec 4, 2023
5d936c2
fixup! actions: segregate the integration tests to different namespaces
stevefan1999-personal Dec 4, 2023
5d23acf
actions: use pull_request assignment trick to simulate workflow_dispatch
stevefan1999-personal Dec 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/helm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Release Charts

on:
push:
branches:
- 'master'
- 'v*.x'
tags:
- 'v*'
workflow_dispatch:
pull_request:
types: [assigned]
jobs:
release:
# depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions
# see: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"

- name: Install Helm
uses: azure/setup-helm@v3
- name: Add repositories
run: |
for dir in $(ls -d charts/*/); do
helm dependency list $dir 2> /dev/null | tail +2 | head -n -1 | awk '{ print "helm repo add " $1 " " $3 }' | while read cmd; do $cmd; done
done
- name: Run chart-releaser
uses: helm/chart-releaser-action@v1.6.0
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
90 changes: 90 additions & 0 deletions .github/workflows/test-k8s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: K8S Integration test

on:
push:
branches:
- master
- develop
pull_request:
types: [assigned]
workflow_dispatch:
defaults:
run:
shell: bash

permissions:
contents: read

jobs:
test:
permissions:
checks: write # for coverallsapp/github-action to create new checks
contents: read # for actions/checkout to fetch code
name: K8S Integration test

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install kubectl
uses: azure/setup-kubectl@v3
- name: Install Helm
uses: azure/setup-helm@v3
- name: Create k3d cluster
uses: stevefan1999-personal/k3d-action@main
with:
cluster-name: "nodebb-test"
args: --agents 0 -i ghcr.io/jlian/k3d-nfs:v1.25.3-k3s1
- name: Install NFS Server Provisioner
run: |
kubectl patch storageclass local-path -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
helm repo add nfs-ganesha-server-and-external-provisioner https://kubernetes-sigs.github.io/nfs-ganesha-server-and-external-provisioner/
helm install -n kube-system nfs-provisioner nfs-ganesha-server-and-external-provisioner/nfs-server-provisioner \
--set persistence.storageClass=local-path \
--set persistence.enabled=true \
--set persistence.size=20Gi \
--set storageClass.defaultClass=true
- name: Install Verdaccio
run: |
helm repo add verdaccio https://charts.verdaccio.org
helm install npm verdaccio/verdaccio \
--set persistence.storageClass=local-path \
--set persistence.enabled=true \
--set persistence.size=20Gi
- name: Add charts repositories
run: |
for dir in $(ls -d charts/*/); do
helm dependency list $dir 2> /dev/null | tail +2 | head -n -1 | awk '{ print "helm repo add " $1 " " $3 }' | while read cmd; do $cmd; done
done
- name: Build NodeBB chart dependencies
run: |
cd ./charts/nodebb
helm dependency build
- name: Install example NodeBB chart based on Redis
run: |
cd ./charts/nodebb
helm upgrade --create-namespace -n redis --install redis-test . -f ./values.yaml -f ./values.example.redis.yaml --set env[0].name=NPM_CONFIG_REGISTRY --set env[0].value=http://npm-verdaccio.default:4873/
kubectl wait pod -n redis --all --for=condition=Ready --timeout=30m
helm uninstall -n redis redis-test --wait
- name: Install example NodeBB chart based on Mongo
run: |
cd ./charts/nodebb
helm upgrade --create-namespace -n mongo --install mongo-test . -f ./values.yaml -f ./values.example.mongo.yaml --set env[0].name=NPM_CONFIG_REGISTRY --set env[0].value=http://npm-verdaccio.default:4873/
kubectl wait pod -n mongo --all --for=condition=Ready --timeout=30m
helm uninstall -n mongo mongo-test --wait
- name: Install example NodeBB chart based on Postgres
run: |
cd ./charts/nodebb
helm upgrade --create-namespace -n postgres --install postgres-test . -f ./values.yaml -f ./values.example.postgres.yaml --set env[0].name=NPM_CONFIG_REGISTRY --set env[0].value=http://npm-verdaccio.default:4873/
kubectl wait pod -n postgres --all --for=condition=Ready --timeout=30m
helm uninstall -n postgres postgres-test --wait
- name: Remove all PVC and pods
if: always()
run: |
helm uninstall npm --wait
kubectl delete pvc --all -n redis --wait
kubectl delete pvc --all -n mongo --wait
kubectl delete pvc --all -n postgres --wait
helm uninstall -n kube-system nfs-provisioner --wait
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ RUN if [ $BUILDPLATFORM != $TARGETPLATFORM ]; then \

FROM node:lts-slim as run

RUN apt update && apt install -y --no-install-recommends \
jq && \
apt clean && \
rm -rf /var/lib/apt/lists/*

ARG NODE_ENV
ENV NODE_ENV=$NODE_ENV \
daemon=false \
Expand Down
2 changes: 2 additions & 0 deletions charts/nodebb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
charts/
.template
23 changes: 23 additions & 0 deletions charts/nodebb/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
12 changes: 12 additions & 0 deletions charts/nodebb/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
dependencies:
- name: redis
repository: https://charts.bitnami.com/bitnami
version: 18.4.0
- name: mongodb
repository: https://charts.bitnami.com/bitnami
version: 14.3.1
- name: postgresql
repository: https://charts.bitnami.com/bitnami
version: 13.2.18
digest: sha256:f40e655ad5f8de0fa41e192bf64fecfdf157e4310fb3e62b6eea1e9cac3dfe2f
generated: "2023-12-04T10:58:35.1043994+08:00"
19 changes: 19 additions & 0 deletions charts/nodebb/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v2
name: nodebb
description: A Helm chart for NodeBB
type: application
version: 0.1.0
appVersion: "3.6.0"
dependencies:
- name: redis
version: 18.4.0
repository: https://charts.bitnami.com/bitnami
condition: global.redis.managed
- name: mongodb
version: 14.3.1
repository: https://charts.bitnami.com/bitnami
condition: global.mongodb.managed
- name: postgresql
version: 13.2.18
repository: https://charts.bitnami.com/bitnami
condition: global.postgresql.managed
20 changes: 20 additions & 0 deletions charts/nodebb/Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set shell := ["pwsh", "-c"]

name := "nodebb"
chart := "."
namespace := "nodebb"
config := "values.yaml"

init:
@helm repo add nodebb https://nodebb.github.io/helm-charts
@helm repo update

install:
@helm upgrade --install --create-namespace -n {{namespace}} {{name}} {{chart}} -f {{config}}

template:
@rm -Re -Fo -ErrorAction SilentlyContinue .template; exit 0
@helm template -n {{namespace}} {{name}} {{chart}} -f {{config}} --output-dir .template --debug

uninstall:
@helm uninstall -n {{namespace}} {{name}}
23 changes: 23 additions & 0 deletions charts/nodebb/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{- $domain := .Values.nodebb.domain -}}
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $domain }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "nodebb.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "nodebb.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "nodebb.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "nodebb.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
82 changes: 82 additions & 0 deletions charts/nodebb/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "nodebb.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "nodebb.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "nodebb.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "nodebb.labels" -}}
helm.sh/chart: {{ include "nodebb.chart" . }}
{{ include "nodebb.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

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

{{/*
Create the name of the service account to use
*/}}
{{- define "nodebb.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (printf "%s-sa" (include "nodebb.fullname" .)) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{- define "nodebb.basePvcConfig" -}}
{{- if .args.enabled -}}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ printf "%s-%s" (include "nodebb.fullname" .global) .suffix }}
labels:
{{- toYaml .args.labels | nindent 4 }}
annotations:
{{- toYaml .args.annotations | nindent 4 }}
spec:
storageClassName: {{ .args.storageClass }}
resources:
requests:
storage: {{ .args.size }}
accessModes: {{ .args.accessModes }}
---
{{- end -}}
{{- end }}