Skip to content

Commit

Permalink
feat: Add helm chart for deploying wadm (#248)
Browse files Browse the repository at this point in the history
Signed-off-by: Joonas Bergius <[email protected]>
  • Loading branch information
joonas authored Apr 1, 2024
1 parent f83bdff commit ea900d0
Show file tree
Hide file tree
Showing 9 changed files with 403 additions and 0 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/chart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: chart

env:
HELM_VERSION: v3.14.0

on:
push:
tags:
- 'chart-v[0-9].[0-9]+.[0-9]+'
pull_request:
paths:
- 'charts/**'
- '.github/workflows/chart.yml'

jobs:
validate:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Fetch main branch for chart-testing
run: |
git fetch origin main:main
- name: Set up Helm
uses: azure/setup-helm@v4
with:
version: ${{ env.HELM_VERSION }}

# Used by helm chart-testing below
- name: Set up Python
uses: actions/[email protected]
with:
python-version: '3.12.2'

- name: Set up chart-testing
uses: helm/[email protected]
with:
version: v3.10.1
yamllint_version: 1.35.1
yamale_version: 5.0.0

- name: Run chart-testing (lint)
run: |
ct lint --config charts/wadm/ct.yaml
- name: Create kind cluster
uses: helm/[email protected]
with:
version: "v0.22.0"

- name: Install nats in the test cluster
run: |
helm repo add nats https://nats-io.github.io/k8s/helm/charts/
helm repo update
helm install nats nats/nats
- name: Run chart-testing (install)
run: |
ct install --config charts/wadm/ct.yaml
publish:
if: ${{ startsWith(github.ref, 'refs/tags/chart-v') }}
runs-on: ubuntu-22.04
needs: validate
permissions:
packages: write

steps:
- uses: actions/checkout@v4

- name: Set up Helm
uses: azure/setup-helm@v4
with:
version: ${{ env.HELM_VERSION }}

- name: Package
run: |
helm package chart -d .helm-charts
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Lowercase the organization name for ghcr.io
run: |
echo "GHCR_REPO_NAMESPACE=${GITHUB_REPOSITORY_OWNER,,}" >>${GITHUB_ENV}
- name: Publish
run: |
for chart in .helm-charts/*; do
if [ -z "${chart:-}" ]; then
break
fi
helm push "${chart}" "oci://ghcr.io/${{ env.GHCR_REPO_NAMESPACE }}/charts"
done
23 changes: 23 additions & 0 deletions charts/wadm/.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/
24 changes: 24 additions & 0 deletions charts/wadm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: wadm
description: A Helm chart for deploying wadm on Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
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.1.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
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "v0.10.0"
4 changes: 4 additions & 0 deletions charts/wadm/ci/install-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
wadm:
config:
nats:
server: "nats.default.svc.cluster.local:4222"
3 changes: 3 additions & 0 deletions charts/wadm/ct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
validate-maintainers: false
target-branch: main # TODO: Remove this once chart-testing 3.10.1+ is released
helm-extra-args: --timeout 60s
Empty file added charts/wadm/templates/NOTES.txt
Empty file.
51 changes: 51 additions & 0 deletions charts/wadm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "wadm.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 "wadm.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 "wadm.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

{{/*
Selector labels
*/}}
{{- define "wadm.selectorLabels" -}}
app.kubernetes.io/name: {{ include "wadm.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
116 changes: 116 additions & 0 deletions charts/wadm/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "wadm.fullname" . }}
labels:
{{- include "wadm.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "wadm.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "wadm.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.wadm.image.repository }}:{{ .Values.wadm.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.wadm.image.pullPolicy }}
env:
- name: WADM_NATS_SERVER
value: {{ .Values.wadm.config.nats.server | quote }}
{{- if .Values.wadm.config.nats.seed }}
- name: WADM_NATS_NKEY
value: {{ .Values.wadm.config.nats.seed | quote }}
{{- end }}
{{- if .Values.wadm.config.nats.jwt }}
- name: WADM_NATS_JWT
value: {{ .Values.wadm.config.nats.jwt | quote }}
{{- end }}
{{- if .Values.wadm.config.nats.credsFile }}
- name: WADM_NATS_CREDS_FILE
value: {{ .Values.wadm.config.nats.credsFile | quote }}
{{- end }}
{{- if .Values.wadm.config.nats.tlsCaFile }}
- name: WADM_NATS_TLS_CA_FILE
value: {{ .Values.wadm.config.nats.tlsCaFile | quote }}
{{- end }}
{{- if .Values.wadm.config.hostId }}
- name: WADM_HOST_ID
value: {{ .Values.wadm.config.hostId | quote }}
{{- end }}
{{- if .Values.wadm.config.structuredLogging }}
- name: WADM_STRUCTURED_LOGGING
value: {{ .Values.wadm.config.structuredLogging | quote }}
{{- end }}
{{- if .Values.wadm.config.tracing }}
- name: WADM_TRACING_ENABLED
value: {{ .Values.wadm.config.tracing | quote }}
{{- end }}
{{- if .Values.wadm.config.tracingEndpoint }}
- name: WADM_TRACING_ENDPOINT
value: {{ .Values.wadm.config.tracingEndpoint | quote }}
{{- end }}
{{- if .Values.wadm.config.jetstreamDomain }}
- name: WADM_JETSTREAM_DOMAIN
value: {{ .Values.wadm.config.jetstreamDomain | quote }}
{{- end }}
{{- if .Values.wadm.config.maxJobs }}
- name: WADM_MAX_JOBS
value: {{ .Values.wadm.config.maxJobs }}
{{- end }}
{{- if .Values.wadm.config.stateBucket }}
- name: WADM_STATE_BUCKET_NAME
value: {{ .Values.wadm.config.stateBucket | quote }}
{{- end }}
{{- if .Values.wadm.config.manifestBucket }}
- name: WADM_MANIFEST_BUCKET_NAME
value: {{ .Values.wadm.config.manifestBucket | quote }}
{{- end }}
{{- if .Values.wadm.config.cleanupInterval }}
- name: WADM_CLEANUP_INTERVAL
value: {{ .Values.wadm.config.cleanupInterval }}
{{- end }}
{{- if .Values.wadm.config.apiPrefix }}
- name: WADM_API_PREFIX
value: {{ .Values.wadm.config.apiPrefix }}
{{- end }}
{{- if .Values.wadm.config.streamPrefix }}
- name: WADM_STREAM_PREFIX
value: {{ .Values.wadm.config.streamPrefix }}
{{- end }}
{{- if .Values.wadm.config.multitenant }}
- name: WADM_MULTITENANT
value: {{ .Values.wadm.config.multitenant | quote }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
Loading

0 comments on commit ea900d0

Please sign in to comment.